qdrant_client/
manual_builder.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
//! For service types which are in a sub-module in qdrant.rs we can't use dervie_builder if we
//! want to preserve consistency with the other builders. This is because the generated builders types are
//! private but for custom type conversions, build() function and constructor with required values we
//! need access to those private fields. For this reason we introduce a few manually created builder here.

use std::path::PathBuf;

use derive_builder::Builder;

/// Builder for service types within qdrant::points_update_operation.
/// This sub-module is necessary since we do a `use manual_builder::*` in the qdrant.rs file to have
/// all builder coming from qdrant.rs file in the user API. However there are some builder types here
/// whichs name is already part of the qdrant.rs module. This submodule prevents ambiguity for those builder.
pub mod points_update_operation {
    use std::collections::HashMap;

    use crate::grpc_macros::builder_type_conversions;
    use crate::qdrant::points_update_operation::{
        ClearPayload, DeletePayload, DeletePoints, DeleteVectors, OverwritePayload,
        PointStructList, SetPayload, UpdateVectors,
    };
    use crate::qdrant::{
        points_selector, PointStruct, PointVectors, PointsSelector, ShardKeySelector, Value,
        VectorsSelector,
    };

    #[derive(Clone)]
    pub struct PointStructListBuilder {
        points: Vec<PointStruct>,
        shard_key_selector: Option<ShardKeySelector>,
    }

    impl PointStructListBuilder {
        pub fn new(points: impl Into<Vec<PointStruct>>) -> Self {
            Self {
                points: points.into(),
                shard_key_selector: None,
            }
        }

        /// Option for custom sharding to specify used shard keys
        pub fn shard_key_selector(
            &mut self,
            shard_key_selector: impl Into<ShardKeySelector>,
        ) -> &mut Self {
            self.shard_key_selector = Some(shard_key_selector.into());
            self
        }

        fn build_inner(&self) -> Result<PointStructList, ()> {
            let builder = self.clone();
            Ok(PointStructList {
                points: builder.points,
                shard_key_selector: builder.shard_key_selector,
            })
        }
    }

    builder_type_conversions!(PointStructList, PointStructListBuilder);

    #[derive(Clone)]
    pub struct SetPayloadBuilder {
        payload: HashMap<String, Value>,
        points_selector: Option<PointsSelector>,
        shard_key_selector: Option<ShardKeySelector>,
        key: Option<String>,
    }

    impl SetPayloadBuilder {
        pub fn new(payload: impl Into<HashMap<String, Value>>) -> Self {
            Self {
                payload: payload.into(),
                points_selector: None,
                shard_key_selector: None,
                key: None,
            }
        }

        /// Affected points
        pub fn points_selector(
            &mut self,
            points_selector: impl Into<points_selector::PointsSelectorOneOf>,
        ) -> &mut Self {
            self.points_selector = Some(PointsSelector {
                points_selector_one_of: Some(points_selector.into()),
            });
            self
        }

        /// Option for custom sharding to specify used shard keys
        pub fn shard_key_selector(
            &mut self,
            shard_key_selector: impl Into<ShardKeySelector>,
        ) -> &mut Self {
            self.shard_key_selector = Some(shard_key_selector.into());
            self
        }

        /// Option for indicate property of payload
        pub fn key(&mut self, key: impl Into<String>) -> &mut Self {
            self.key = Some(key.into());
            self
        }

        fn build_inner(&self) -> Result<SetPayload, ()> {
            let builder = self.clone();
            Ok(SetPayload {
                payload: builder.payload,
                points_selector: builder.points_selector,
                shard_key_selector: builder.shard_key_selector,
                key: builder.key,
            })
        }
    }

    builder_type_conversions!(SetPayload, SetPayloadBuilder);

    #[derive(Clone)]
    pub struct OverwritePayloadBuilder {
        payload: HashMap<String, Value>,
        points_selector: Option<PointsSelector>,
        shard_key_selector: Option<ShardKeySelector>,
        key: Option<String>,
    }

    impl OverwritePayloadBuilder {
        pub fn new(payload: impl Into<HashMap<String, Value>>) -> Self {
            Self {
                payload: payload.into(),
                points_selector: None,
                shard_key_selector: None,
                key: None,
            }
        }

