Skip to main content

qdrant_client/builders/
search_point_groups_builder.rs

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