rust-client
Rust client for Qdrant vector search engine.

Installation
cargo add qdrant-client
Package is available in crates.io
Dependencies
The client uses gRPC via the Tonic library.
In order to build tonic >= 0.8.0, you need the protoc Protocol Buffers compiler, along with Protocol Buffers resource files.
Refer to the Tonic installation guide for more details.
Usage
Run Qdrant with enabled gRPC interface:
docker run -p 6333:6333 -p 6334:6334 \
-e QDRANT__SERVICE__GRPC_PORT="6334" \
qdrant/qdrant
Or by updating the configuration file:
service:
grpc_port: 6334
More info about gRPC in documentation.
Making requests
Add necessary dependencies:
cargo add qdrant-client anyhow tonic tokio --features tokio/rt-multi-thread
Add search example from examples/search.rs to your src/main.rs:
use anyhow::Result;
use qdrant_client::prelude::*;
use qdrant_client::qdrant::vectors_config::Config;
use qdrant_client::qdrant::{CreateCollection, SearchPoints, VectorParams, VectorsConfig};
use std::collections::HashMap;
#[tokio::main]
async fn main() -> Result<()> {
let config = QdrantClientConfig::from_url("http://localhost:6334");
let client = QdrantClient::new(Some(config)).await?;
let collections_list = client.list_collections().await?;
dbg!(collections_list);
let collection_name = "test";
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()
})
.await?;
let collection_info = client.collection_info(collection_name).await?;
dbg!(collection_info);
let payload: Payload = vec![("foo", "Bar".into()), ("bar", 12.into())]
.into_iter()
.collect::<HashMap<_, Value>>()
.into();
let points = vec![PointStruct::new(0, vec![12.; 10], payload)];
client
.upsert_points_blocking(collection_name, points, None)
.await?;
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()
})
.await?;
dbg!(search_result);
Ok(())
}
Or run the example from this project directly:
cargo run --example search