qdrant_client/builders/
discover_points_builder.rs

1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[derive(Clone)]
5pub struct DiscoverPointsBuilder {
6    /// name of the collection
7    pub(crate) collection_name: Option<String>,
8    /// Use this as the primary search objective
9    pub(crate) target: Option<Option<TargetVector>>,
10    /// Search will be constrained by these pairs of examples
11    pub(crate) context: Option<Vec<ContextExamplePair>>,
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    /// Offset of the result
21    pub(crate) offset: Option<Option<u64>>,
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    /// Options for specifying read consistency guarantees
29    read_consistency: Option<read_consistency::Value>,
30    /// If set, overrides global timeout setting for this request. Unit is seconds.
31    pub(crate) timeout: Option<Option<u64>>,
32    /// Specify in which shards to look for the points, if not specified - look in all shards
33    pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
34}
35
36impl DiscoverPointsBuilder {
37    /// name of the collection
38    #[allow(unused_mut)]
39    pub fn collection_name(self, value: String) -> Self {
40        let mut new = self;
41        new.collection_name = Option::Some(value);
42        new
43    }
44    /// Use this as the primary search objective
45    #[allow(unused_mut)]
46    pub fn target<VALUE: core::convert::Into<TargetVector>>(self, value: VALUE) -> Self {
47        let mut new = self;
48        new.target = Option::Some(Option::Some(value.into()));
49        new
50    }
51    /// Search will be constrained by these pairs of examples
52    #[allow(unused_mut)]
53    pub fn context(self, value: Vec<ContextExamplePair>) -> Self {
54        let mut new = self;
55        new.context = Option::Some(value);
56        new
57    }
58    /// Filter conditions - return only those points that satisfy the specified conditions
59    #[allow(unused_mut)]
60    pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
61        let mut new = self;
62        new.filter = Option::Some(Option::Some(value.into()));
63        new
64    }
65    /// Max number of result
66    #[allow(unused_mut)]
67    pub fn limit(self, value: u64) -> Self {
68        let mut new = self;
69        new.limit = Option::Some(value);
70        new
71    }
72    /// Options for specifying which payload to include or not
73    #[allow(unused_mut)]
74    pub fn with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
75        self,
76        value: VALUE,
77    ) -> Self {
78        let mut new = self;
79        new.with_payload = Option::Some(value.into());
80        new
81    }
82    /// Search config
83    #[allow(unused_mut)]
84    pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
85        let mut new = self;
86        new.params = Option::Some(Option::Some(value.into()));
87        new
88    }
89    /// Offset of the result
90    #[allow(unused_mut)]
91    pub fn offset(self, value: u64) -> Self {
92        let mut new = self;
93        new.offset = Option::Some(Option::Some(value));
94        new
95    }
96    /// Define which vector to use for recommendation, if not specified - default vector
97    #[allow(unused_mut)]
98    pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
99        let mut new = self;
100        new.using = Option::Some(Option::Some(value.into()));
101        new
102    }
103    /// Options for specifying which vectors to include into response
104    #[allow(unused_mut)]
105    pub fn with_vectors<VALUE: core::convert::Into<with_vectors_selector::SelectorOptions>>(
106        self,
107        value: VALUE,
108    ) -> Self {
109        let mut new = self;
110        new.with_vectors = Option::Some(value.into());
111        new
112    }
113    /// Name of the collection to use for points lookup, if not specified - use current collection
114    #[allow(unused_mut)]
115    pub fn lookup_from<VALUE: core::convert::Into<LookupLocation>>(self, value: VALUE) -> Self {
116        let mut new = self;
117        new.lookup_from = Option::Some(Option::Some(value.into()));
118        new
119    }
120    /// Options for specifying read consistency guarantees
121    #[allow(unused_mut)]
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    /// If set, overrides global timeout setting for this request. Unit is seconds.
131    #[allow(unused_mut)]
132    pub fn timeout(self, value: u64) -> Self {
133        let mut new = self;
134        new.timeout = Option::Some(Option::Some(value));
135        new
136    }
137    /// Specify in which shards to look for the points, if not specified - look in all shards
138    #[allow(unused_mut)]
139    pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
140        self,
141        value: VALUE,
142    ) -> Self {
143        let mut new = self;
144        new.shard_key_selector = Option::Some(Option::Some(value.into()));
145        new
146    }
147
148    fn build_inner(self) -> Result<DiscoverPoints, DiscoverPointsBuilderError> {
149        Ok(DiscoverPoints {
150            collection_name: match self.collection_name {
151                Some(value) => value,
152                None => {
153                    return Result::Err(core::convert::Into::into(
154                        ::derive_builder::UninitializedFieldError::from("collection_name"),
155                    ));
156                }
157            },
158            target: self.target.unwrap_or_default(),
159            context: match self.context {
160                Some(value) => value,
161                None => {
162                    return Result::Err(core::convert::Into::into(
163                        ::derive_builder::UninitializedFieldError::from("context"),
164                    ));
165                }
166            },
167            filter: self.filter.unwrap_or_default(),
168            limit: match self.limit {
169                Some(value) => value,
170                None => {
171                    return Result::Err(core::convert::Into::into(
172                        ::derive_builder::UninitializedFieldError::from("limit"),
173                    ));
174                }
175            },
176            with_payload: { convert_option(&self.with_payload) },
177            params: self.params.unwrap_or_default(),
178            offset: self.offset.unwrap_or_default(),
179            using: self.using.unwrap_or_default(),
180            with_vectors: { convert_option(&self.with_vectors) },
181            lookup_from: self.lookup_from.unwrap_or_default(),
182            read_consistency: { convert_option(&self.read_consistency) },
183            timeout: self.timeout.unwrap_or_default(),
184            shard_key_selector: self.shard_key_selector.unwrap_or_default(),
185        })
186    }
187    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
188    fn create_empty() -> Self {
189        Self {
190            collection_name: core::default::Default::default(),
191            target: core::default::Default::default(),
192            context: core::default::Default::default(),
193            filter: core::default::Default::default(),
194            limit: core::default::Default::default(),
195            with_payload: core::default::Default::default(),
196            params: core::default::Default::default(),
197            offset: core::default::Default::default(),
198            using: core::default::Default::default(),
199            with_vectors: core::default::Default::default(),
200            lookup_from: core::default::Default::default(),
201            read_consistency: core::default::Default::default(),
202            timeout: core::default::Default::default(),
203            shard_key_selector: core::default::Default::default(),
204        }
205    }
206}
207
208impl From<DiscoverPointsBuilder> for DiscoverPoints {
209    fn from(value: DiscoverPointsBuilder) -> Self {
210        value.build_inner().unwrap_or_else(|_| {
211            panic!(
212                "Failed to convert {0} to {1}",
213                "DiscoverPointsBuilder", "DiscoverPoints"
214            )
215        })
216    }
217}
218
219impl DiscoverPointsBuilder {
220    /// Builds the desired type. Can often be omitted.
221    pub fn build(self) -> DiscoverPoints {
222        self.build_inner().unwrap_or_else(|_| {
223            panic!(
224                "Failed to build {0} into {1}",
225                "DiscoverPointsBuilder", "DiscoverPoints"
226            )
227        })
228    }
229}
230
231impl DiscoverPointsBuilder {
232    pub(crate) fn empty() -> Self {
233        Self::create_empty()
234    }
235}
236
237/// Error type for DiscoverPointsBuilder
238#[non_exhaustive]
239#[derive(Debug)]
240pub enum DiscoverPointsBuilderError {
241    /// Uninitialized field
242    UninitializedField(&'static str),
243    /// Custom validation error
244    ValidationError(String),
245}
246
247// Implementing the Display trait for better error messages
248impl std::fmt::Display for DiscoverPointsBuilderError {
249    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
250        match self {
251            Self::UninitializedField(field) => {
252                write!(f, "`{field}` must be initialized")
253            }
254            Self::ValidationError(error) => write!(f, "{error}"),
255        }
256    }
257}
258
259// Implementing the Error trait
260impl std::error::Error for DiscoverPointsBuilderError {}
261
262// Implementing From trait for conversion from UninitializedFieldError
263impl From<derive_builder::UninitializedFieldError> for DiscoverPointsBuilderError {
264    fn from(error: derive_builder::UninitializedFieldError) -> Self {
265        Self::UninitializedField(error.field_name())
266    }
267}
268
269// Implementing From trait for conversion from String
270impl From<String> for DiscoverPointsBuilderError {
271    fn from(error: String) -> Self {
272        Self::ValidationError(error)
273    }
274}