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, // Unique point 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
§Query (search)
Finally, we can retrieve points in various ways, the common one being a plain similarity search:
use qdrant_client::qdrant::QueryPointsBuilder;
let query_request = QueryPointsBuilder::new("my_collection") // Collection name
.query(vec![0.0_f32; 512]) // Query vector
.limit(4) // Search limit, number of results to return
.with_payload(true); // Include full payload in the result
let response = client.query(query_request).await?;The parameter for QueryPointsBuilder::new() is pretty
straightforward: the name of the collection to query in. It is combined with other
functions to further specialize your query to
cover all query flavors.
In this example query(...) is used to enable vector
similarity search on the given vector. limit(4)
specifies we only want up to 4 top-k results. And
with_payload(true) tells Qdrant to also return
the (full) payload data for each point. filter() is
also commonly used to apply payload based filtering. See the Filter
documentation for details.
Documentation: https://qdrant.tech/documentation/concepts/search/#query-api
Modules§
- config
- Client configuration
- qdrant
- API types
- serde_
deser - Deserialize into any serde type
Structs§
Enums§
- Qdrant
Error - Qdrant client error
Type Aliases§
- Qdrant
Builder - A builder for
Qdrant