Skip to main content

qdrant_client/builders/
query_point_groups_builder.rs

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