Skip to content

Commit

Permalink
[Proposal] Builder generation for CreateCollection and VectorParams (#…
Browse files Browse the repository at this point in the history
…108)

* Builder generation for CreateCollection and VectorParams
  • Loading branch information
JojiiOfficial authored May 2, 2024
1 parent d97922b commit 47573e7
Show file tree
Hide file tree
Showing 6 changed files with 440 additions and 68 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ serde = { version = "1", features = ["derive"], optional = true }
serde_json = { version = "1", optional = true }
reqwest = { version = "0.12.3", optional = true, default-features = false, features = ["stream", "rustls-tls", "http2"] }
futures-util = { version = "0.3.30", optional = true }
derive_builder = { version = "0.20" }

[dev-dependencies]
tonic-build = { version = "0.11.0", features = ["prost"] }
Expand Down
25 changes: 12 additions & 13 deletions examples/search.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::Result;
use qdrant_client::prelude::*;
use qdrant_client::qdrant::vectors_config::Config;
use qdrant_client::qdrant::Distance;
use qdrant_client::qdrant::{
Condition, CreateCollection, Filter, SearchPoints, VectorParams, VectorsConfig,
Condition, CreateCollectionBuilder, Filter, SearchPoints, VectorParamsBuilder,
};
use serde_json::json;

Expand All @@ -28,17 +28,16 @@ async fn main() -> Result<()> {
client.delete_collection(collection_name).await?;

client
.create_collection(&CreateCollection {
collection_name: collection_name.into(),
vectors_config: Some(VectorsConfig {
config: Some(Config::Params(VectorParams {
size: 10,
distance: Distance::Cosine.into(),
..Default::default()
})),
}),
..Default::default()
})
.create_collection(
&CreateCollectionBuilder::default()
.collection_name(collection_name)
.vectors_config(
VectorParamsBuilder::default()
.distance(Distance::Cosine)
.size(10),
)
.build(),
)
.await?;

let collection_info = client.collection_info(collection_name).await?;
Expand Down
12 changes: 9 additions & 3 deletions src/grpc_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use crate::qdrant::{
ProductQuantization, QuantizationConfig, QuantizationConfigDiff, ReadConsistency, RenameAlias,
RepeatedIntegers, RepeatedStrings, ScalarQuantization, ShardKey, ShardKeySelector,
SparseIndexConfig, SparseIndices, SparseVectorConfig, SparseVectorParams, StartFrom, Struct,
TargetVector, TextIndexParams, Value, Vector, VectorExample, VectorParams, VectorParamsDiff,
VectorParamsDiffMap, VectorParamsMap, Vectors, VectorsConfig, VectorsConfigDiff,
VectorsSelector, WithPayloadSelector, WithVectorsSelector,
TargetVector, TextIndexParams, Value, Vector, VectorExample, VectorParams, VectorParamsBuilder,
VectorParamsDiff, VectorParamsDiffMap, VectorParamsMap, Vectors, VectorsConfig,
VectorsConfigDiff, VectorsSelector, WithPayloadSelector, WithVectorsSelector,
};
use std::collections::HashMap;

Expand Down Expand Up @@ -771,3 +771,9 @@ impl From<Vec<PointId>> for PointsIdsList {
Self { ids: value }
}
}

impl From<&mut VectorParamsBuilder> for vectors_config::Config {
fn from(value: &mut VectorParamsBuilder) -> Self {
value.build().into()
}
}
Loading

0 comments on commit 47573e7

Please sign in to comment.