qdrant_client/builders/
recommend_point_groups_builder.rs

1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[derive(Clone)]
5pub struct RecommendPointGroupsBuilder {
6    /// Name of the collection
7    pub(crate) collection_name: Option<String>,
8    /// Look for vectors closest to the vectors from these points
9    pub(crate) positive: Option<Vec<PointId>>,
10    /// Try to avoid vectors like the vector from these points
11    pub(crate) negative: Option<Vec<PointId>>,
12    /// Filter conditions - return only those points that satisfy the specified conditions
13    pub(crate) filter: Option<Option<Filter>>,
14    /// Max number of groups in result
15    pub(crate) limit: Option<u32>,
16    /// Options for specifying which payload to include or not
17    with_payload: Option<with_payload_selector::SelectorOptions>,
18    /// Search config
19    pub(crate) params: Option<Option<SearchParams>>,
20    /// If provided - cut off results with worse scores
21    pub(crate) score_threshold: Option<Option<f32>>,
22    /// Define which vector to use for recommendation, if not specified - default vector
23    pub(crate) using: Option<Option<String>>,
24    /// Options for specifying which vectors to include into response
25    with_vectors: Option<with_vectors_selector::SelectorOptions>,
26    /// Name of the collection to use for points lookup, if not specified - use current collection
27    pub(crate) lookup_from: Option<Option<LookupLocation>>,
28    /// 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.
29    pub(crate) group_by: Option<String>,
30    /// Maximum amount of points to return per group
31    pub(crate) group_size: Option<u32>,
32    /// Options for specifying read consistency guarantees
33    read_consistency: Option<read_consistency::Value>,
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    /// How to use the example vectors to find the results
37    pub(crate) strategy: Option<Option<i32>>,
38    /// Look for vectors closest to those
39    pub(crate) positive_vectors: Option<Vec<Vector>>,
40    /// Try to avoid vectors like this
41    pub(crate) negative_vectors: Option<Vec<Vector>>,
42    /// If set, overrides global timeout setting for this request. Unit is seconds.
43    pub(crate) timeout: Option<Option<u64>>,
44    /// Specify in which shards to look for the points, if not specified - look in all shards
45    pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
46}
47
48impl RecommendPointGroupsBuilder {
49    /// Name of the collection
50    #[allow(unused_mut)]
51    pub fn collection_name(self, value: String) -> Self {
52        let mut new = self;
53        new.collection_name = Option::Some(value);
54        new
55    }
56    /// Filter conditions - return only those points that satisfy the specified conditions
57    #[allow(unused_mut)]
58    pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
59        let mut new = self;
60        new.filter = Option::Some(Option::Some(value.into()));
61        new
62    }
63    /// Max number of groups in result
64    #[allow(unused_mut)]
65    pub fn limit(self, value: u32) -> Self {
66        let mut new = self;
67        new.limit = Option::Some(value);
68        new
69    }
70    /// Options for specifying which payload to include or not
71    #[allow(unused_mut)]
72    pub fn with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
73        self,
74        value: VALUE,
75    ) -> Self {
76        let mut new = self;
77        new.with_payload = Option::Some(value.into());
78        new
79    }
80    /// Search config
81    #[allow(unused_mut)]
82    pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
83        let mut new = self;
84        new.params = Option::Some(Option::Some(value.into()));
85        new
86    }
87    /// If provided - cut off results with worse scores
88    #[allow(unused_mut)]
89    pub fn score_threshold(self, value: f32) -> Self {
90        let mut new = self;
91        new.score_threshold = Option::Some(Option::Some(value));
92        new
93    }
94    /// Define which vector to use for recommendation, if not specified - default vector
95    #[allow(unused_mut)]
96    pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
97        let mut new = self;
98        new.using = 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<with_vectors_selector::SelectorOptions>>(
104        self,
105        value: VALUE,
106    ) -> Self {
107        let mut new = self;
108        new.with_vectors = Option::Some(value.into());
109        new
110    }
111    /// Name of the collection to use for points lookup, if not specified - use current collection
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    /// 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.
119    #[allow(unused_mut)]
120    pub fn group_by(self, value: String) -> Self {
121        let mut new = self;
122        new.group_by = Option::Some(value);
123        new
124    }
125    /// Maximum amount of points to return per group
126    #[allow(unused_mut)]
127    pub fn group_size(self, value: u32) -> Self {
128        let mut new = self;
129        new.group_size = Option::Some(value);
130        new
131    }
132    /// Options for specifying read consistency guarantees
133    #[allow(unused_mut)]
134    pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
135        self,
136        value: VALUE,
137    ) -> Self {
138        let mut new = self;
139        new.read_consistency = Option::Some(value.into());
140        new
141    }
142    /// Options for specifying how to use the group id to lookup points in another collection
143    #[allow(unused_mut)]
144    pub fn with_lookup<VALUE: core::convert::Into<WithLookup>>(self, value: VALUE) -> Self {
145        let mut new = self;
146        new.with_lookup = Option::Some(Option::Some(value.into()));
147        new
148    }
149    /// How to use the example vectors to find the results
150    #[allow(unused_mut)]
151    pub fn strategy<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
152        let mut new = self;
153        new.strategy = 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(self, value: u64) -> Self {
159        let mut new = self;
160        new.timeout = Option::Some(Option::Some(value));
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<RecommendPointGroups, RecommendPointGroupsBuilderError> {
175        Ok(RecommendPointGroups {
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            positive: self.positive.unwrap_or_default(),
185            negative: self.negative.unwrap_or_default(),
186            filter: self.filter.unwrap_or_default(),
187            limit: match self.limit {
188                Some(value) => value,
189                None => {
190                    return Result::Err(core::convert::Into::into(
191                        ::derive_builder::UninitializedFieldError::from("limit"),
192                    ));
193                }
194            },
195            with_payload: { convert_option(&self.with_payload) },
196            params: self.params.unwrap_or_default(),
197            score_threshold: self.score_threshold.unwrap_or_default(),
198            using: self.using.unwrap_or_default(),
199            with_vectors: { convert_option(&self.with_vectors) },
200            lookup_from: self.lookup_from.unwrap_or_default(),
201            group_by: match self.group_by {
202                Some(value) => value,
203                None => {
204                    return Result::Err(core::convert::Into::into(
205                        ::derive_builder::UninitializedFieldError::from("group_by"),
206                    ));
207                }
208            },
209            group_size: match self.group_size {
210                Some(value) => value,
211                None => {
212                    return Result::Err(core::convert::Into::into(
213                        ::derive_builder::UninitializedFieldError::from("group_size"),
214                    ));
215                }
216            },
217            read_consistency: { convert_option(&self.read_consistency) },
218            with_lookup: self.with_lookup.unwrap_or_default(),
219            strategy: self.strategy.unwrap_or_default(),
220            positive_vectors: self.positive_vectors.unwrap_or_default(),
221            negative_vectors: self.negative_vectors.unwrap_or_default(),
222            timeout: self.timeout.unwrap_or_default(),
223            shard_key_selector: self.shard_key_selector.unwrap_or_default(),
224        })
225    }
226    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
227    fn create_empty() -> Self {
228        Self {
229            collection_name: core::default::Default::default(),
230            positive: core::default::Default::default(),
231            negative: core::default::Default::default(),
232            filter: core::default::Default::default(),
233            limit: core::default::Default::default(),
234            with_payload: core::default::Default::default(),
235            params: core::default::Default::default(),
236            score_threshold: core::default::Default::default(),
237            using: core::default::Default::default(),
238            with_vectors: core::default::Default::default(),
239            lookup_from: core::default::Default::default(),
240            group_by: core::default::Default::default(),
241            group_size: core::default::Default::default(),
242            read_consistency: core::default::Default::default(),
243            with_lookup: core::default::Default::default(),
244            strategy: core::default::Default::default(),
245            positive_vectors: core::default::Default::default(),
246            negative_vectors: core::default::Default::default(),
247            timeout: core::default::Default::default(),
248            shard_key_selector: core::default::Default::default(),
249        }
250    }
251}
252
253impl From<RecommendPointGroupsBuilder> for RecommendPointGroups {
254    fn from(value: RecommendPointGroupsBuilder) -> Self {
255        value.build_inner().unwrap_or_else(|_| {
256            panic!(
257                "Failed to convert {0} to {1}",
258                "RecommendPointGroupsBuilder", "RecommendPointGroups"
259            )
260        })
261    }
262}
263
264impl RecommendPointGroupsBuilder {
265    /// Builds the desired type. Can often be omitted.
266    pub fn build(self) -> RecommendPointGroups {
267        self.build_inner().unwrap_or_else(|_| {
268            panic!(
269                "Failed to build {0} into {1}",
270                "RecommendPointGroupsBuilder", "RecommendPointGroups"
271            )
272        })
273    }
274}
275
276impl RecommendPointGroupsBuilder {
277    pub(crate) fn empty() -> Self {
278        Self::create_empty()
279    }
280}
281
282/// Error type for RecommendPointGroupsBuilder
283#[non_exhaustive]
284#[derive(Debug)]
285pub enum RecommendPointGroupsBuilderError {
286    /// Uninitialized field
287    UninitializedField(&'static str),
288    /// Custom validation error
289    ValidationError(String),
290}
291
292// Implementing the Display trait for better error messages
293impl std::fmt::Display for RecommendPointGroupsBuilderError {
294    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
295        match self {
296            Self::UninitializedField(field) => {
297                write!(f, "`{field}` must be initialized")
298            }
299            Self::ValidationError(error) => write!(f, "{error}"),
300        }
301    }
302}
303
304// Implementing the Error trait
305impl std::error::Error for RecommendPointGroupsBuilderError {}
306
307// Implementing From trait for conversion from UninitializedFieldError
308impl From<derive_builder::UninitializedFieldError> for RecommendPointGroupsBuilderError {
309    fn from(error: derive_builder::UninitializedFieldError) -> Self {
310        Self::UninitializedField(error.field_name())
311    }
312}
313
314// Implementing From trait for conversion from String
315impl From<String> for RecommendPointGroupsBuilderError {
316    fn from(error: String) -> Self {
317        Self::ValidationError(error)
318    }
319}