qdrant_client/builders/
recommend_points_builder.rs

1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[derive(Clone)]
5pub struct RecommendPointsBuilder {
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 result
15    pub(crate) limit: Option<u64>,
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    /// Offset of the result
23    pub(crate) offset: Option<Option<u64>>,
24    /// Define which vector to use for recommendation, if not specified - default vector
25    pub(crate) using: Option<Option<String>>,
26    /// Options for specifying which vectors to include into response
27    with_vectors: Option<with_vectors_selector::SelectorOptions>,
28    /// Name of the collection to use for points lookup, if not specified - use current collection
29    pub(crate) lookup_from: Option<Option<LookupLocation>>,
30    /// Options for specifying read consistency guarantees
31    read_consistency: Option<read_consistency::Value>,
32    /// How to use the example vectors to find the results
33    pub(crate) strategy: Option<Option<i32>>,
34    /// Look for vectors closest to those
35    pub(crate) positive_vectors: Option<Vec<Vector>>,
36    /// Try to avoid vectors like this
37    pub(crate) negative_vectors: Option<Vec<Vector>>,
38    /// If set, overrides global timeout setting for this request. Unit is seconds.
39    pub(crate) timeout: Option<Option<u64>>,
40    /// Specify in which shards to look for the points, if not specified - look in all shards
41    pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
42}
43
44impl RecommendPointsBuilder {
45    /// name of the collection
46    #[allow(unused_mut)]
47    pub fn collection_name(self, value: String) -> Self {
48        let mut new = self;
49        new.collection_name = Option::Some(value);
50        new
51    }
52    /// Filter conditions - return only those points that satisfy the specified conditions
53    #[allow(unused_mut)]
54    pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
55        let mut new = self;
56        new.filter = Option::Some(Option::Some(value.into()));
57        new
58    }
59    /// Max number of result
60    #[allow(unused_mut)]
61    pub fn limit(self, value: u64) -> Self {
62        let mut new = self;
63        new.limit = Option::Some(value);
64        new
65    }
66    /// Options for specifying which payload to include or not
67    #[allow(unused_mut)]
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    #[allow(unused_mut)]
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    #[allow(unused_mut)]
85    pub fn score_threshold(self, value: f32) -> Self {
86        let mut new = self;
87        new.score_threshold = Option::Some(Option::Some(value));
88        new
89    }
90    /// Offset of the result
91    #[allow(unused_mut)]
92    pub fn offset(self, value: u64) -> Self {
93        let mut new = self;
94        new.offset = Option::Some(Option::Some(value));
95        new
96    }
97    /// Define which vector to use for recommendation, if not specified - default vector
98    #[allow(unused_mut)]
99    pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
100        let mut new = self;
101        new.using = Option::Some(Option::Some(value.into()));
102        new
103    }
104    /// Options for specifying which vectors to include into response
105    #[allow(unused_mut)]
106    pub fn with_vectors<VALUE: core::convert::Into<with_vectors_selector::SelectorOptions>>(
107        self,
108        value: VALUE,
109    ) -> Self {
110        let mut new = self;
111        new.with_vectors = Option::Some(value.into());
112        new
113    }
114    /// Name of the collection to use for points lookup, if not specified - use current collection
115    #[allow(unused_mut)]
116    pub fn lookup_from<VALUE: core::convert::Into<LookupLocation>>(self, value: VALUE) -> Self {
117        let mut new = self;
118        new.lookup_from = Option::Some(Option::Some(value.into()));
119        new
120    }
121    /// Options for specifying read consistency guarantees
122    #[allow(unused_mut)]
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    /// How to use the example vectors to find the results
132    #[allow(unused_mut)]
133    pub fn strategy<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
134        let mut new = self;
135        new.strategy = Option::Some(Option::Some(value.into()));
136        new
137    }
138    /// If set, overrides global timeout setting for this request. Unit is seconds.
139    #[allow(unused_mut)]
140    pub fn timeout(self, value: u64) -> Self {
141        let mut new = self;
142        new.timeout = Option::Some(Option::Some(value));
143        new
144    }
145    /// Specify in which shards to look for the points, if not specified - look in all shards
146    #[allow(unused_mut)]
147    pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
148        self,
149        value: VALUE,
150    ) -> Self {
151        let mut new = self;
152        new.shard_key_selector = Option::Some(Option::Some(value.into()));
153        new
154    }
155
156    fn build_inner(self) -> Result<RecommendPoints, RecommendPointsBuilderError> {
157        Ok(RecommendPoints {
158            collection_name: match self.collection_name {
159                Some(value) => value,
160                None => {
161                    return Result::Err(core::convert::Into::into(
162                        ::derive_builder::UninitializedFieldError::from("collection_name"),
163                    ));
164                }
165            },
166            positive: self.positive.unwrap_or_default(),
167            negative: self.negative.unwrap_or_default(),
168            filter: self.filter.unwrap_or_default(),
169            limit: match self.limit {
170                Some(value) => value,
171                None => {
172                    return Result::Err(core::convert::Into::into(
173                        ::derive_builder::UninitializedFieldError::from("limit"),
174                    ));
175                }
176            },
177            with_payload: { convert_option(&self.with_payload) },
178            params: self.params.unwrap_or_default(),
179            score_threshold: self.score_threshold.unwrap_or_default(),
180            offset: self.offset.unwrap_or_default(),
181            using: self.using.unwrap_or_default(),
182            with_vectors: { convert_option(&self.with_vectors) },
183            lookup_from: self.lookup_from.unwrap_or_default(),
184            read_consistency: { convert_option(&self.read_consistency) },
185            strategy: self.strategy.unwrap_or_default(),
186            positive_vectors: self.positive_vectors.unwrap_or_default(),
187            negative_vectors: self.negative_vectors.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            positive: core::default::Default::default(),
197            negative: core::default::Default::default(),
198            filter: core::default::Default::default(),
199            limit: core::default::Default::default(),
200            with_payload: core::default::Default::default(),
201            params: core::default::Default::default(),
202            score_threshold: core::default::Default::default(),
203            offset: core::default::Default::default(),
204            using: core::default::Default::default(),
205            with_vectors: core::default::Default::default(),
206            lookup_from: core::default::Default::default(),
207            read_consistency: core::default::Default::default(),
208            strategy: core::default::Default::default(),
209            positive_vectors: core::default::Default::default(),
210            negative_vectors: core::default::Default::default(),
211            timeout: core::default::Default::default(),
212            shard_key_selector: core::default::Default::default(),
213        }
214    }
215}
216
217impl From<RecommendPointsBuilder> for RecommendPoints {
218    fn from(value: RecommendPointsBuilder) -> Self {
219        value.build_inner().unwrap_or_else(|_| {
220            panic!(
221                "Failed to convert {0} to {1}",
222                "RecommendPointsBuilder", "RecommendPoints"
223            )
224        })
225    }
226}
227
228impl RecommendPointsBuilder {
229    /// Builds the desired type. Can often be omitted.
230    pub fn build(self) -> RecommendPoints {
231        self.build_inner().unwrap_or_else(|_| {
232            panic!(
233                "Failed to build {0} into {1}",
234                "RecommendPointsBuilder", "RecommendPoints"
235            )
236        })
237    }
238}
239
240impl RecommendPointsBuilder {
241    pub(crate) fn empty() -> Self {
242        Self::create_empty()
243    }
244}
245
246/// Error type for RecommendPointsBuilder
247#[non_exhaustive]
248#[derive(Debug)]
249pub enum RecommendPointsBuilderError {
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 RecommendPointsBuilderError {
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 RecommendPointsBuilderError {}
270
271// Implementing From trait for conversion from UninitializedFieldError
272impl From<derive_builder::UninitializedFieldError> for RecommendPointsBuilderError {
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 RecommendPointsBuilderError {
280    fn from(error: String) -> Self {
281        Self::ValidationError(error)
282    }
283}