1use std::collections::HashMap;
2
3use crate::qdrant::update_collection_cluster_setup_request::Operation;
4use crate::qdrant::{
5 shard_key, AbortShardTransferBuilder, BinaryQuantizationBuilder, ClearPayloadPointsBuilder,
6 ContextExamplePair, CountPointsBuilder, CreateAliasBuilder, CreateCollectionBuilder,
7 CreateFieldIndexCollectionBuilder, CreateShardKeyRequestBuilder, DeleteCollectionBuilder,
8 DeleteFieldIndexCollectionBuilder, DeletePayloadPointsBuilder, DeletePointVectorsBuilder,
9 DeletePointsBuilder, DeleteShardKey, DeleteShardKeyRequestBuilder,
10 DeleteSnapshotRequestBuilder, DiscoverBatchPointsBuilder, DiscoverPoints,
11 DiscoverPointsBuilder, Distance, FacetCountsBuilder, FieldType, GetPointsBuilder,
12 LookupLocationBuilder, MoveShardBuilder, PayloadExcludeSelector, PayloadIncludeSelector,
13 PointId, PointStruct, PointVectors, PointsUpdateOperation, ProductQuantizationBuilder,
14 QuantizationType, QueryBatchPointsBuilder, QueryPointGroupsBuilder, QueryPoints,
15 QueryPointsBuilder, RecommendBatchPointsBuilder, RecommendExample, RecommendPointGroupsBuilder,
16 RecommendPoints, RecommendPointsBuilder, RenameAliasBuilder, ReplicaBuilder,
17 ReplicateShardBuilder, ScalarQuantizationBuilder, ScrollPointsBuilder,
18 SearchBatchPointsBuilder, SearchMatrixPointsBuilder, SearchPointGroupsBuilder, SearchPoints,
19 SearchPointsBuilder, SetPayloadPointsBuilder, ShardKey, UpdateBatchPointsBuilder,
20 UpdateCollectionBuilder, UpdateCollectionClusterSetupRequestBuilder, UpdatePointVectorsBuilder,
21 UpsertPointsBuilder, Value, VectorParamsBuilder, VectorsSelector, WithLookupBuilder,
22};
23
24impl VectorParamsBuilder {
25 pub fn new(size: u64, distance: Distance) -> Self {
26 let mut builder = Self::empty();
27 builder.size = Some(size);
28 builder.distance = Some(distance.into());
29 builder
30 }
31}
32
33impl Default for ScalarQuantizationBuilder {
34 fn default() -> Self {
35 let mut builder = Self::empty();
36 builder.r#type = Some(QuantizationType::Int8.into());
37 builder
38 }
39}
40
41impl ProductQuantizationBuilder {
42 pub fn new(compression: i32) -> Self {
43 let mut builder = Self::empty();
44 builder.compression = Some(compression);
45 builder
46 }
47}
48
49impl BinaryQuantizationBuilder {
50 pub fn new(always_ram: bool) -> Self {
51 let mut builder = Self::empty();
52 builder.always_ram = Some(Some(always_ram));
53 builder
54 }
55}
56
57impl SearchPointsBuilder {
58 pub fn new(
59 collection_name: impl Into<String>,
60 vector: impl Into<Vec<f32>>,
61 limit: u64,
62 ) -> Self {
63 let mut builder = Self::empty();
64 builder.collection_name = Some(collection_name.into());
65 builder.vector = Some(vector.into());
66 builder.limit = Some(limit);
67 builder
68 }
69}
70
71impl UpdateCollectionBuilder {
72 pub fn new(collection_name: impl Into<String>) -> Self {
73 let mut builder = Self::empty();
74 builder.collection_name = Some(collection_name.into());
75 builder
76 }
77}
78
79impl SetPayloadPointsBuilder {
80 pub fn new(
81 collection_name: impl Into<String>,
82 payload: impl Into<HashMap<String, Value>>,
83 ) -> Self {
84 let mut builder = Self::empty();
85 builder.collection_name = Some(collection_name.into());
86 builder.payload = Some(payload.into());
87 builder
88 }
89}
90
91impl UpdateBatchPointsBuilder {
92 pub fn new(
93 collection_name: impl Into<String>,
94 operations: impl Into<Vec<PointsUpdateOperation>>,
95 ) -> Self {
96 let mut builder = Self::empty();
97 builder.collection_name = Some(collection_name.into());
98 builder.operations = Some(operations.into());
99 builder
100 }
101}
102
103impl DeletePayloadPointsBuilder {
104 pub fn new(collection_name: impl Into<String>, keys: impl Into<Vec<String>>) -> Self {
105 let mut builder = Self::empty();
106 builder.collection_name = Some(collection_name.into());
107 builder.keys = Some(keys.into());
108 builder
109 }
110}
111
112impl ClearPayloadPointsBuilder {
113 pub fn new(collection_name: impl Into<String>) -> Self {
114 let mut builder = Self::empty();
115 builder.collection_name = Some(collection_name.into());
116 builder
117 }
118}
119
120impl GetPointsBuilder {
121 pub fn new(collection_name: impl Into<String>, ids: impl Into<Vec<PointId>>) -> Self {
122 let mut builder = Self::empty();
123 builder.collection_name = Some(collection_name.into());
124 builder.ids = Some(ids.into());
125 builder
126 }
127}
128
129impl SearchBatchPointsBuilder {
130 pub fn new(
131 collection_name: impl Into<String>,
132 search_points: impl Into<Vec<SearchPoints>>,
133 ) -> Self {
134 let mut builder = Self::empty();
135 builder.collection_name = Some(collection_name.into());
136 builder.search_points = Some(search_points.into());
137 builder
138 }
139}
140
141impl SearchPointGroupsBuilder {
142 pub fn new(
143 collection_name: impl Into<String>,
144 vector: impl Into<Vec<f32>>,
145 limit: u32,
146 group_by: impl Into<String>,
147 group_size: u32,
148 ) -> Self {
149 let mut builder = Self::empty();
150 builder.collection_name = Some(collection_name.into());
151 builder.vector = Some(vector.into());
152 builder.limit = Some(limit);
153 builder.group_by = Some(group_by.into());
154 builder.group_size = Some(group_size);
155 builder
156 }
157}
158
159impl WithLookupBuilder {
160 pub fn new(collection: impl Into<String>) -> Self {
161 let mut builder = Self::empty();
162 builder.collection = Some(collection.into());
163 builder
164 }
165}
166
167impl DeletePointsBuilder {
168 pub fn new(collection_name: impl Into<String>) -> Self {
169 let mut builder = Self::empty();
170 builder.collection_name = Some(collection_name.into());
171 builder
172 }
173}
174
175impl DeletePointVectorsBuilder {
176 pub fn new(collection_name: impl Into<String>) -> Self {
177 let mut builder = Self::empty();
178 builder.collection_name = Some(collection_name.into());
179 builder
180 }
181}
182
183impl UpdatePointVectorsBuilder {
184 pub fn new(collection_name: impl Into<String>, points: impl Into<Vec<PointVectors>>) -> Self {
185 let mut builder = Self::empty();
186 builder.collection_name = Some(collection_name.into());
187 builder.points = Some(points.into());
188 builder
189 }
190}
191
192impl ScrollPointsBuilder {
193 pub fn new(collection_name: impl Into<String>) -> Self {
194 let mut builder = Self::empty();
195 builder.collection_name = Some(collection_name.into());
196 builder
197 }
198}
199
200impl RecommendPointsBuilder {
201 pub fn new(collection_name: impl Into<String>, limit: u64) -> Self {
202 let mut builder = Self::empty();
203 builder.collection_name = Some(collection_name.into());
204 builder.limit = Some(limit);
205 builder
206 }
207}
208
209impl LookupLocationBuilder {
210 pub fn new(collection_name: impl Into<String>) -> Self {
211 let mut builder = Self::empty();
212 builder.collection_name = Some(collection_name.into());
213 builder
214 }
215}
216
217impl RecommendBatchPointsBuilder {
218 pub fn new(
219 collection_name: impl Into<String>,
220 recommend_points: impl Into<Vec<RecommendPoints>>,
221 ) -> Self {
222 let mut builder = Self::empty();
223 builder.collection_name = Some(collection_name.into());
224 builder.recommend_points = Some(recommend_points.into());
225 builder
226 }
227}
228
229impl RecommendPointGroupsBuilder {
230 pub fn new(
231 collection_name: impl Into<String>,
232 group_by: impl Into<String>,
233 group_size: u32,
234 limit: u32,
235 ) -> Self {
236 let mut builder = Self::empty();
237 builder.collection_name = Some(collection_name.into());
238 builder.group_by = Some(group_by.into());
239 builder.group_size = Some(group_size);
240 builder.limit = Some(limit);
241 builder
242 }
243}
244
245impl DiscoverPointsBuilder {
246 pub fn new(
247 collection_name: impl Into<String>,
248 context: impl Into<Vec<ContextExamplePair>>,
249 limit: u64,
250 ) -> Self {
251 let mut builder = Self::empty();
252 builder.collection_name = Some(collection_name.into());
253 builder.context = Some(context.into());
254 builder.limit = Some(limit);
255 builder
256 }
257}
258
259impl DiscoverBatchPointsBuilder {
260 pub fn new(
261 collection_name: impl Into<String>,
262 discover_points: impl Into<Vec<DiscoverPoints>>,
263 ) -> Self {
264 let mut builder = Self::empty();
265 builder.collection_name = Some(collection_name.into());
266 builder.discover_points = Some(discover_points.into());
267 builder
268 }
269}
270
271impl CountPointsBuilder {
272 pub fn new(collection_name: impl Into<String>) -> Self {
273 let mut builder = Self::empty();
274 builder.collection_name = Some(collection_name.into());
275 builder
276 }
277}
278
279impl UpsertPointsBuilder {
280 pub fn new(collection_name: impl Into<String>, points: impl Into<Vec<PointStruct>>) -> Self {
281 let mut builder = Self::empty();
282 builder.collection_name = Some(collection_name.into());
283 builder.points = Some(points.into());
284 builder
285 }
286}
287
288impl CreateFieldIndexCollectionBuilder {
289 pub fn new(
290 collection_name: impl Into<String>,
291 field_name: impl Into<String>,
292 field_type: FieldType,
293 ) -> Self {
294 let mut builder = Self::empty();
295 builder.collection_name = Some(collection_name.into());
296 builder.field_name = Some(field_name.into());
297 builder.field_type(field_type)
298 }
299}
300
301impl DeleteFieldIndexCollectionBuilder {
302 pub fn new(collection_name: impl Into<String>, field_name: impl Into<String>) -> Self {
303 let mut builder = Self::empty();
304 builder.collection_name = Some(collection_name.into());
305 builder.field_name = Some(field_name.into());
306 builder
307 }
308}
309
310impl UpdateCollectionClusterSetupRequestBuilder {
311 pub fn new(collection_name: impl Into<String>, operation: impl Into<Operation>) -> Self {
312 let mut builder = Self::empty();
313 builder.collection_name = Some(collection_name.into());
314 builder.operation = Some(Some(operation.into()));
315 builder
316 }
317}
318
319impl MoveShardBuilder {
320 pub fn new(shard_id: u32, from_peer_id: u64, to_peer_id: u64) -> Self {
321 let mut builder = Self::empty();
322 builder.shard_id = Some(shard_id);
323 builder.from_peer_id = Some(from_peer_id);
324 builder.to_peer_id = Some(to_peer_id);
325 builder
326 }
327}
328
329impl ReplicateShardBuilder {
330 pub fn new(shard_id: u32, from_peer_id: u64, to_peer_id: u64) -> Self {
331 let mut builder = Self::empty();
332 builder.shard_id = Some(shard_id);
333 builder.from_peer_id = Some(from_peer_id);
334 builder.to_peer_id = Some(to_peer_id);
335 builder
336 }
337}
338
339impl AbortShardTransferBuilder {
340 pub fn new(shard_id: u32, from_peer_id: u64, to_peer_id: u64) -> Self {
341 let mut builder = Self::empty();
342 builder.shard_id = Some(shard_id);
343 builder.from_peer_id = Some(from_peer_id);
344 builder.to_peer_id = Some(to_peer_id);
345 builder
346 }
347}
348
349impl ReplicaBuilder {
350 pub fn new(shard_id: u32, peer_id: u64) -> Self {
351 let mut builder = Self::empty();
352 builder.shard_id = Some(shard_id);
353 builder.peer_id = Some(peer_id);
354 builder
355 }
356}
357
358impl CreateShardKeyRequestBuilder {
359 pub fn new(collection_name: impl Into<String>) -> Self {
360 let mut builder = Self::empty();
361 builder.collection_name = Some(collection_name.into());
362 builder
363 }
364}
365
366impl DeleteShardKeyRequestBuilder {
367 pub fn new(collection_name: impl Into<String>) -> Self {
368 let mut builder = Self::empty();
369 builder.collection_name = Some(collection_name.into());
370 builder
371 }
372
373 pub fn key(mut self, key: impl Into<shard_key::Key>) -> Self {
375 self.request = Some(Some(DeleteShardKey {
376 shard_key: Some(ShardKey {
377 key: Some(key.into()),
378 }),
379 }));
380 self
381 }
382}
383
384impl DeleteCollectionBuilder {
385 pub fn new(collection_name: impl Into<String>) -> Self {
386 let mut builder = Self::empty();
387 builder.collection_name = Some(collection_name.into());
388 builder
389 }
390}
391
392impl PayloadIncludeSelector {
393 pub fn new(fileds: impl Into<Vec<String>>) -> Self {
394 Self {
395 fields: fileds.into(),
396 }
397 }
398}
399
400impl PayloadExcludeSelector {
401 pub fn new(fileds: impl Into<Vec<String>>) -> Self {
402 Self {
403 fields: fileds.into(),
404 }
405 }
406}
407
408impl VectorsSelector {
409 pub fn new(names: impl Into<Vec<String>>) -> Self {
410 Self {
411 names: names.into(),
412 }
413 }
414}
415
416impl RecommendPointsBuilder {
417 pub fn add_positive(mut self, recommend_example: impl Into<RecommendExample>) -> Self {
419 let recommend_example = recommend_example.into();
420 match recommend_example {
421 RecommendExample::PointId(point_id) => {
422 self.positive.get_or_insert_with(Vec::new).push(point_id);
423 }
424 RecommendExample::Vector(vector) => {
425 self.positive_vectors
426 .get_or_insert_with(Vec::new)
427 .push(vector);
428 }
429 }
430 self
431 }
432
433 pub fn add_negative(mut self, recommend_example: impl Into<RecommendExample>) -> Self {
435 let recommend_example = recommend_example.into();
436 match recommend_example {
437 RecommendExample::PointId(point_id) => {
438 self.negative.get_or_insert_with(Vec::new).push(point_id);
439 }
440 RecommendExample::Vector(vector) => {
441 self.negative_vectors
442 .get_or_insert_with(Vec::new)
443 .push(vector);
444 }
445 }
446 self
447 }
448}
449
450impl RecommendPointGroupsBuilder {
451 pub fn add_positive(mut self, recommend_example: impl Into<RecommendExample>) -> Self {
453 let recommend_example = recommend_example.into();
454 match recommend_example {
455 RecommendExample::PointId(point_id) => {
456 self.positive.get_or_insert_with(Vec::new).push(point_id);
457 }
458 RecommendExample::Vector(vector) => {
459 self.positive_vectors
460 .get_or_insert_with(Vec::new)
461 .push(vector);
462 }
463 }
464 self
465 }
466
467 pub fn add_negative(mut self, recommend_example: impl Into<RecommendExample>) -> Self {
469 let recommend_example = recommend_example.into();
470 match recommend_example {
471 RecommendExample::PointId(point_id) => {
472 self.negative.get_or_insert_with(Vec::new).push(point_id);
473 }
474 RecommendExample::Vector(vector) => {
475 self.negative_vectors
476 .get_or_insert_with(Vec::new)
477 .push(vector);
478 }
479 }
480 self
481 }
482}
483
484impl CreateCollectionBuilder {
485 pub fn new(collection_name: impl Into<String>) -> Self {
486 Self::default().collection_name(collection_name)
487 }
488}
489
490impl CreateAliasBuilder {
491 pub fn new(collection_name: impl Into<String>, alias_name: impl Into<String>) -> Self {
492 let mut builder = Self::empty();
493 builder.collection_name = Some(collection_name.into());
494 builder.alias_name = Some(alias_name.into());
495 builder
496 }
497}
498
499impl RenameAliasBuilder {
500 pub fn new(old_alias_name: impl Into<String>, new_alias_name: impl Into<String>) -> Self {
501 let mut builder = Self::empty();
502 builder.old_alias_name = Some(old_alias_name.into());
503 builder.new_alias_name = Some(new_alias_name.into());
504 builder
505 }
506}
507
508impl QueryPointsBuilder {
509 pub fn new(collection_name: impl Into<String>) -> Self {
510 let mut builder = Self::empty();
511 builder.collection_name = Some(collection_name.into());
512 builder
513 }
514}
515
516impl QueryBatchPointsBuilder {
517 pub fn new(
518 collection_name: impl Into<String>,
519 query_points: impl Into<Vec<QueryPoints>>,
520 ) -> Self {
521 let mut builder = Self::empty();
522 builder.collection_name = Some(collection_name.into());
523 builder.query_points = Some(query_points.into());
524 builder
525 }
526}
527
528impl DeleteSnapshotRequestBuilder {
529 pub fn new(collection_name: impl Into<String>, snapshot_name: impl Into<String>) -> Self {
530 let mut builder = Self::empty();
531 builder.collection_name = Some(collection_name.into());
532 builder.snapshot_name = Some(snapshot_name.into());
533 builder
534 }
535}
536
537impl QueryPointGroupsBuilder {
538 pub fn new(
539 collection_name: impl Into<String>,
540 group_by: impl Into<String>,
541 ) -> QueryPointGroupsBuilder {
542 let mut builder = Self::empty();
543 builder.collection_name = Some(collection_name.into());
544 builder.group_by = Some(group_by.into());
545 builder
546 }
547}
548
549impl FacetCountsBuilder {
550 pub fn new(collection_name: impl Into<String>, key: impl Into<String>) -> FacetCountsBuilder {
551 let mut builder = Self::empty();
552 builder.collection_name = Some(collection_name.into());
553 builder.key = Some(key.into());
554 builder
555 }
556}
557
558impl SearchMatrixPointsBuilder {
559 pub fn new(collection_name: impl Into<String>) -> SearchMatrixPointsBuilder {
560 let mut builder = Self::empty();
561 builder.collection_name = Some(collection_name.into());
562 builder
563 }
564}