From 930f5a7d6fb9bda849dcf1f8526b4843f4cac14c Mon Sep 17 00:00:00 2001 From: Jojii <15957865+JojiiOfficial@users.noreply.github.com> Date: Fri, 3 May 2024 15:53:34 +0200 Subject: [PATCH] add builder for DeletePayloadPoints, ClearPayloadPoints, GetPoints, (#112) SearchBatchPoints --- src/qdrant.rs | 101 +++++++++++++++++++++++++++++ tests/builder_coverage.rs | 9 ++- tests/protos.rs | 52 +++++++++++++++ tests/protos_append/builder_ext.rs | 38 +++++++++++ 4 files changed, 198 insertions(+), 2 deletions(-) diff --git a/src/qdrant.rs b/src/qdrant.rs index 9d840d6..0ab6f61 100644 --- a/src/qdrant.rs +++ b/src/qdrant.rs @@ -2654,6 +2654,8 @@ pub struct DeletePoints { #[prost(message, optional, tag = "5")] pub shard_key_selector: ::core::option::Option, } +#[derive(derive_builder::Builder)] +#[builder(build_fn(private, name = "build_inner"), custom_constructor)] #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetPoints { @@ -2665,15 +2667,37 @@ pub struct GetPoints { pub ids: ::prost::alloc::vec::Vec, /// Options for specifying which payload to include or not #[prost(message, optional, tag = "4")] + #[builder( + setter(into, strip_option), + field( + ty = "Option", + build = "convert_option(&self.with_payload)" + ) + )] pub with_payload: ::core::option::Option, /// Options for specifying which vectors to include into response #[prost(message, optional, tag = "5")] + #[builder( + setter(into, strip_option), + field( + ty = "Option", + build = "convert_option(&self.with_vectors)" + ) + )] pub with_vectors: ::core::option::Option, /// Options for specifying read consistency guarantees #[prost(message, optional, tag = "6")] + #[builder( + setter(into, strip_option), + field( + ty = "Option", + build = "convert_option(&self.read_consistency)" + ) + )] pub read_consistency: ::core::option::Option, /// Specify in which shards to look for the points, if not specified - look in all shards #[prost(message, optional, tag = "7")] + #[builder(default, setter(into, strip_option))] pub shard_key_selector: ::core::option::Option, } #[allow(clippy::derive_partial_eq_without_eq)] @@ -2765,6 +2789,8 @@ pub struct SetPayloadPoints { #[builder(default, setter(into, strip_option))] pub key: ::core::option::Option<::prost::alloc::string::String>, } +#[derive(derive_builder::Builder)] +#[builder(build_fn(private, name = "build_inner"), custom_constructor)] #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct DeletePayloadPoints { @@ -2773,20 +2799,32 @@ pub struct DeletePayloadPoints { pub collection_name: ::prost::alloc::string::String, /// Wait until the changes have been applied? #[prost(bool, optional, tag = "2")] + #[builder(default, setter(strip_option))] pub wait: ::core::option::Option, /// List of keys to delete #[prost(string, repeated, tag = "3")] pub keys: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, /// Affected points #[prost(message, optional, tag = "5")] + #[builder( + setter(into, strip_option), + field( + ty = "Option", + build = "convert_option(&self.points_selector)" + ) + )] pub points_selector: ::core::option::Option, /// Write ordering guarantees #[prost(message, optional, tag = "6")] + #[builder(default, setter(into, strip_option))] pub ordering: ::core::option::Option, /// Option for custom sharding to specify used shard keys #[prost(message, optional, tag = "7")] + #[builder(default, setter(into, strip_option))] pub shard_key_selector: ::core::option::Option, } +#[derive(derive_builder::Builder)] +#[builder(build_fn(private, name = "build_inner"), custom_constructor)] #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct ClearPayloadPoints { @@ -2795,15 +2833,25 @@ pub struct ClearPayloadPoints { pub collection_name: ::prost::alloc::string::String, /// Wait until the changes have been applied? #[prost(bool, optional, tag = "2")] + #[builder(default, setter(strip_option))] pub wait: ::core::option::Option, /// Affected points #[prost(message, optional, tag = "3")] + #[builder( + setter(into, strip_option), + field( + ty = "Option", + build = "convert_option(&self.points)" + ) + )] pub points: ::core::option::Option, /// Write ordering guarantees #[prost(message, optional, tag = "4")] + #[builder(default, setter(into, strip_option))] pub ordering: ::core::option::Option, /// Option for custom sharding to specify used shard keys #[prost(message, optional, tag = "5")] + #[builder(default, setter(into, strip_option))] pub shard_key_selector: ::core::option::Option, } #[allow(clippy::derive_partial_eq_without_eq)] @@ -3059,6 +3107,8 @@ pub struct SearchPoints { #[builder(default, setter(into, strip_option))] pub sparse_indices: ::core::option::Option, } +#[derive(derive_builder::Builder)] +#[builder(build_fn(private, name = "build_inner"), custom_constructor)] #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct SearchBatchPoints { @@ -3069,9 +3119,17 @@ pub struct SearchBatchPoints { pub search_points: ::prost::alloc::vec::Vec, /// Options for specifying read consistency guarantees #[prost(message, optional, tag = "3")] + #[builder( + setter(into, strip_option), + field( + ty = "Option", + build = "convert_option(&self.read_consistency)" + ) + )] pub read_consistency: ::core::option::Option, /// If set, overrides global timeout setting for this request. Unit is seconds. #[prost(uint64, optional, tag = "4")] + #[builder(default, setter(strip_option))] pub timeout: ::core::option::Option, } #[allow(clippy::derive_partial_eq_without_eq)] @@ -3087,6 +3145,7 @@ pub struct WithLookup { #[prost(message, optional, tag = "3")] pub with_vectors: ::core::option::Option, } + #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct SearchPointGroups { @@ -6967,6 +7026,10 @@ builder_type_conversions!(UpdateCollection, UpdateCollectionBuilder); builder_type_conversions!(SetPayloadPoints, SetPayloadPointsBuilder); builder_type_conversions!(UpsertPoints, UpsertPointsBuilder); builder_type_conversions!(UpdateBatchPoints, UpdateBatchPointsBuilder); +builder_type_conversions!(DeletePayloadPoints, DeletePayloadPointsBuilder); +builder_type_conversions!(ClearPayloadPoints, ClearPayloadPointsBuilder); +builder_type_conversions!(GetPoints, GetPointsBuilder); +builder_type_conversions!(SearchBatchPoints, SearchBatchPointsBuilder); use std::collections::HashMap; @@ -7048,3 +7111,41 @@ impl UpdateBatchPointsBuilder { builder } } + +impl DeletePayloadPointsBuilder { + pub fn new(collection_name: impl Into, keys: impl Into>) -> Self { + let mut builder = Self::create_empty(); + builder.collection_name = Some(collection_name.into()); + builder.keys = Some(keys.into()); + builder + } +} + +impl ClearPayloadPointsBuilder { + pub fn new(collection_name: impl Into) -> Self { + let mut builder = Self::create_empty(); + builder.collection_name = Some(collection_name.into()); + builder + } +} + +impl GetPointsBuilder { + pub fn new(collection_name: impl Into, ids: impl Into>) -> Self { + let mut builder = Self::create_empty(); + builder.collection_name = Some(collection_name.into()); + builder.ids = Some(ids.into()); + builder + } +} + +impl SearchBatchPointsBuilder { + pub fn new( + collection_name: impl Into, + search_points: impl Into>, + ) -> Self { + let mut builder = Self::create_empty(); + builder.collection_name = Some(collection_name.into()); + builder.search_points = Some(search_points.into()); + builder + } +} diff --git a/tests/builder_coverage.rs b/tests/builder_coverage.rs index 3a607fa..637f80b 100644 --- a/tests/builder_coverage.rs +++ b/tests/builder_coverage.rs @@ -1,7 +1,8 @@ use qdrant_client::prelude::Distance; use qdrant_client::qdrant::{ - BinaryQuantizationBuilder, ProductQuantizationBuilder, QuantizationType, - ScalarQuantizationBuilder, SearchPointsBuilder, SetPayloadPointsBuilder, + BinaryQuantizationBuilder, ClearPayloadPointsBuilder, DeletePayloadPointsBuilder, + GetPointsBuilder, ProductQuantizationBuilder, QuantizationType, ScalarQuantizationBuilder, + SearchBatchPointsBuilder, SearchPointsBuilder, SetPayloadPointsBuilder, UpdateBatchPointsBuilder, UpdateCollectionBuilder, VectorParamsBuilder, }; use std::collections::HashMap; @@ -27,4 +28,8 @@ fn builder_coverage() { UpdateCollectionBuilder::new("mycollection").build(); SetPayloadPointsBuilder::new("mycollection", HashMap::default()).build(); UpdateBatchPointsBuilder::new("mycollection", vec![]).build(); + DeletePayloadPointsBuilder::new("mycollection", vec![]).build(); + ClearPayloadPointsBuilder::new("mycollection").build(); + GetPointsBuilder::new("mycollection", vec![]).build(); + SearchBatchPointsBuilder::new("mycollection", vec![]).build(); } diff --git a/tests/protos.rs b/tests/protos.rs index ee5b12d..37161c4 100644 --- a/tests/protos.rs +++ b/tests/protos.rs @@ -245,6 +245,45 @@ fn configure_builder(builder: Builder) -> Builder { // UpdateBatchPoints ("UpdateBatchPoints.wait", DEFAULT_OPTION), ("UpdateBatchPoints.ordering", DEFAULT_OPTION_INTO), + // DeletePayloadPoints + ("DeletePayloadPoints.wait", DEFAULT_OPTION), + ( + "DeletePayloadPoints.points_selector", + builder_custom_into!(points_selector::PointsSelectorOneOf, self.points_selector), + ), + ("DeletePayloadPoints.ordering", DEFAULT_OPTION_INTO), + ( + "DeletePayloadPoints.shard_key_selector", + DEFAULT_OPTION_INTO, + ), + // ClearPayloadPoints + ("ClearPayloadPoints.wait", DEFAULT_OPTION), + ( + "ClearPayloadPoints.points", + builder_custom_into!(points_selector::PointsSelectorOneOf, self.points), + ), + ("ClearPayloadPoints.ordering", DEFAULT_OPTION_INTO), + ("ClearPayloadPoints.shard_key_selector", DEFAULT_OPTION_INTO), + // GetPoints + ( + "GetPoints.with_payload", + builder_custom_into!(with_payload_selector::SelectorOptions, self.with_payload), + ), + ( + "GetPoints.with_vectors", + builder_custom_into!(with_vectors_selector::SelectorOptions, self.with_vectors), + ), + ( + "GetPoints.read_consistency", + builder_custom_into!(read_consistency::Value, self.read_consistency), + ), + ("GetPoints.shard_key_selector", DEFAULT_OPTION_INTO), + // SearchBatchPoints + ( + "SearchBatchPoints.read_consistency", + builder_custom_into!(read_consistency::Value, self.read_consistency), + ), + ("SearchBatchPoints.timeout", DEFAULT_OPTION), ], builder_derive_options(), ) @@ -293,6 +332,19 @@ fn builder_derive_options() -> &'static [BuildDeriveOptions] { ("SetPayloadPoints", NO_DEFAULT_BUILDER_DERIVE_OPTIONS, true), ("UpsertPoints", NO_DEFAULT_BUILDER_DERIVE_OPTIONS, true), ("UpdateBatchPoints", NO_DEFAULT_BUILDER_DERIVE_OPTIONS, true), + ( + "DeletePayloadPoints", + NO_DEFAULT_BUILDER_DERIVE_OPTIONS, + true, + ), + ( + "ClearPayloadPoints", + NO_DEFAULT_BUILDER_DERIVE_OPTIONS, + true, + ), + // GetPoints + ("GetPoints", NO_DEFAULT_BUILDER_DERIVE_OPTIONS, true), + ("SearchBatchPoints", NO_DEFAULT_BUILDER_DERIVE_OPTIONS, true), ] } diff --git a/tests/protos_append/builder_ext.rs b/tests/protos_append/builder_ext.rs index 4ee3ccb..68e7e86 100644 --- a/tests/protos_append/builder_ext.rs +++ b/tests/protos_append/builder_ext.rs @@ -78,3 +78,41 @@ impl UpdateBatchPointsBuilder { builder } } + +impl DeletePayloadPointsBuilder { + pub fn new(collection_name: impl Into, keys: impl Into>) -> Self { + let mut builder = Self::create_empty(); + builder.collection_name = Some(collection_name.into()); + builder.keys = Some(keys.into()); + builder + } +} + +impl ClearPayloadPointsBuilder { + pub fn new(collection_name: impl Into) -> Self { + let mut builder = Self::create_empty(); + builder.collection_name = Some(collection_name.into()); + builder + } +} + +impl GetPointsBuilder { + pub fn new(collection_name: impl Into, ids: impl Into>) -> Self { + let mut builder = Self::create_empty(); + builder.collection_name = Some(collection_name.into()); + builder.ids = Some(ids.into()); + builder + } +} + +impl SearchBatchPointsBuilder { + pub fn new( + collection_name: impl Into, + search_points: impl Into>, + ) -> Self { + let mut builder = Self::create_empty(); + builder.collection_name = Some(collection_name.into()); + builder.search_points = Some(search_points.into()); + builder + } +}