        /// Affected points
        pub fn points_selector(
            &mut self,
            points_selector: impl Into<points_selector::PointsSelectorOneOf>,
        ) -> &mut Self {
            self.points_selector = Some(PointsSelector {
                points_selector_one_of: Some(points_selector.into()),
            });
            self
        }

        /// Option for custom sharding to specify used shard keys
        pub fn shard_key_selector(
            &mut self,
            shard_key_selector: impl Into<ShardKeySelector>,
        ) -> &mut Self {
            self.shard_key_selector = Some(shard_key_selector.into());
            self
        }

        /// Option for indicate property of payload
        pub fn key(&mut self, key: impl Into<String>) -> &mut Self {
            self.key = Some(key.into());
            self
        }

        fn build_inner(&self) -> Result<OverwritePayload, ()> {
            let builder = self.clone();
            Ok(OverwritePayload {
                payload: builder.payload,
                points_selector: builder.points_selector,
                shard_key_selector: builder.shard_key_selector,
                key: builder.key,
            })
        }
    }

    builder_type_conversions!(OverwritePayload, OverwritePayloadBuilder);

    #[derive(Clone)]
    pub struct DeletePayloadBuilder {
        keys: Vec<String>,
        points_selector: Option<PointsSelector>,
        shard_key_selector: Option<ShardKeySelector>,
    }

    impl DeletePayloadBuilder {
        pub fn new(keys: impl Into<Vec<String>>) -> Self {
            Self {
                keys: keys.into(),
                points_selector: None,
                shard_key_selector: None,
            }
        }

        /// Affected points
        pub fn points_selector(
            &mut self,
            points_selector: impl Into<points_selector::PointsSelectorOneOf>,
        ) -> &mut Self {
            self.points_selector = Some(PointsSelector {
                points_selector_one_of: Some(points_selector.into()),
            });
            self
        }

        /// Option for custom sharding to specify used shard keys
        pub fn shard_key_selector(
            &mut self,
            shard_key_selector: impl Into<ShardKeySelector>,
        ) -> &mut Self {
            self.shard_key_selector = Some(shard_key_selector.into());
            self
        }

        fn build_inner(&self) -> Result<DeletePayload, ()> {
            let builder = self.clone();
            Ok(DeletePayload {
                keys: builder.keys,
                points_selector: builder.points_selector,
                shard_key_selector: builder.shard_key_selector,
            })
        }
    }

    builder_type_conversions!(DeletePayload, DeletePayloadBuilder);

    #[derive(Clone)]
    pub struct UpdateVectorsBuilder {
        points: Vec<PointVectors>,
        shard_key_selector: Option<ShardKeySelector>,
    }

    impl UpdateVectorsBuilder {
        pub fn new(points: impl Into<Vec<PointVectors>>) -> Self {
            Self {
                points: points.into(),
                shard_key_selector: None,
            }
        }

        /// Option for custom sharding to specify used shard keys
        pub fn shard_key_selector(
            &mut self,
            shard_key_selector: impl Into<ShardKeySelector>,
        ) -> &mut Self {
            self.shard_key_selector = Some(shard_key_selector.into());
            self
        }

        fn build_inner(&self) -> Result<UpdateVectors, ()> {
            let builder = self.clone();
            Ok(UpdateVectors {
                points: builder.points,
                shard_key_selector: builder.shard_key_selector,
            })
        }
    }

    builder_type_conversions!(UpdateVectors, UpdateVectorsBuilder);

    #[derive(Clone, Default)]
    pub struct DeleteVectorsBuilder {
        points_selector: Option<PointsSelector>,
        vectors: Option<VectorsSelector>,
        shard_key_selector: Option<ShardKeySelector>,
    }

    impl DeleteVectorsBuilder {
        pub fn new() -> Self {
            Self {
                points_selector: None,
                vectors: None,
                shard_key_selector: None,
            }
        }

        /// Affected points
        pub fn points_selector(
            &mut self,
            points_selector: impl Into<points_selector::PointsSelectorOneOf>,
        ) -> &mut Self {
            self.points_selector = Some(PointsSelector {
                points_selector_one_of: Some(points_selector.into()),
            });
            self
        }

