qdrant_client/builders/
context_input_pair_builder.rs

1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct ContextInputPairBuilder {
5    /// A positive vector
6    pub(crate) positive: Option<Option<VectorInput>>,
7    /// Repel from this vector
8    pub(crate) negative: Option<Option<VectorInput>>,
9}
10
11impl ContextInputPairBuilder {
12    /// A positive vector
13    pub fn positive<VALUE: core::convert::Into<VectorInput>>(self, value: VALUE) -> Self {
14        let mut new = self;
15        new.positive = Option::Some(Option::Some(value.into()));
16        new
17    }
18    /// Repel from this vector
19    pub fn negative<VALUE: core::convert::Into<VectorInput>>(self, value: VALUE) -> Self {
20        let mut new = self;
21        new.negative = Option::Some(Option::Some(value.into()));
22        new
23    }
24
25    fn build_inner(self) -> Result<ContextInputPair, ContextInputPairBuilderError> {
26        Ok(ContextInputPair {
27            positive: self.positive.unwrap_or_default(),
28            negative: self.negative.unwrap_or_default(),
29        })
30    }
31    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
32    fn create_empty() -> Self {
33        Self {
34            positive: core::default::Default::default(),
35            negative: core::default::Default::default(),
36        }
37    }
38}
39
40impl From<ContextInputPairBuilder> for ContextInputPair {
41    fn from(value: ContextInputPairBuilder) -> Self {
42        value.build_inner().unwrap_or_else(|_| {
43            panic!(
44                "Failed to convert {0} to {1}",
45                "ContextInputPairBuilder", "ContextInputPair"
46            )
47        })
48    }
49}
50
51impl ContextInputPairBuilder {
52    /// Builds the desired type. Can often be omitted.
53    pub fn build(self) -> ContextInputPair {
54        self.build_inner().unwrap_or_else(|_| {
55            panic!(
56                "Failed to build {0} into {1}",
57                "ContextInputPairBuilder", "ContextInputPair"
58            )
59        })
60    }
61}
62
63impl ContextInputPairBuilder {
64    pub(crate) fn empty() -> Self {
65        Self::create_empty()
66    }
67}
68
69/// Error type for ContextInputPairBuilder
70#[non_exhaustive]
71#[derive(Debug)]
72pub enum ContextInputPairBuilderError {
73    /// Uninitialized field
74    UninitializedField(&'static str),
75    /// Custom validation error
76    ValidationError(String),
77}
78
79// Implementing the Display trait for better error messages
80impl std::fmt::Display for ContextInputPairBuilderError {
81    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
82        match self {
83            Self::UninitializedField(field) => {
84                write!(f, "`{field}` must be initialized")
85            }
86            Self::ValidationError(error) => write!(f, "{error}"),
87        }
88    }
89}
90
91// Implementing the Error trait
92impl std::error::Error for ContextInputPairBuilderError {}
93
94// Implementing From trait for conversion from UninitializedFieldError
95impl From<derive_builder::UninitializedFieldError> for ContextInputPairBuilderError {
96    fn from(error: derive_builder::UninitializedFieldError) -> Self {
97        Self::UninitializedField(error.field_name())
98    }
99}
100
101// Implementing From trait for conversion from String
102impl From<String> for ContextInputPairBuilderError {
103    fn from(error: String) -> Self {
104        Self::ValidationError(error)
105    }
106}