qdrant_client/builders/
query_point_groups_builder.rs

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