qdrant_client/builders/
search_matrix_points_builder.rs

1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct SearchMatrixPointsBuilder {
5    /// Name of the collection
6    pub(crate) collection_name: Option<String>,
7    /// Filter conditions - return only those points that satisfy the specified conditions.
8    pub(crate) filter: Option<Option<Filter>>,
9    /// How many points to select and search within. Default is 10.
10    pub(crate) sample: Option<Option<u64>>,
11    /// How many neighbours per sample to find. Default is 3.
12    pub(crate) limit: Option<Option<u64>>,
13    /// Define which vector to use for querying. If missing, the default vector is is used.
14    pub(crate) using: Option<Option<String>>,
15    /// If set, overrides global timeout setting for this request. Unit is seconds.
16    pub(crate) timeout: Option<Option<u64>>,
17    /// Options for specifying read consistency guarantees
18    pub(crate) read_consistency: Option<Option<ReadConsistency>>,
19    /// Specify in which shards to look for the points, if not specified - look in all shards
20    pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
21}
22
23impl SearchMatrixPointsBuilder {
24    /// Name of the collection
25    #[allow(unused_mut)]
26    pub fn collection_name(self, value: String) -> Self {
27        let mut new = self;
28        new.collection_name = Option::Some(value);
29        new
30    }
31    /// Filter conditions - return only those points that satisfy the specified conditions.
32    #[allow(unused_mut)]
33    pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
34        let mut new = self;
35        new.filter = Option::Some(Option::Some(value.into()));
36        new
37    }
38    /// How many points to select and search within. Default is 10.
39    #[allow(unused_mut)]
40    pub fn sample(self, value: u64) -> Self {
41        let mut new = self;
42        new.sample = Option::Some(Option::Some(value));
43        new
44    }
45    /// How many neighbours per sample to find. Default is 3.
46    #[allow(unused_mut)]
47    pub fn limit(self, value: u64) -> Self {
48        let mut new = self;
49        new.limit = Option::Some(Option::Some(value));
50        new
51    }
52    /// Define which vector to use for querying. If missing, the default vector is is used.
53    #[allow(unused_mut)]
54    pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
55        let mut new = self;
56        new.using = Option::Some(Option::Some(value.into()));
57        new
58    }
59    /// If set, overrides global timeout setting for this request. Unit is seconds.
60    #[allow(unused_mut)]
61    pub fn timeout(self, value: u64) -> Self {
62        let mut new = self;
63        new.timeout = Option::Some(Option::Some(value));
64        new
65    }
66    /// Options for specifying read consistency guarantees
67    #[allow(unused_mut)]
68    pub fn read_consistency<VALUE: core::convert::Into<ReadConsistency>>(
69        self,
70        value: VALUE,
71    ) -> Self {
72        let mut new = self;
73        new.read_consistency = Option::Some(Option::Some(value.into()));
74        new
75    }
76    /// Specify in which shards to look for the points, if not specified - look in all shards
77    #[allow(unused_mut)]
78    pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
79        self,
80        value: VALUE,
81    ) -> Self {
82        let mut new = self;
83        new.shard_key_selector = Option::Some(Option::Some(value.into()));
84        new
85    }
86
87    fn build_inner(self) -> Result<SearchMatrixPoints, SearchMatrixPointsBuilderError> {
88        Ok(SearchMatrixPoints {
89            collection_name: match self.collection_name {
90                Some(value) => value,
91                None => {
92                    return Result::Err(core::convert::Into::into(
93                        ::derive_builder::UninitializedFieldError::from("collection_name"),
94                    ));
95                }
96            },
97            filter: self.filter.unwrap_or_default(),
98            sample: self.sample.unwrap_or_default(),
99            limit: self.limit.unwrap_or_default(),
100            using: self.using.unwrap_or_default(),
101            timeout: self.timeout.unwrap_or_default(),
102            read_consistency: self.read_consistency.unwrap_or_default(),
103            shard_key_selector: self.shard_key_selector.unwrap_or_default(),
104        })
105    }
106    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
107    fn create_empty() -> Self {
108        Self {
109            collection_name: core::default::Default::default(),
110            filter: core::default::Default::default(),
111            sample: core::default::Default::default(),
112            limit: core::default::Default::default(),
113            using: core::default::Default::default(),
114            timeout: core::default::Default::default(),
115            read_consistency: core::default::Default::default(),
116            shard_key_selector: core::default::Default::default(),
117        }
118    }
119}
120
121impl From<SearchMatrixPointsBuilder> for SearchMatrixPoints {
122    fn from(value: SearchMatrixPointsBuilder) -> Self {
123        value.build_inner().unwrap_or_else(|_| {
124            panic!(
125                "Failed to convert {0} to {1}",
126                "SearchMatrixPointsBuilder", "SearchMatrixPoints"
127            )
128        })
129    }
130}
131
132impl SearchMatrixPointsBuilder {
133    /// Builds the desired type. Can often be omitted.
134    pub fn build(self) -> SearchMatrixPoints {
135        self.build_inner().unwrap_or_else(|_| {
136            panic!(
137                "Failed to build {0} into {1}",
138                "SearchMatrixPointsBuilder", "SearchMatrixPoints"
139            )
140        })
141    }
142}
143
144impl SearchMatrixPointsBuilder {
145    pub(crate) fn empty() -> Self {
146        Self::create_empty()
147    }
148}
149
150#[non_exhaustive]
151#[derive(Debug)]
152pub enum SearchMatrixPointsBuilderError {
153    /// Uninitialized field
154    UninitializedField(&'static str),
155    /// Custom validation error
156    ValidationError(String),
157}
158
159// Implementing the Display trait for better error messages
160impl std::fmt::Display for SearchMatrixPointsBuilderError {
161    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
162        match self {
163            Self::UninitializedField(field) => {
164                write!(f, "`{field}` must be initialized")
165            }
166            Self::ValidationError(error) => write!(f, "{error}"),
167        }
168    }
169}
170
171// Implementing the Error trait
172impl std::error::Error for SearchMatrixPointsBuilderError {}
173
174// Implementing From trait for conversion from UninitializedFieldError
175impl From<derive_builder::UninitializedFieldError> for SearchMatrixPointsBuilderError {
176    fn from(error: derive_builder::UninitializedFieldError) -> Self {
177        Self::UninitializedField(error.field_name())
178    }
179}
180
181// Implementing From trait for conversion from String
182impl From<String> for SearchMatrixPointsBuilderError {
183    fn from(error: String) -> Self {
184        Self::ValidationError(error)
185    }
186}