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