qdrant_client/
manual_builder.rs

1//! For service types which are in a sub-module in qdrant.rs we can't use dervie_builder if we
2//! want to preserve consistency with the other builders. This is because the generated builders types are
3//! private but for custom type conversions, build() function and constructor with required values we
4//! need access to those private fields. For this reason we introduce a few manually created builder here.
5
6use std::path::PathBuf;
7
8use derive_builder::Builder;
9
10/// Builder for service types within qdrant::points_update_operation.
11/// This sub-module is necessary since we do a `use manual_builder::*` in the qdrant.rs file to have
12/// all builder coming from qdrant.rs file in the user API. However there are some builder types here
13/// whichs name is already part of the qdrant.rs module. This submodule prevents ambiguity for those builder.
14pub mod points_update_operation {
15    use std::collections::HashMap;
16
17    use crate::grpc_macros::builder_type_conversions;
18    use crate::qdrant::points_update_operation::{
19        ClearPayload, DeletePayload, DeletePoints, DeleteVectors, OverwritePayload,
20        PointStructList, SetPayload, UpdateVectors,
21    };
22    use crate::qdrant::{
23        points_selector, PointStruct, PointVectors, PointsSelector, ShardKeySelector, Value,
24        VectorsSelector,
25    };
26
27    #[derive(Clone)]
28    pub struct PointStructListBuilder {
29        points: Vec<PointStruct>,
30        shard_key_selector: Option<ShardKeySelector>,
31    }
32
33    impl PointStructListBuilder {
34        pub fn new(points: impl Into<Vec<PointStruct>>) -> Self {
35            Self {
36                points: points.into(),
37                shard_key_selector: None,
38            }
39        }
40
41        /// Option for custom sharding to specify used shard keys
42        pub fn shard_key_selector(
43            &mut self,
44            shard_key_selector: impl Into<ShardKeySelector>,
45        ) -> &mut Self {
46            self.shard_key_selector = Some(shard_key_selector.into());
47            self
48        }
49
50        fn build_inner(&self) -> Result<PointStructList, ()> {
51            let builder = self.clone();
52            Ok(PointStructList {
53                points: builder.points,
54                shard_key_selector: builder.shard_key_selector,
55                update_filter: None,
56            })
57        }
58    }
59
60    builder_type_conversions!(PointStructList, PointStructListBuilder);
61
62    #[derive(Clone)]
63    pub struct SetPayloadBuilder {
64        payload: HashMap<String, Value>,
65        points_selector: Option<PointsSelector>,
66        shard_key_selector: Option<ShardKeySelector>,
67        key: Option<String>,
68    }
69
70    impl SetPayloadBuilder {
71        pub fn new(payload: impl Into<HashMap<String, Value>>) -> Self {
72            Self {
73                payload: payload.into(),
74                points_selector: None,
75                shard_key_selector: None,
76                key: None,
77            }
78        }
79
80        /// Affected points
81        pub fn points_selector(
82            &mut self,
83            points_selector: impl Into<points_selector::PointsSelectorOneOf>,
84        ) -> &mut Self {
85            self.points_selector = Some(PointsSelector {
86                points_selector_one_of: Some(points_selector.into()),
87            });
88            self
89        }
90
91        /// Option for custom sharding to specify used shard keys
92        pub fn shard_key_selector(
93            &mut self,
94            shard_key_selector: impl Into<ShardKeySelector>,
95        ) -> &mut Self {
96            self.shard_key_selector = Some(shard_key_selector.into());
97            self
98        }
99
100        /// Option for indicate property of payload
101        pub fn key(&mut self, key: impl Into<String>) -> &mut Self {
102            self.key = Some(key.into());
103            self
104        }
105
106        fn build_inner(&self) -> Result<SetPayload, ()> {
107            let builder = self.clone();
108            Ok(SetPayload {
109                payload: builder.payload,
110                points_selector: builder.points_selector,
111                shard_key_selector: builder.shard_key_selector,
112                key: builder.key,
113            })
114        }
115    }
116
117    builder_type_conversions!(SetPayload, SetPayloadBuilder);
118
119    #[derive(Clone)]
120    pub struct OverwritePayloadBuilder {
121        payload: HashMap<String, Value>,
122        points_selector: Option<PointsSelector>,
123        shard_key_selector: Option<ShardKeySelector>,
124        key: Option<String>,
125    }
126
127    impl OverwritePayloadBuilder {
128        pub fn new(payload: impl Into<HashMap<String, Value>>) -> Self {
129            Self {
130                payload: payload.into(),
131                points_selector: None,
132                shard_key_selector: None,
133                key: None,
134            }
135        }
136
137        /// Affected points
138        pub fn points_selector(
139            &mut self,
140            points_selector: impl Into<points_selector::PointsSelectorOneOf>,
141        ) -> &mut Self {
142            self.points_selector = Some(PointsSelector {
143                points_selector_one_of: Some(points_selector.into()),
144            });
145            self
146        }
147
148        /// Option for custom sharding to specify used shard keys
149        pub fn shard_key_selector(
150            &mut self,
151            shard_key_selector: impl Into<ShardKeySelector>,
152        ) -> &mut Self {
153            self.shard_key_selector = Some(shard_key_selector.into());
154            self
155        }
156
157        /// Option for indicate property of payload
158        pub fn key(&mut self, key: impl Into<String>) -> &mut Self {
159            self.key = Some(key.into());
160            self
161        }
162
163        fn build_inner(&self) -> Result<OverwritePayload, ()> {
164            let builder = self.clone();
165            Ok(OverwritePayload {
166                payload: builder.payload,
167                points_selector: builder.points_selector,
168                shard_key_selector: builder.shard_key_selector,
169                key: builder.key,
170            })
171        }
172    }
173
174    builder_type_conversions!(OverwritePayload, OverwritePayloadBuilder);
175
176    #[derive(Clone)]
177    pub struct DeletePayloadBuilder {
178        keys: Vec<String>,
179        points_selector: Option<PointsSelector>,
180        shard_key_selector: Option<ShardKeySelector>,
181    }
182
183    impl DeletePayloadBuilder {
184        pub fn new(keys: impl Into<Vec<String>>) -> Self {
185            Self {
186                keys: keys.into(),
187                points_selector: None,
188                shard_key_selector: None,
189            }
190        }
191
192        /// Affected points
193        pub fn points_selector(
194            &mut self,
195            points_selector: impl Into<points_selector::PointsSelectorOneOf>,
196        ) -> &mut Self {
197            self.points_selector = Some(PointsSelector {
198                points_selector_one_of: Some(points_selector.into()),
199            });
200            self
201        }
202
203        /// Option for custom sharding to specify used shard keys
204        pub fn shard_key_selector(
205            &mut self,
206            shard_key_selector: impl Into<ShardKeySelector>,
207        ) -> &mut Self {
208            self.shard_key_selector = Some(shard_key_selector.into());
209            self
210        }
211
212        fn build_inner(&self) -> Result<DeletePayload, ()> {
213            let builder = self.clone();
214            Ok(DeletePayload {
215                keys: builder.keys,
216                points_selector: builder.points_selector,
217                shard_key_selector: builder.shard_key_selector,
218            })
219        }
220    }
221
222    builder_type_conversions!(DeletePayload, DeletePayloadBuilder);
223
224    #[derive(Clone)]
225    pub struct UpdateVectorsBuilder {
226        points: Vec<PointVectors>,
227        shard_key_selector: Option<ShardKeySelector>,
228    }
229
230    impl UpdateVectorsBuilder {
231        pub fn new(points: impl Into<Vec<PointVectors>>) -> Self {
232            Self {
233                points: points.into(),
234                shard_key_selector: None,
235            }
236        }
237
238        /// Option for custom sharding to specify used shard keys
239        pub fn shard_key_selector(
240            &mut self,
241            shard_key_selector: impl Into<ShardKeySelector>,
242        ) -> &mut Self {
243            self.shard_key_selector = Some(shard_key_selector.into());
244            self
245        }
246
247        fn build_inner(&self) -> Result<UpdateVectors, ()> {
248            let builder = self.clone();
249            Ok(UpdateVectors {
250                points: builder.points,
251                shard_key_selector: builder.shard_key_selector,
252                update_filter: None,
253            })
254        }
255    }
256
257    builder_type_conversions!(UpdateVectors, UpdateVectorsBuilder);
258
259    #[derive(Clone, Default)]
260    pub struct DeleteVectorsBuilder {
261        points_selector: Option<PointsSelector>,
262        vectors: Option<VectorsSelector>,
263        shard_key_selector: Option<ShardKeySelector>,
264    }
265
266    impl DeleteVectorsBuilder {
267        pub fn new() -> Self {
268            Self {
269                points_selector: None,
270                vectors: None,
271                shard_key_selector: None,
272            }
273        }
274
275        /// Affected points
276        pub fn points_selector(
277            &mut self,
278            points_selector: impl Into<points_selector::PointsSelectorOneOf>,
279        ) -> &mut Self {
280            self.points_selector = Some(PointsSelector {
281                points_selector_one_of: Some(points_selector.into()),
282            });
283            self
284        }
285
286        /// List of vector names to delete
287        pub fn vectors(&mut self, vectors: impl Into<VectorsSelector>) -> &mut Self {
288            self.vectors = Some(vectors.into());
289            self
290        }
291
292        /// Option for custom sharding to specify used shard keys
293        pub fn shard_key_selector(
294            &mut self,
295            shard_key_selector: impl Into<ShardKeySelector>,
296        ) -> &mut Self {
297            self.shard_key_selector = Some(shard_key_selector.into());
298            self
299        }
300
301        fn build_inner(&self) -> Result<DeleteVectors, ()> {
302            let builder = self.clone();
303            Ok(DeleteVectors {
304                points_selector: builder.points_selector,
305                vectors: builder.vectors,
306                shard_key_selector: builder.shard_key_selector,
307            })
308        }
309    }
310
311    builder_type_conversions!(DeleteVectors, DeleteVectorsBuilder);
312
313    #[derive(Clone, Default)]
314    pub struct DeletePointsBuilder {
315        points: Option<PointsSelector>,
316        shard_key_selector: Option<ShardKeySelector>,
317    }
318
319    impl DeletePointsBuilder {
320        pub fn new() -> Self {
321            Self {
322                points: None,
323                shard_key_selector: None,
324            }
325        }
326
327        /// Affected points
328        pub fn points(
329            &mut self,
330            points: impl Into<points_selector::PointsSelectorOneOf>,
331        ) -> &mut Self {
332            self.points = Some(PointsSelector {
333                points_selector_one_of: Some(points.into()),
334            });
335            self
336        }
337
338        /// Option for custom sharding to specify used shard keys
339        pub fn shard_key_selector(
340            &mut self,
341            shard_key_selector: impl Into<ShardKeySelector>,
342        ) -> &mut Self {
343            self.shard_key_selector = Some(shard_key_selector.into());
344            self
345        }
346
347        fn build_inner(&self) -> Result<DeletePoints, ()> {
348            let builder = self.clone();
349            Ok(DeletePoints {
350                points: builder.points,
351                shard_key_selector: builder.shard_key_selector,
352            })
353        }
354    }
355
356    builder_type_conversions!(DeletePoints, DeletePointsBuilder);
357
358    #[derive(Clone, Default)]
359    pub struct ClearPayloadBuilder {
360        points: Option<PointsSelector>,
361        shard_key_selector: Option<ShardKeySelector>,
362    }
363
364    impl ClearPayloadBuilder {
365        pub fn new() -> Self {
366            Self {
367                points: None,
368                shard_key_selector: None,
369            }
370        }
371
372        /// Affected points
373        pub fn points(
374            &mut self,
375            points: impl Into<points_selector::PointsSelectorOneOf>,
376        ) -> &mut Self {
377            self.points = Some(PointsSelector {
378                points_selector_one_of: Some(points.into()),
379            });
380            self
381        }
382
383        /// Option for custom sharding to specify used shard keys
384        pub fn shard_key_selector(
385            &mut self,
386            shard_key_selector: impl Into<ShardKeySelector>,
387        ) -> &mut Self {
388            self.shard_key_selector = Some(shard_key_selector.into());
389            self
390        }
391
392        fn build_inner(&self) -> Result<ClearPayload, ()> {
393            let builder = self.clone();
394            Ok(ClearPayload {
395                points: builder.points,
396                shard_key_selector: builder.shard_key_selector,
397            })
398        }
399    }
400
401    builder_type_conversions!(ClearPayload, ClearPayloadBuilder);
402}
403
404#[derive(Builder)]
405#[builder(
406    build_fn(private, name = "build_inner"),
407    pattern = "owned",
408    custom_constructor
409)]
410pub struct SnapshotDownload {
411    pub out_path: PathBuf,
412    pub collection_name: String,
413    #[builder(default, setter(strip_option, into))]
414    pub snapshot_name: Option<String>,
415    #[builder(default, setter(strip_option, into))]
416    pub rest_api_uri: Option<String>,
417}
418
419impl SnapshotDownloadBuilder {
420    pub fn new(out_path: impl Into<PathBuf>, collection_name: impl Into<String>) -> Self {
421        let mut builder = Self::create_empty();
422        builder.out_path = Some(out_path.into());
423        builder.collection_name = Some(collection_name.into());
424        builder
425    }
426
427    pub fn build(self) -> SnapshotDownload {
428        self.build_inner().unwrap()
429    }
430}
431
432impl From<SnapshotDownloadBuilder> for SnapshotDownload {
433    fn from(value: SnapshotDownloadBuilder) -> Self {
434        value.build()
435    }
436}