Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Blocking API #43

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
reqwest = { version = "0.11.17", optional = true, features = ["stream"] }
futures-util = { version = "0.3.28", optional = true }
tokio = "1.28.0"

[dev-dependencies]
tonic-build = { version = "0.9.2", features = ["prost"] }
Expand Down
90 changes: 90 additions & 0 deletions examples/search_sync.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use anyhow::Result;
use qdrant_client::prelude::*;
use qdrant_client::qdrant::vectors_config::Config;
use qdrant_client::qdrant::{CreateCollection, SearchPoints, VectorParams, VectorsConfig};
use serde_json::json;

fn main() -> Result<()> {
// Example of top level client
// You may also use tonic-generated client from `src/qdrant.rs`
let config = QdrantClientConfig::from_url("http://localhost:6334");
let client = QdrantClientSync::new(Some(config))?;

let collections_list = client.list_collections()?;
dbg!(collections_list);
// collections_list = ListCollectionsResponse {
// collections: [
// CollectionDescription {
// name: "test",
// },
// ],
// time: 1.78e-6,
// }

let collection_name = "test";
client.delete_collection(collection_name)?;

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

let collection_info = client.collection_info(collection_name)?;
dbg!(collection_info);

let payload: Payload = json!(
{
"foo": "Bar",
"bar": 12,
}
)
.try_into()
.unwrap();

let points = vec![PointStruct::new(0, vec![12.; 10], payload)];
client.upsert_points_blocking(collection_name, points, None)?;

let search_result = client.search_points(&SearchPoints {
collection_name: collection_name.into(),
vector: vec![11.; 10],
filter: None,
limit: 10,
with_vectors: None,
with_payload: None,
params: None,
score_threshold: None,
offset: None,
..Default::default()
})?;
dbg!(search_result);
// search_result = SearchResponse {
// result: [
// ScoredPoint {
// id: Some(
// PointId {
// point_id_options: Some(
// Num(
// 0,
// ),
// ),
// },
// ),
// payload: {},
// score: 1.0000001,
// version: 0,
// vectors: None,
// },
// ],
// time: 5.312e-5,
// }

Ok(())
}
Loading