Skip to main content

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    pub fn collection_name(self, value: String) -> Self {
51        let mut new = self;
52        new.collection_name = Option::Some(value);
53        new
54    }
55    /// Filter conditions - return only those points that satisfy the specified conditions
56    pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
57        let mut new = self;
58        new.filter = Option::Some(Option::Some(value.into()));
59        new
60    }
61    /// Max number of groups in result
62    pub fn limit(self, value: u32) -> Self {
63        let mut new = self;
64        new.limit = Option::Some(value);
65        new
66    }
67    /// Options for specifying which payload to include or not
68    pub fn with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
69        self,
70        value: VALUE,
71    ) -> Self {
72        let mut new = self;
73        new.with_payload = Option::Some(value.into());
74        new
75    }
76    /// Search config
77    pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
78        let mut new = self;
79        new.params = Option::Some(Option::Some(value.into()));
80        new
81    }
82    /// If provided - cut off results with worse scores
83    pub fn score_threshold(self, value: f32) -> Self {
84        let mut new = self;
85        new.score_threshold = Option::Some(Option::Some(value));
86        new
87    }
88    /// Define which vector to use for recommendation, if not specified - default vector
89    pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
90        let mut new = self;
91        new.using = 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<with_vectors_selector::SelectorOptions>>(
96        self,
97        value: VALUE,
98    ) -> Self {
99        let mut new = self;
100        new.with_vectors = Option::Some(value.into());
101        new
102    }
103    /// Name of the collection to use for points lookup, if not specified - use current collection
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    /// 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.
110    pub fn group_by(self, value: String) -> Self {
111        let mut new = self;
112        new.group_by = Option::Some(value);
113        new
114    }
115    /// Maximum amount of points to return per group
116    pub fn group_size(self, value: u32) -> Self {
117        let mut new = self;
118        new.group_size = Option::Some(value);
119        new
120    }
121    /// Options for specifying read consistency guarantees
122    pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
123        self,
124        value: VALUE,
125    ) -> Self {
126        let mut new = self;
127        new.read_consistency = Option::Some(value.into());
128        new
129    }
130    /// Options for specifying how to use the group id to lookup points in another collection
131    pub fn with_lookup<VALUE: core::convert::Into<WithLookup>>(self, value: VALUE) -> Self {
132        let mut new = self;
133        new.with_lookup = Option::Some(Option::Some(value.into()));
134        new
135    }
136    /// How to use the example vectors to find the results
137    pub fn strategy<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
138        let mut new = self;
139        new.strategy = 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(self, value: u64) -> Self {
144        let mut new = self;
145        new.timeout = Option::Some(Option::Some(value));
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<RecommendPointGroups, RecommendPointGroupsBuilderError> {
159        Ok(RecommendPointGroups {
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            positive: self.positive.unwrap_or_default(),
169            negative: self.negative.unwrap_or_default(),
170            filter: self.filter.unwrap_or_default(),
171            limit: match self.limit {
172                Some(value) => value,
173                None => {
174                    return Result::Err(core::convert::Into::into(
175                        ::derive_builder::UninitializedFieldError::from("limit"),
176                    ));
177                }
178            },
179            with_payload: { convert_option(&self.with_payload) },
180            params: self.params.unwrap_or_default(),
181            score_threshold: self.score_threshold.unwrap_or_default(),
182            using: self.using.unwrap_or_default(),
183            with_vectors: { convert_option(&self.with_vectors) },
184            lookup_from: self.lookup_from.unwrap_or_default(),
185            group_by: match self.group_by {
186                Some(value) => value,
187                None => {
188                    return Result::Err(core::convert::Into::into(
189                        ::derive_builder::UninitializedFieldError::from("group_by"),
190                    ));
191                }
192            },
193            group_size: match self.group_size {
194                Some(value) => value,
195                None => {
196                    return Result::Err(core::convert::Into::into(
197                        ::derive_builder::UninitializedFieldError::from("group_size"),
198                    ));
199                }
200            },
201            read_consistency: { convert_option(&self.read_consistency) },
202            with_lookup: self.with_lookup.unwrap_or_default(),
203            strategy: self.strategy.unwrap_or_default(),
204            positive_vectors: self.positive_vectors.unwrap_or_default(),
205            negative_vectors: self.negative_vectors.unwrap_or_default(),
206            timeout: self.timeout.unwrap_or_default(),
207            shard_key_selector: self.shard_key_selector.unwrap_or_default(),
208        })
209    }
210    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
211    fn create_empty() -> Self {
212        Self {
213            collection_name: core::default::Default::default(),
214            positive: core::default::Default::default(),
215            negative: core::default::Default::default(),
216            filter: core::default::Default::default(),
217            limit: core::default::Default::default(),
218            with_payload: core::default::Default::default(),
219            params: core::default::Default::default(),
220            score_threshold: core::default::Default::default(),
221            using: core::default::Default::default(),
222            with_vectors: core::default::Default::default(),
223            lookup_from: core::default::Default::default(),
224            group_by: core::default::Default::default(),
225            group_size: core::default::Default::default(),
226            read_consistency: core::default::Default::default(),
227            with_lookup: core::default::Default::default(),
228            strategy: core::default::Default::default(),
229            positive_vectors: core::default::Default::default(),
230            negative_vectors: core::default::Default::default(),
231            timeout: core::default::Default::default(),
232            shard_key_selector: core::default::Default::default(),
233        }
234    }
235}
236
237impl From<RecommendPointGroupsBuilder> for RecommendPointGroups {
238    fn from(value: RecommendPointGroupsBuilder) -> Self {
239        value.build_inner().unwrap_or_else(|_| {
240            panic!(
241                "Failed to convert {0} to {1}",
242                "RecommendPointGroupsBuilder", "RecommendPointGroups"
243            )
244        })
245    }
246}
247
248impl RecommendPointGroupsBuilder {
249    /// Builds the desired type. Can often be omitted.
250    pub fn build(self) -> RecommendPointGroups {
251        self.build_inner().unwrap_or_else(|_| {
252            panic!(
253                "Failed to build {0} into {1}",
254                "RecommendPointGroupsBuilder", "RecommendPointGroups"
255            )
256        })
257    }
258}
259
260impl RecommendPointGroupsBuilder {
261    pub(crate) fn empty() -> Self {
262        Self::create_empty()
263    }
264}
265
266/// Error type for RecommendPointGroupsBuilder
267#[non_exhaustive]
268#[derive(Debug)]
269pub enum RecommendPointGroupsBuilderError {
270    /// Uninitialized field
271    UninitializedField(&'static str),
272    /// Custom validation error
273    ValidationError(String),
274}
275
276// Implementing the Display trait for better error messages
277impl std::fmt::Display for RecommendPointGroupsBuilderError {
278    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
279        match self {
280            Self::UninitializedField(field) => {
281                write!(f, "`{field}` must be initialized")
282            }
283            Self::ValidationError(error) => write!(f, "{error}"),
284        }
285    }
286}
287
288// Implementing the Error trait
289impl std::error::Error for RecommendPointGroupsBuilderError {}
290
291// Implementing From trait for conversion from UninitializedFieldError
292impl From<derive_builder::UninitializedFieldError> for RecommendPointGroupsBuilderError {
293    fn from(error: derive_builder::UninitializedFieldError) -> Self {
294        Self::UninitializedField(error.field_name())
295    }
296}
297
298// Implementing From trait for conversion from String
299impl From<String> for RecommendPointGroupsBuilderError {
300    fn from(error: String) -> Self {
301        Self::ValidationError(error)
302    }
303}