To use the client, you need to add qdrant-client along with anyhow, tonic, tokio, and serde-json. Ensure tokio is configured with the rt-multi-thread feature.
Required dependencies:
cargo add qdrant-client anyhow tonic tokio serde-json --features tokio/rt-multi-thread
Basic Workflow Example:
- Initialize the client using
Qdrant::from_url("...").build()?. - Create collections using
CreateCollectionBuilder. - Upsert points using
UpsertPointsBuilder and PointStruct. - Query points using
QueryPointsBuilder with filters and search parameters.
Note: You can also use the tonic-generated client from src/qdrant.rs directly.
use qdrant_client::qdrant::{
Condition, CreateCollectionBuilder, Distance, Filter, PointStruct, QueryPointsBuilder,
ScalarQuantizationBuilder, SearchParamsBuilder, UpsertPointsBuilder, VectorParamsBuilder,
};
use qdrant_client::{Payload, Qdrant, QdrantError};
#[tokio::main]
async fn main() -> Result<(), QdrantError> {
// Initialize client
let client = Qdrant::from_url("http://localhost:6334").build()?;
let collection_name = "test";
// Create a collection
client
.create_collection(
CreateCollectionBuilder::new(collection_name)
.vectors_config(VectorParamsBuilder::new(10, Distance::Cosine))
.quantization_config(ScalarQuantizationBuilder::default()),
)
.await?;
// Prepare payload and points
let payload: Payload = serde_json::json!(
{
"foo": "Bar",
"bar": 12,
"baz": {
"qux": "quux"
}
}
)
.try_into()
.unwrap();
let points = vec![PointStruct::new(0, vec![12.; 10], payload)];
// Upsert points
client
.upsert_points(UpsertPointsBuilder::new(collection_name, points))
.await?;
// Query points
let query_result = client
.query(
QueryPointsBuilder::new(collection_name)
.query(vec![11.0; 10])
.limit(10)
.filter(Filter::all([Condition::matches("bar", 12)]))
.with_payload(true)
.params(SearchParamsBuilder::default().exact(true)),
)
.await?;
Ok(())
}