Skip to main content

qdrant_client/builders/
recommend_point_groups_builder.rs

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