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            })
56        }
57    }
58
59    builder_type_conversions!(PointStructList, PointStructListBuilder);
60
61    #[derive(Clone)]
62    pub struct SetPayloadBuilder {
63        payload: HashMap<String, Value>,
64        points_selector: Option<PointsSelector>,
65        shard_key_selector: Option<ShardKeySelector>,
66        key: Option<String>,
67    }
68
69    impl SetPayloadBuilder {
70        pub fn new(payload: impl Into<HashMap<String, Value>>) -> Self {
71            Self {
72                payload: payload.into(),
73                points_selector: None,
74                shard_key_selector: None,
75                key: None,
76            }
77        }
78
79        /// Affected points
80        pub fn points_selector(
81            &mut self,
82            points_selector: impl Into<points_selector::PointsSelectorOneOf>,
83        ) -> &mut Self {
84            self.points_selector = Some(PointsSelector {
85                points_selector_one_of: Some(points_selector.into()),
86            });
87            self
88        }
89
90        /// Option for custom sharding to specify used shard keys
91        pub fn shard_key_selector(
92            &mut self,
93            shard_key_selector: impl Into<ShardKeySelector>,
94        ) -> &mut Self {
95            self.shard_key_selector = Some(shard_key_selector.into());
96            self
97        }
98
99        /// Option for indicate property of payload
100        pub fn key(&mut self, key: impl Into<String>) -> &mut Self {
101            self.key = Some(key.into());
102            self
103        }
104
105        fn build_inner(&self) -> Result<SetPayload, ()> {
106            let builder = self.clone();
107            Ok(SetPayload {
108                payload: builder.payload,
109                points_selector: builder.points_selector,
110                shard_key_selector: builder.shard_key_selector,
111                key: builder.key,
112            })
113        }
114    }
115
116    builder_type_conversions!(SetPayload, SetPayloadBuilder);
117
118    #[derive(Clone)]
119    pub struct OverwritePayloadBuilder {
120        payload: HashMap<String, Value>,
121        points_selector: Option<PointsSelector>,
122        shard_key_selector: Option<ShardKeySelector>,
123        key: Option<String>,
124    }
125
126    impl OverwritePayloadBuilder {
127        pub fn new(payload: impl Into<HashMap<String, Value>>) -> Self {
128            Self {
129                payload: payload.into(),
130                points_selector: None,
131                shard_key_selector: None,
132                key: None,
133            }
134        }
135
136        /// Affected points
137        pub fn points_selector(
138            &mut self,
139            points_selector: impl Into<points_selector::PointsSelectorOneOf>,
140        ) -> &mut Self {
141            self.points_selector = Some(PointsSelector {
142                points_selector_one_of: Some(points_selector.into()),
143            });
144            self
145        }
146
147        /// Option for custom sharding to specify used shard keys
148        pub fn shard_key_selector(
149            &mut self,
150            shard_key_selector: impl Into<ShardKeySelector>,
151        ) -> &mut Self {
152            self.shard_key_selector = Some(shard_key_selector.into());
153            self
154        }
155
156        /// Option for indicate property of payload
157        pub fn key(&mut self, key: impl Into<String>) -> &mut Self {
158            self.key = Some(key.into());
159            self
160        }
161
162        fn build_inner(&self) -> Result<OverwritePayload, ()> {
163            let builder = self.clone();
164            Ok(OverwritePayload {
165                payload: builder.payload,
166                points_selector: builder.points_selector,
167                shard_key_selector: builder.shard_key_selector,
168                key: builder.key,
169            })
170        }
171    }
172
173    builder_type_conversions!(OverwritePayload, OverwritePayloadBuilder);
174
175    #[derive(Clone)]
176    pub struct DeletePayloadBuilder {
177        keys: Vec<String>,
178        points_selector: Option<PointsSelector>,
179        shard_key_selector: Option<ShardKeySelector>,
180    }
181
182    impl DeletePayloadBuilder {
183        pub fn new(keys: impl Into<Vec<String>>) -> Self {
184            Self {
185                keys: keys.into(),
186                points_selector: None,
187                shard_key_selector: None,
188            }
189        }
190
191        /// Affected points
192        pub fn points_selector(
193            &mut self,
194            points_selector: impl Into<points_selector::PointsSelectorOneOf>,
195        ) -> &mut Self {
196            self.points_selector = Some(PointsSelector {
197                points_selector_one_of: Some(points_selector.into()),
198            });
199            self
200        }
201
202        /// Option for custom sharding to specify used shard keys
203        pub fn shard_key_selector(
204            &mut self,
205            shard_key_selector: impl Into<ShardKeySelector>,
206        ) -> &mut Self {
207            self.shard_key_selector = Some(shard_key_selector.into());
208            self
209        }
210
211        fn build_inner(&self) -> Result<DeletePayload, ()> {
212            let builder = self.clone();
213            Ok(DeletePayload {
214                keys: builder.keys,
215                points_selector: builder.points_selector,
216                shard_key_selector: builder.shard_key_selector,
217            })
218        }
219    }
220
221    builder_type_conversions!(DeletePayload, DeletePayloadBuilder);
222
223    #[derive(Clone)]
224    pub struct UpdateVectorsBuilder {
225        points: Vec<PointVectors>,
226        shard_key_selector: Option<ShardKeySelector>,
227    }
228
229    impl UpdateVectorsBuilder {
230        pub fn new(points: impl Into<Vec<PointVectors>>) -> Self {
231            Self {
232                points: points.into(),
233                shard_key_selector: None,
234            }
235        }
236
237        /// Option for custom sharding to specify used shard keys
238        pub fn shard_key_selector(
239            &mut self,
240            shard_key_selector: impl Into<ShardKeySelector>,
241        ) -> &mut Self {
242            self.shard_key_selector = Some(shard_key_selector.into());
243            self
244        }
245
246        fn build_inner(&self) -> Result<UpdateVectors, ()> {
247            let builder = self.clone();
248            Ok(UpdateVectors {
249                points: builder.points,
250                shard_key_selector: builder.shard_key_selector,
251            })
252        }
253    }
254
255    builder_type_conversions!(UpdateVectors, UpdateVectorsBuilder);
256
257    #[derive(Clone, Default)]
258    pub struct DeleteVectorsBuilder {
259        points_selector: Option<PointsSelector>,
260        vectors: Option<VectorsSelector>,
261        shard_key_selector: Option<ShardKeySelector>,
262    }
263
264    impl DeleteVectorsBuilder {
265        pub fn new() -> Self {
266            Self {
267                points_selector: None,
268                vectors: None,
269                shard_key_selector: None,
270            }
271        }
272
273        /// Affected points
274        pub fn points_selector(
275            &mut self,
276            points_selector: impl Into<points_selector::PointsSelectorOneOf>,
277        ) -> &mut Self {
278            self.points_selector = Some(PointsSelector {
279                points_selector_one_of: Some(points_selector.into()),
280            });
281            self
282        }
283
284        /// List of vector names to delete
285        pub fn vectors(&mut self, vectors: impl Into<VectorsSelector>) -> &mut Self {
286            self.vectors = Some(vectors.into());
287            self
288        }
289
290        /// Option for custom sharding to specify used shard keys
291        pub fn shard_key_selector(
292            &mut self,
293            shard_key_selector: impl Into<ShardKeySelector>,
294        ) -> &mut Self {
295            self.shard_key_selector = Some(shard_key_selector.into());
296            self
297        }
298
299        fn build_inner(&self) -> Result<DeleteVectors, ()> {
300            let builder = self.clone();
301            Ok(DeleteVectors {
302                points_selector: builder.points_selector,
303                vectors: builder.vectors,
304                shard_key_selector: builder.shard_key_selector,
305            })
306        }
307    }
308
309    builder_type_conversions!(DeleteVectors, DeleteVectorsBuilder);
310
311    #[derive(Clone, Default)]
312    pub struct DeletePointsBuilder {
313        points: Option<PointsSelector>,
314        shard_key_selector: Option<ShardKeySelector>,
315    }
316
317    impl DeletePointsBuilder {
318        pub fn new() -> Self {
319            Self {
320                points: None,
321                shard_key_selector: None,
322            }
323        }
324
325        /// Affected points
326        pub fn points(
327            &mut self,
328            points: impl Into<points_selector::PointsSelectorOneOf>,
329        ) -> &mut Self {
330            self.points = Some(PointsSelector {
331                points_selector_one_of: Some(points.into()),
332            });
333            self
334        }
335
336        /// Option for custom sharding to specify used shard keys
337        pub fn shard_key_selector(
338            &mut self,
339            shard_key_selector: impl Into<ShardKeySelector>,
340        ) -> &mut Self {
341            self.shard_key_selector = Some(shard_key_selector.into());
342            self
343        }
344
345        fn build_inner(&self) -> Result<DeletePoints, ()> {
346            let builder = self.clone();
347            Ok(DeletePoints {
348                points: builder.points,
349                shard_key_selector: builder.shard_key_selector,
350            })
351        }
352    }
353
354    builder_type_conversions!(DeletePoints, DeletePointsBuilder);
355
356    #[derive(Clone, Default)]
357    pub struct ClearPayloadBuilder {
358        points: Option<PointsSelector>,
359        shard_key_selector: Option<ShardKeySelector>,
360    }
361
362    impl ClearPayloadBuilder {
363        pub fn new() -> Self {
364            Self {
365                points: None,
366                shard_key_selector: None,
367            }
368        }
369
370        /// Affected points
371        pub fn points(
372            &mut self,
373            points: impl Into<points_selector::PointsSelectorOneOf>,
374        ) -> &mut Self {
375            self.points = Some(PointsSelector {
376                points_selector_one_of: Some(points.into()),
377            });
378            self
379        }
380
381        /// Option for custom sharding to specify used shard keys
382        pub fn shard_key_selector(
383            &mut self,
384            shard_key_selector: impl Into<ShardKeySelector>,
385        ) -> &mut Self {
386            self.shard_key_selector = Some(shard_key_selector.into());
387            self
388        }
389
390        fn build_inner(&self) -> Result<ClearPayload, ()> {
391            let builder = self.clone();
392            Ok(ClearPayload {
393                points: builder.points,
394                shard_key_selector: builder.shard_key_selector,
395            })
396        }
397    }
398
399    builder_type_conversions!(ClearPayload, ClearPayloadBuilder);
400}
401
402#[derive(Builder)]
403#[builder(
404    build_fn(private, name = "build_inner"),
405    pattern = "owned",
406    custom_constructor
407)]
408pub struct SnapshotDownload {
409    pub out_path: PathBuf,
410    pub collection_name: String,
411    #[builder(default, setter(strip_option, into))]
412    pub snapshot_name: Option<String>,
413    #[builder(default, setter(strip_option, into))]
414    pub rest_api_uri: Option<String>,
415}
416
417impl SnapshotDownloadBuilder {
418    pub fn new(out_path: impl Into<PathBuf>, collection_name: impl Into<String>) -> Self {
419        let mut builder = Self::create_empty();
420        builder.out_path = Some(out_path.into());
421        builder.collection_name = Some(collection_name.into());
422        builder
423    }
424
425    pub fn build(self) -> SnapshotDownload {
426        self.build_inner().unwrap()
427    }
428}
429
430impl From<SnapshotDownloadBuilder> for SnapshotDownload {
431    fn from(value: SnapshotDownloadBuilder) -> Self {
432        value.build()
433    }
434}