qdrant_client/builders/
context_input_pair_builder.rs1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct ContextInputPairBuilder {
5 pub(crate) positive: Option<Option<VectorInput>>,
7 pub(crate) negative: Option<Option<VectorInput>>,
9}
10
11impl ContextInputPairBuilder {
12 #[allow(unused_mut)]
14 pub fn positive<VALUE: core::convert::Into<VectorInput>>(self, value: VALUE) -> Self {
15 let mut new = self;
16 new.positive = Option::Some(Option::Some(value.into()));
17 new
18 }
19 #[allow(unused_mut)]
21 pub fn negative<VALUE: core::convert::Into<VectorInput>>(self, value: VALUE) -> Self {
22 let mut new = self;
23 new.negative = Option::Some(Option::Some(value.into()));
24 new
25 }
26
27 fn build_inner(self) -> Result<ContextInputPair, ContextInputPairBuilderError> {
28 Ok(ContextInputPair {
29 positive: self.positive.unwrap_or_default(),
30 negative: self.negative.unwrap_or_default(),
31 })
32 }
33 fn create_empty() -> Self {
35 Self {
36 positive: core::default::Default::default(),
37 negative: core::default::Default::default(),
38 }
39 }
40}
41
42impl From<ContextInputPairBuilder> for ContextInputPair {
43 fn from(value: ContextInputPairBuilder) -> Self {
44 value.build_inner().unwrap_or_else(|_| {
45 panic!(
46 "Failed to convert {0} to {1}",
47 "ContextInputPairBuilder", "ContextInputPair"
48 )
49 })
50 }
51}
52
53impl ContextInputPairBuilder {
54 pub fn build(self) -> ContextInputPair {
56 self.build_inner().unwrap_or_else(|_| {
57 panic!(
58 "Failed to build {0} into {1}",
59 "ContextInputPairBuilder", "ContextInputPair"
60 )
61 })
62 }
63}
64
65impl ContextInputPairBuilder {
66 pub(crate) fn empty() -> Self {
67 Self::create_empty()
68 }
69}
70
71#[non_exhaustive]
73#[derive(Debug)]
74pub enum ContextInputPairBuilderError {
75 UninitializedField(&'static str),
77 ValidationError(String),
79}
80
81impl std::fmt::Display for ContextInputPairBuilderError {
83 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
84 match self {
85 Self::UninitializedField(field) => {
86 write!(f, "`{field}` must be initialized")
87 }
88 Self::ValidationError(error) => write!(f, "{error}"),
89 }
90 }
91}
92
93impl std::error::Error for ContextInputPairBuilderError {}
95
96impl From<derive_builder::UninitializedFieldError> for ContextInputPairBuilderError {
98 fn from(error: derive_builder::UninitializedFieldError) -> Self {
99 Self::UninitializedField(error.field_name())
100 }
101}
102
103impl From<String> for ContextInputPairBuilderError {
105 fn from(error: String) -> Self {
106 Self::ValidationError(error)
107 }
108}