        /// List of vector names to delete
        pub fn vectors(&mut self, vectors: impl Into<VectorsSelector>) -> &mut Self {
            self.vectors = Some(vectors.into());
            self
        }

        /// Option for custom sharding to specify used shard keys
        pub fn shard_key_selector(
            &mut self,
            shard_key_selector: impl Into<ShardKeySelector>,
        ) -> &mut Self {
            self.shard_key_selector = Some(shard_key_selector.into());
            self
        }

        fn build_inner(&self) -> Result<DeleteVectors, ()> {
            let builder = self.clone();
            Ok(DeleteVectors {
                points_selector: builder.points_selector,
                vectors: builder.vectors,
                shard_key_selector: builder.shard_key_selector,
            })
        }
    }

    builder_type_conversions!(DeleteVectors, DeleteVectorsBuilder);

    #[derive(Clone, Default)]
    pub struct DeletePointsBuilder {
        points: Option<PointsSelector>,
        shard_key_selector: Option<ShardKeySelector>,
    }

    impl DeletePointsBuilder {
        pub fn new() -> Self {
            Self {
                points: None,
                shard_key_selector: None,
            }
        }

        /// Affected points
        pub fn points(
            &mut self,
            points: impl Into<points_selector::PointsSelectorOneOf>,
        ) -> &mut Self {
            self.points = Some(PointsSelector {
                points_selector_one_of: Some(points.into()),
            });
            self
        }

        /// Option for custom sharding to specify used shard keys
        pub fn shard_key_selector(
            &mut self,
            shard_key_selector: impl Into<ShardKeySelector>,
        ) -> &mut Self {
            self.shard_key_selector = Some(shard_key_selector.into());
            self
        }

        fn build_inner(&self) -> Result<DeletePoints, ()> {
            let builder = self.clone();
            Ok(DeletePoints {
                points: builder.points,
                shard_key_selector: builder.shard_key_selector,
            })
        }
    }

    builder_type_conversions!(DeletePoints, DeletePointsBuilder);

    #[derive(Clone, Default)]
    pub struct ClearPayloadBuilder {
        points: Option<PointsSelector>,
        shard_key_selector: Option<ShardKeySelector>,
    }

    impl ClearPayloadBuilder {
        pub fn new() -> Self {
            Self {
                points: None,
                shard_key_selector: None,
            }
        }

        /// Affected points
        pub fn points(
            &mut self,
            points: impl Into<points_selector::PointsSelectorOneOf>,
        ) -> &mut Self {
            self.points = Some(PointsSelector {
                points_selector_one_of: Some(points.into()),
            });
            self
        }

        /// Option for custom sharding to specify used shard keys
        pub fn shard_key_selector(
            &mut self,
            shard_key_selector: impl Into<ShardKeySelector>,
        ) -> &mut Self {
            self.shard_key_selector = Some(shard_key_selector.into());
            self
        }

        fn build_inner(&self) -> Result<ClearPayload, ()> {
            let builder = self.clone();
            Ok(ClearPayload {
                points: builder.points,
                shard_key_selector: builder.shard_key_selector,
            })
        }
    }

    builder_type_conversions!(ClearPayload, ClearPayloadBuilder);
}

#[derive(Builder)]
#[builder(
    build_fn(private, name = "build_inner"),
    pattern = "owned",
    custom_constructor
)]
pub struct SnapshotDownload {
    pub out_path: PathBuf,
    pub collection_name: String,
    #[builder(default, setter(strip_option, into))]
    pub snapshot_name: Option<String>,
    #[builder(default, setter(strip_option, into))]
    pub rest_api_uri: Option<String>,
}

impl SnapshotDownloadBuilder {
    pub fn new(out_path: impl Into<PathBuf>, collection_name: impl Into<String>) -> Self {
        let mut builder = Self::create_empty();
        builder.out_path = Some(out_path.into());
        builder.collection_name = Some(collection_name.into());
        builder
    }

    pub fn build(self) -> SnapshotDownload {
        self.build_inner().unwrap()
    }
}

impl From<SnapshotDownloadBuilder> for SnapshotDownload {
    fn from(value: SnapshotDownloadBuilder) -> Self {
        value.build()
    }
}