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