qdrant_client/builders/
search_point_groups_builder.rs

1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[derive(Clone)]
5pub struct SearchPointGroupsBuilder {
6    /// Name of the collection
7    pub(crate) collection_name: Option<String>,
8    /// Vector to compare against
9    pub(crate) vector: Option<Vec<f32>>,
10    /// Filter conditions - return only those points that satisfy the specified conditions
11    pub(crate) filter: Option<Option<Filter>>,
12    /// Max number of result
13    pub(crate) limit: Option<u32>,
14    /// Options for specifying which payload to include or not
15    with_payload: Option<with_payload_selector::SelectorOptions>,
16    /// Search config
17    pub(crate) params: Option<Option<SearchParams>>,
18    /// If provided - cut off results with worse scores
19    pub(crate) score_threshold: Option<Option<f32>>,
20    /// Which vector to use for search, if not specified - use default vector
21    pub(crate) vector_name: Option<Option<String>>,
22    /// Options for specifying which vectors to include into response
23    with_vectors: Option<with_vectors_selector::SelectorOptions>,
24    /// Payload field to group by, must be a string or number field. If there are multiple values for the field, all of them will be used. One point can be in multiple groups.
25    pub(crate) group_by: Option<String>,
26    /// Maximum amount of points to return per group
27    pub(crate) group_size: Option<u32>,
28    /// Options for specifying read consistency guarantees
29    read_consistency: Option<read_consistency::Value>,
30    /// Options for specifying how to use the group id to lookup points in another collection
31    pub(crate) with_lookup: Option<Option<WithLookup>>,
32    /// If set, overrides global timeout setting for this request. Unit is seconds.
33    pub(crate) timeout: Option<Option<u64>>,
34    /// Specify in which shards to look for the points, if not specified - look in all shards
35    pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
36    pub(crate) sparse_indices: Option<Option<SparseIndices>>,
37}
38
39impl SearchPointGroupsBuilder {
40    /// Name of the collection
41    #[allow(unused_mut)]
42    pub fn collection_name(self, value: String) -> Self {
43        let mut new = self;
44        new.collection_name = Option::Some(value);
45        new
46    }
47    /// Vector to compare against
48    #[allow(unused_mut)]
49    pub fn vector(self, value: Vec<f32>) -> Self {
50        let mut new = self;
51        new.vector = Option::Some(value);
52        new
53    }
54    /// Filter conditions - return only those points that satisfy the specified conditions
55    #[allow(unused_mut)]
56    pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
57        let mut new = self;
58        new.filter = Option::Some(Option::Some(value.into()));
59        new
60    }
61    /// Max number of result
62    #[allow(unused_mut)]
63    pub fn limit(self, value: u32) -> Self {
64        let mut new = self;
65        new.limit = Option::Some(value);
66        new
67    }
68    /// Options for specifying which payload to include or not
69    #[allow(unused_mut)]
70    pub fn with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
71        self,
72        value: VALUE,
73    ) -> Self {
74        let mut new = self;
75        new.with_payload = Option::Some(value.into());
76        new
77    }
78    /// Search config
79    #[allow(unused_mut)]
80    pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
81        let mut new = self;
82        new.params = Option::Some(Option::Some(value.into()));
83        new
84    }
85    /// If provided - cut off results with worse scores
86    #[allow(unused_mut)]
87    pub fn score_threshold<VALUE: core::convert::Into<f32>>(self, value: VALUE) -> Self {
88        let mut new = self;
89        new.score_threshold = Option::Some(Option::Some(value.into()));
90        new
91    }
92    /// Which vector to use for search, if not specified - use default vector
93    #[allow(unused_mut)]
94    pub fn vector_name<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
95        let mut new = self;
96        new.vector_name = Option::Some(Option::Some(value.into()));
97        new
98    }
99    /// Options for specifying which vectors to include into response
100    #[allow(unused_mut)]
101    pub fn with_vectors<VALUE: core::convert::Into<with_vectors_selector::SelectorOptions>>(
102        self,
103        value: VALUE,
104    ) -> Self {
105        let mut new = self;
106        new.with_vectors = Option::Some(value.into());
107        new
108    }
109    /// Payload field to group by, must be a string or number field. If there are multiple values for the field, all of them will be used. One point can be in multiple groups.
110    #[allow(unused_mut)]
111    pub fn group_by(self, value: String) -> Self {
112        let mut new = self;
113        new.group_by = Option::Some(value);
114        new
115    }
116    /// Maximum amount of points to return per group
117    #[allow(unused_mut)]
118    pub fn group_size(self, value: u32) -> Self {
119        let mut new = self;
120        new.group_size = Option::Some(value);
121        new
122    }
123    /// Options for specifying read consistency guarantees
124    #[allow(unused_mut)]
125    pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
126        self,
127        value: VALUE,
128    ) -> Self {
129        let mut new = self;
130        new.read_consistency = Option::Some(value.into());
131        new
132    }
133    /// Options for specifying how to use the group id to lookup points in another collection
134    #[allow(unused_mut)]
135    pub fn with_lookup<VALUE: core::convert::Into<WithLookup>>(self, value: VALUE) -> Self {
136        let mut new = self;
137        new.with_lookup = Option::Some(Option::Some(value.into()));
138        new
139    }
140    /// If set, overrides global timeout setting for this request. Unit is seconds.
141    #[allow(unused_mut)]
142    pub fn timeout<VALUE: core::convert::Into<u64>>(self, value: VALUE) -> Self {
143        let mut new = self;
144        new.timeout = Option::Some(Option::Some(value.into()));
145        new
146    }
147    /// Specify in which shards to look for the points, if not specified - look in all shards
148    #[allow(unused_mut)]
149    pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
150        self,
151        value: VALUE,
152    ) -> Self {
153        let mut new = self;
154        new.shard_key_selector = Option::Some(Option::Some(value.into()));
155        new
156    }
157    #[allow(unused_mut)]
158    pub fn sparse_indices<VALUE: core::convert::Into<SparseIndices>>(self, value: VALUE) -> Self {
159        let mut new = self;
160        new.sparse_indices = Option::Some(Option::Some(value.into()));
161        new
162    }
163
164    fn build_inner(self) -> Result<SearchPointGroups, SearchPointGroupsBuilderError> {
165        Ok(SearchPointGroups {
166            collection_name: match self.collection_name {
167                Some(value) => value,
168                None => {
169                    return Result::Err(core::convert::Into::into(
170                        ::derive_builder::UninitializedFieldError::from("collection_name"),
171                    ));
172                }
173            },
174            vector: match self.vector {
175                Some(value) => value,
176                None => {
177                    return Result::Err(core::convert::Into::into(
178                        ::derive_builder::UninitializedFieldError::from("vector"),
179                    ));
180                }
181            },
182            filter: self.filter.unwrap_or_default(),
183            limit: match self.limit {
184                Some(value) => value,
185                None => {
186                    return Result::Err(core::convert::Into::into(
187                        ::derive_builder::UninitializedFieldError::from("limit"),
188                    ));
189                }
190            },
191            with_payload: { convert_option(&self.with_payload) },
192            params: self.params.unwrap_or_default(),
193            score_threshold: self.score_threshold.unwrap_or_default(),
194            vector_name: self.vector_name.unwrap_or_default(),
195            with_vectors: { convert_option(&self.with_vectors) },
196            group_by: match self.group_by {
197                Some(value) => value,
198                None => {
199                    return Result::Err(core::convert::Into::into(
200                        ::derive_builder::UninitializedFieldError::from("group_by"),
201                    ));
202                }
203            },
204            group_size: match self.group_size {
205                Some(value) => value,
206                None => {
207                    return Result::Err(core::convert::Into::into(
208                        ::derive_builder::UninitializedFieldError::from("group_size"),
209                    ));
210                }
211            },
212            read_consistency: { convert_option(&self.read_consistency) },
213            with_lookup: self.with_lookup.unwrap_or_default(),
214            timeout: self.timeout.unwrap_or_default(),
215            shard_key_selector: self.shard_key_selector.unwrap_or_default(),
216            sparse_indices: self.sparse_indices.unwrap_or_default(),
217        })
218    }
219    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
220    fn create_empty() -> Self {
221        Self {
222            collection_name: core::default::Default::default(),
223            vector: core::default::Default::default(),
224            filter: core::default::Default::default(),
225            limit: core::default::Default::default(),
226            with_payload: core::default::Default::default(),
227            params: core::default::Default::default(),
228            score_threshold: core::default::Default::default(),
229            vector_name: core::default::Default::default(),
230            with_vectors: core::default::Default::default(),
231            group_by: core::default::Default::default(),
232            group_size: core::default::Default::default(),
233            read_consistency: core::default::Default::default(),
234            with_lookup: core::default::Default::default(),
235            timeout: core::default::Default::default(),
236            shard_key_selector: core::default::Default::default(),
237            sparse_indices: core::default::Default::default(),
238        }
239    }
240}
241
242impl From<SearchPointGroupsBuilder> for SearchPointGroups {
243    fn from(value: SearchPointGroupsBuilder) -> Self {
244        value.build_inner().unwrap_or_else(|_| {
245            panic!(
246                "Failed to convert {0} to {1}",
247                "SearchPointGroupsBuilder", "SearchPointGroups"
248            )
249        })
250    }
251}
252
253impl SearchPointGroupsBuilder {
254    /// Builds the desired type. Can often be omitted.
255    pub fn build(self) -> SearchPointGroups {
256        self.build_inner().unwrap_or_else(|_| {
257            panic!(
258                "Failed to build {0} into {1}",
259                "SearchPointGroupsBuilder", "SearchPointGroups"
260            )
261        })
262    }
263}
264
265impl SearchPointGroupsBuilder {
266    pub(crate) fn empty() -> Self {
267        Self::create_empty()
268    }
269}
270
271// src/builders/abort_shard_transfer_builder.rs
272
273#[non_exhaustive]
274#[derive(Debug)]
275pub enum SearchPointGroupsBuilderError {
276    /// Uninitialized field
277    UninitializedField(&'static str),
278    /// Custom validation error
279    ValidationError(String),
280}
281
282// Implementing the Display trait for better error messages
283impl std::fmt::Display for SearchPointGroupsBuilderError {
284    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
285        match self {
286            Self::UninitializedField(field) => {
287                write!(f, "`{field}` must be initialized")
288            }
289            Self::ValidationError(error) => write!(f, "{error}"),
290        }
291    }
292}
293
294// Implementing the Error trait
295impl std::error::Error for SearchPointGroupsBuilderError {}
296
297// Implementing From trait for conversion from UninitializedFieldError
298impl From<derive_builder::UninitializedFieldError> for SearchPointGroupsBuilderError {
299    fn from(error: derive_builder::UninitializedFieldError) -> Self {
300        Self::UninitializedField(error.field_name())
301    }
302}
303
304// Implementing From trait for conversion from String
305impl From<String> for SearchPointGroupsBuilderError {
306    fn from(error: String) -> Self {
307        Self::ValidationError(error)
308    }
309}