Expand description
The Qdrant - High-Performance Vector Search at Scale - client for Rust.
This crate connects to your Qdrant server over gRPC and provides an easy to use API interface for it.
§Connect
First you’ll need to set up a Qdrant
client, used to connect to a Qdrant
instance:
use qdrant_client::Qdrant;
let client = Qdrant::from_url("http://localhost:6334")
.api_key(std::env::var("QDRANT_API_KEY"))
.build()?;
§Create collection
Qdrant works with Collections ⧉ of Points ⧉ . To add vector data, you first create a collection:
use qdrant_client::qdrant::{CreateCollectionBuilder, Distance, VectorParamsBuilder};
let response = client
.create_collection(
CreateCollectionBuilder::new("my_collection")
.vectors_config(VectorParamsBuilder::new(512, Distance::Cosine)),
)
.await?;
The most interesting parts are the two arguments of
VectorParamsBuilder::new
. The first one (512
) is the
length of vectors to store and the second one (Distance::Cosine
)
is the Distance, which is the Distance
measure to gauge similarity for
the nearest neighbors search.
Documentation: https://qdrant.tech/documentation/concepts/collections/#create-a-collection
§Upsert points
Now we have a collection, we can insert (or rather upsert) points. Points have an id, one or more vectors and a payload. We can usually do that in bulk, but for this example, we’ll add a single point:
use qdrant_client::qdrant::{PointStruct, UpsertPointsBuilder};
let points = vec![
PointStruct::new(
42, // Uniqe piont ID
vec![0.0_f32; 512], // Vector to upsert
// Attached payload
[
("great", true.into()),
("level", 9000.into()),
("text", "Hi Qdrant!".into()),
("list", vec![1.234f32, 0.815].into()),
],
),
];
let response = client
.upsert_points(UpsertPointsBuilder::new("my_collection", points))
.await?;
Documentation: https://qdrant.tech/documentation/concepts/points/#upload-points
§Search
Finally, we can retrieve points in various ways, the common one being a plain similarity search:
use qdrant_client::qdrant::SearchPointsBuilder;
let search_request = SearchPointsBuilder::new(
"my_collection", // Collection name
vec![0.0_f32; 512], // Cearch vector
4, // Search limit, number of results to return
).with_payload(true);
let response = client.search_points(search_request).await?;
The parameter for SearchPointsBuilder::new()
contsructor
are pretty straightforward: name of the collection, the vector and how many top-k results to
return. The with_payload(true)
call tells qdrant
to also return the (full) payload data for each point. You can also add a
filter()
call to the
SearchPointsBuilder
to filter the result. See the
Filter
documentation for details.
Documentation: https://qdrant.tech/documentation/concepts/search/
Modules§
- Client configuration
- API types
Structs§
- Point payload
- API client to interact with a Qdrant server.
Enums§
- Qdrant client error
Type Aliases§
- A builder for
Qdrant