pub struct Qdrant {
pub config: QdrantConfig,
/* private fields */
}
Expand description
API client to interact with a Qdrant server.
Connects to a Qdrant server and provides an API interface.
§Set up
Set up a Qdrant
client to connect to a Qdrant instance with just an URL:
use qdrant_client::Qdrant;
let client = Qdrant::from_url("http://localhost:6334").build()?;
Or use an URL, API key and timeout:
use qdrant_client::Qdrant;
let client = Qdrant::from_url("http://localhost:6334")
.api_key(std::env::var("QDRANT_API_KEY"))
.timeout(std::time::Duration::from_secs(10))
.build()?;
§Operations
Categories:
- Collection operations - manage collections, aliases and cluster configuration
- Point operations - manage points and vectors
- Payload operations - manage point payloads
- Search operations - search and explore points
- Query operations - query points using universal search
- Index operations - manage field and payload indices
- Snapshot operations - manage instance or collection snapshots
- Shard key operations - manage shard keys
Common operations include:
create_collection
- create a new collectionupsert_points
- insert or update pointssearch_points
- search points with similarity search
Fields§
§config: QdrantConfig
Client configuration
Implementations§
source§impl Qdrant
impl Qdrant
§Collection operations
Create, update and delete collections, manage collection aliases and collection cluster configuration.
Documentation: https://qdrant.tech/documentation/concepts/collections/
sourcepub async fn create_collection(
&self,
request: impl Into<CreateCollection>,
) -> Result<CollectionOperationResponse, QdrantError>
pub async fn create_collection( &self, request: impl Into<CreateCollection>, ) -> Result<CollectionOperationResponse, QdrantError>
Create a new collection.
use qdrant_client::qdrant::{CreateCollectionBuilder, Distance, VectorParamsBuilder};
client
.create_collection(
CreateCollectionBuilder::new("my_collection")
.vectors_config(VectorParamsBuilder::new(100, Distance::Cosine)),
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/collections/#create-a-collection
sourcepub async fn collection_info(
&self,
request: impl Into<GetCollectionInfoRequest>,
) -> Result<GetCollectionInfoResponse, QdrantError>
pub async fn collection_info( &self, request: impl Into<GetCollectionInfoRequest>, ) -> Result<GetCollectionInfoResponse, QdrantError>
Get collection info.
client.collection_info("my_collection").await?;
Documentation: https://qdrant.tech/documentation/concepts/collections/#collection-info
sourcepub async fn list_collections(
&self,
) -> Result<ListCollectionsResponse, QdrantError>
pub async fn list_collections( &self, ) -> Result<ListCollectionsResponse, QdrantError>
List all collections.
client.list_collections().await?;
This only lists collection names. To list collection name aliases, use
list_aliases
.
Documentation: https://qdrant.tech/documentation/concepts/collections/#list-all-collections
sourcepub async fn collection_exists(
&self,
request: impl Into<CollectionExistsRequest>,
) -> Result<bool, QdrantError>
pub async fn collection_exists( &self, request: impl Into<CollectionExistsRequest>, ) -> Result<bool, QdrantError>
Check whether a collection exists.
client.collection_exists("my_collection").await?;
Documentation: https://qdrant.tech/documentation/concepts/collections/#check-collection-existence
sourcepub async fn update_collection(
&self,
request: impl Into<UpdateCollection>,
) -> Result<CollectionOperationResponse, QdrantError>
pub async fn update_collection( &self, request: impl Into<UpdateCollection>, ) -> Result<CollectionOperationResponse, QdrantError>
Update collection.
Change parameters of a collection, such as the indexing threshold, for a collection that has already been created.
use qdrant_client::qdrant::{OptimizersConfigDiffBuilder, UpdateCollectionBuilder};
client
.update_collection(
UpdateCollectionBuilder::new("my_collection").optimizers_config(
OptimizersConfigDiffBuilder::default().indexing_threshold(10_000),
),
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/collections/#update-collection-parameters
sourcepub async fn delete_collection(
&self,
request: impl Into<DeleteCollection>,
) -> Result<CollectionOperationResponse, QdrantError>
pub async fn delete_collection( &self, request: impl Into<DeleteCollection>, ) -> Result<CollectionOperationResponse, QdrantError>
Delete an existing collection.
client.delete_collection("my_collection").await?;
Documentation: https://qdrant.tech/documentation/concepts/collections/#delete-collection
sourcepub async fn create_alias(
&self,
request: impl Into<CreateAlias>,
) -> Result<CollectionOperationResponse, QdrantError>
pub async fn create_alias( &self, request: impl Into<CreateAlias>, ) -> Result<CollectionOperationResponse, QdrantError>
Create new collection name alias.
use qdrant_client::qdrant::CreateAliasBuilder;
client
.create_alias(CreateAliasBuilder::new("my_collection", "my_alias"))
.await?;
Documentation: https://qdrant.tech/documentation/concepts/collections/#create-alias
sourcepub async fn list_aliases(&self) -> Result<ListAliasesResponse, QdrantError>
pub async fn list_aliases(&self) -> Result<ListAliasesResponse, QdrantError>
List collection name aliases for all collections.
client.list_aliases().await?;
This only lists collection name aliases. To list collection names, use
list_collections
.
Documentation: https://qdrant.tech/documentation/concepts/collections/#list-all-aliases
sourcepub async fn list_collection_aliases(
&self,
request: impl Into<ListCollectionAliasesRequest>,
) -> Result<ListAliasesResponse, QdrantError>
pub async fn list_collection_aliases( &self, request: impl Into<ListCollectionAliasesRequest>, ) -> Result<ListAliasesResponse, QdrantError>
List collection name aliases for a specific collection.
client.list_collection_aliases("my_collection").await?;
Documentation: https://qdrant.tech/documentation/concepts/collections/#list-collection-aliases
sourcepub async fn rename_alias(
&self,
request: impl Into<RenameAlias>,
) -> Result<CollectionOperationResponse, QdrantError>
pub async fn rename_alias( &self, request: impl Into<RenameAlias>, ) -> Result<CollectionOperationResponse, QdrantError>
Rename existing collection name alias.
use qdrant_client::qdrant::RenameAliasBuilder;
client
.rename_alias(RenameAliasBuilder::new("old_alias", "new_alias"))
.await?;
sourcepub async fn delete_alias(
&self,
request: impl Into<DeleteAlias>,
) -> Result<CollectionOperationResponse, QdrantError>
pub async fn delete_alias( &self, request: impl Into<DeleteAlias>, ) -> Result<CollectionOperationResponse, QdrantError>
Delete existing collection name alias.
use qdrant_client::qdrant::CreateAliasBuilder;
client
.delete_alias("my_alias")
.await?;
Documentation: https://qdrant.tech/documentation/concepts/collections/#remove-alias
sourcepub async fn collection_cluster_info(
&self,
request: impl Into<CollectionClusterInfoRequest>,
) -> Result<CollectionClusterInfoResponse, QdrantError>
pub async fn collection_cluster_info( &self, request: impl Into<CollectionClusterInfoRequest>, ) -> Result<CollectionClusterInfoResponse, QdrantError>
List cluster info of a collection.
client.collection_cluster_info("my_collection").await?;
Documentation: https://qdrant.tech/documentation/concepts/collections/#collection-info
sourcepub async fn update_collection_cluster_setup(
&self,
request: impl Into<UpdateCollectionClusterSetupRequest>,
) -> Result<UpdateCollectionClusterSetupResponse, QdrantError>
pub async fn update_collection_cluster_setup( &self, request: impl Into<UpdateCollectionClusterSetupRequest>, ) -> Result<UpdateCollectionClusterSetupResponse, QdrantError>
Update collection cluster setup.
Perform a collection cluster
Operation
, such as
MoveShard
, ReplicateShard
or CreateShardKey
.
use qdrant_client::qdrant::{MoveShardBuilder, UpdateCollectionClusterSetupRequestBuilder};
client
.update_collection_cluster_setup(UpdateCollectionClusterSetupRequestBuilder::new(
"my_collection",
MoveShardBuilder::new(
0, // Shard ID
0, // From peer ID
1, // To peer ID
),
))
.await?;
Documentation: https://qdrant.tech/documentation/concepts/collections/#create-a-collection
source§impl Qdrant
impl Qdrant
§Index operations
Manage field and payload indices in collections.
Documentation: https://qdrant.tech/documentation/concepts/indexing/
sourcepub async fn create_field_index(
&self,
request: impl Into<CreateFieldIndexCollection>,
) -> Result<PointsOperationResponse, QdrantError>
pub async fn create_field_index( &self, request: impl Into<CreateFieldIndexCollection>, ) -> Result<PointsOperationResponse, QdrantError>
Create payload index in a collection.
use qdrant_client::qdrant::{CreateFieldIndexCollectionBuilder, FieldType};
client
.create_field_index(
CreateFieldIndexCollectionBuilder::new(
"my_collection",
"city",
FieldType::Keyword,
),
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/indexing/#payload-index
sourcepub async fn delete_field_index(
&self,
request: impl Into<DeleteFieldIndexCollection>,
) -> Result<PointsOperationResponse, QdrantError>
pub async fn delete_field_index( &self, request: impl Into<DeleteFieldIndexCollection>, ) -> Result<PointsOperationResponse, QdrantError>
Delete payload index from a collection.
use qdrant_client::qdrant::DeleteFieldIndexCollectionBuilder;
client
.delete_field_index(DeleteFieldIndexCollectionBuilder::new(
"my_collection",
"city",
))
.await?;
Documentation: https://qdrant.tech/documentation/concepts/indexing/#payload-index
source§impl Qdrant
impl Qdrant
§Payload operations
Manage point payloads.
Documentation: https://qdrant.tech/documentation/concepts/payload/
sourcepub async fn set_payload(
&self,
request: impl Into<SetPayloadPoints>,
) -> Result<PointsOperationResponse, QdrantError>
pub async fn set_payload( &self, request: impl Into<SetPayloadPoints>, ) -> Result<PointsOperationResponse, QdrantError>
Set payload of points.
Sets only the given payload values on a point, leaving other existing payloads in place.
use qdrant_client::Payload;
use qdrant_client::qdrant::{PointsIdsList, SetPayloadPointsBuilder};
use serde_json::json;
let payload: Payload = json!({
"property1": "string",
"property2": "string",
})
.try_into()
.unwrap();
client
.set_payload(
SetPayloadPointsBuilder::new("my_collection", payload)
.points_selector(PointsIdsList {
ids: vec![0.into(), 3.into(), 10.into()],
})
.wait(true),
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/payload/#set-payload
sourcepub async fn overwrite_payload(
&self,
request: impl Into<SetPayloadPoints>,
) -> Result<PointsOperationResponse, QdrantError>
pub async fn overwrite_payload( &self, request: impl Into<SetPayloadPoints>, ) -> Result<PointsOperationResponse, QdrantError>
Overwrite payload of points.
Sets the given payload values on a point, completely replacing existing payload.
use qdrant_client::Payload;
use qdrant_client::qdrant::{
points_selector::PointsSelectorOneOf, PointsIdsList, SetPayloadPointsBuilder,
};
use serde_json::json;
let payload: Payload = json!({
"property1": "string",
"property2": "string",
})
.try_into()
.unwrap();
client
.overwrite_payload(
SetPayloadPointsBuilder::new("my_collection", payload)
.points_selector(PointsSelectorOneOf::Points(PointsIdsList {
ids: vec![0.into(), 3.into(), 10.into()],
}))
.wait(true),
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/payload/#overwrite-payload
sourcepub async fn delete_payload(
&self,
request: impl Into<DeletePayloadPoints>,
) -> Result<PointsOperationResponse, QdrantError>
pub async fn delete_payload( &self, request: impl Into<DeletePayloadPoints>, ) -> Result<PointsOperationResponse, QdrantError>
Delete specified payload keys of points.
use qdrant_client::qdrant::{DeletePayloadPointsBuilder, PointsIdsList};
client
.delete_payload(
DeletePayloadPointsBuilder::new(
"my_collection",
vec!["color".to_string(), "price".to_string()],
)
.points_selector(PointsIdsList {
ids: vec![0.into(), 3.into(), 100.into()],
})
.wait(true),
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/payload/#delete-payload-keys
sourcepub async fn clear_payload(
&self,
request: impl Into<ClearPayloadPoints>,
) -> Result<PointsOperationResponse, QdrantError>
pub async fn clear_payload( &self, request: impl Into<ClearPayloadPoints>, ) -> Result<PointsOperationResponse, QdrantError>
Clear all payload of points.
use qdrant_client::qdrant::{ClearPayloadPointsBuilder, PointsIdsList};
client
.clear_payload(ClearPayloadPointsBuilder::new("my_collection").points(
PointsIdsList {
ids: vec![0.into(), 3.into(), 100.into()],
},
))
.await?;
Documentation: https://qdrant.tech/documentation/concepts/payload/#clear-payload
source§impl Qdrant
impl Qdrant
§Point operations
Manage points and vectors.
Documentation: https://qdrant.tech/documentation/concepts/points/
sourcepub async fn upsert_points(
&self,
request: impl Into<UpsertPoints>,
) -> Result<PointsOperationResponse, QdrantError>
pub async fn upsert_points( &self, request: impl Into<UpsertPoints>, ) -> Result<PointsOperationResponse, QdrantError>
Insert or update points in a collection.
If points with the specified IDs already exist, they will be overwritten.
All points are upserted in a single operation. For a large number of points you likley want
split all upsertions into separate operations to avoid timing out. You can use
upsert_points_chunked
to automatically do that for you.
use qdrant_client::Payload;
use qdrant_client::qdrant::{PointStruct, UpsertPointsBuilder};
use serde_json::json;
client
.upsert_points(
UpsertPointsBuilder::new(
"my_collection",
vec![
PointStruct::new(
1,
vec![0.9, 0.1, 0.1],
Payload::try_from(json!(
{"color": "red"}
))
.unwrap(),
),
PointStruct::new(
2,
vec![0.1, 0.9, 0.1],
Payload::try_from(json!(
{"color": "green"}
))
.unwrap(),
),
PointStruct::new(
3,
vec![0.1, 0.1, 0.9],
Payload::try_from(json!(
{"color": "blue"}
))
.unwrap(),
),
],
)
.wait(true),
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/points/#upload-points
sourcepub async fn upsert_points_chunked(
&self,
request: impl Into<UpsertPoints>,
chunk_size: usize,
) -> Result<PointsOperationResponse, QdrantError>
pub async fn upsert_points_chunked( &self, request: impl Into<UpsertPoints>, chunk_size: usize, ) -> Result<PointsOperationResponse, QdrantError>
Insert or update points in a collection.
The same as upsert_points
, but it automatically splits all points
into chunks of chunk_size
to prevent timing out.
sourcepub async fn get_points(
&self,
request: impl Into<GetPoints>,
) -> Result<GetResponse, QdrantError>
pub async fn get_points( &self, request: impl Into<GetPoints>, ) -> Result<GetResponse, QdrantError>
Retrieve specific points from a collection.
Use with_vectors
and
with_payload
to specify whether to
include or exclude vector and payload data in the response. By default they are excluded to
save bandwidth.
use qdrant_client::qdrant::GetPointsBuilder;
client
.get_points(
GetPointsBuilder::new(
"my_collection",
vec![0.into(), 30.into(), 100.into()],
)
.with_vectors(true)
.with_payload(true)
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/points/#retrieve-points
sourcepub async fn scroll(
&self,
request: impl Into<ScrollPoints>,
) -> Result<ScrollResponse, QdrantError>
pub async fn scroll( &self, request: impl Into<ScrollPoints>, ) -> Result<ScrollResponse, QdrantError>
Scroll points in a collection.
Use with_vectors
and
with_payload
to specify whether to
include or exclude vector and payload data in the response. By default they are excluded to
save bandwidth.
use qdrant_client::qdrant::{Condition, Filter, ScrollPointsBuilder};
client
.scroll(
ScrollPointsBuilder::new("my_collection")
.filter(Filter::must([Condition::matches(
"color",
"red".to_string(),
)]))
.limit(1)
.with_payload(true)
.with_vectors(true),
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/points/#scroll-points
sourcepub async fn count(
&self,
request: impl Into<CountPoints>,
) -> Result<CountResponse, QdrantError>
pub async fn count( &self, request: impl Into<CountPoints>, ) -> Result<CountResponse, QdrantError>
Count points in a collection.
Use exact
to specify whether to use exact
counting. Exact counting is more accurate but slower.
use qdrant_client::qdrant::{Condition, CountPointsBuilder, Filter};
client
.count(
CountPointsBuilder::new("collection_name")
.filter(Filter::must([Condition::matches(
"color",
"red".to_string(),
)]))
.exact(true),
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/points/#counting-points
sourcepub async fn update_points_batch(
&self,
request: impl Into<UpdateBatchPoints>,
) -> Result<UpdateBatchResponse, QdrantError>
pub async fn update_points_batch( &self, request: impl Into<UpdateBatchPoints>, ) -> Result<UpdateBatchResponse, QdrantError>
Batch point operations in a collection.
Perform a batch of point Operation
s in a single request.
use qdrant_client::Payload;
use qdrant_client::qdrant::{
points_selector::PointsSelectorOneOf,
points_update_operation::{
Operation, OverwritePayload, PointStructList, UpdateVectors,
},
PointStruct, PointVectors, PointsIdsList, PointsSelector, PointsUpdateOperation,
UpdateBatchPointsBuilder,
};
use serde_json::json;
client
.update_points_batch(
UpdateBatchPointsBuilder::new(
"my_collection",
vec![
PointsUpdateOperation {
operation: Some(Operation::Upsert(PointStructList {
points: vec![PointStruct::new(
1,
vec![1.0, 2.0, 3.0, 4.0],
Payload::try_from(json!({})).unwrap(),
)],
..Default::default()
})),
},
PointsUpdateOperation {
operation: Some(Operation::UpdateVectors(UpdateVectors {
points: vec![PointVectors {
id: Some(1.into()),
vectors: Some(vec![1.0, 2.0, 3.0, 4.0].into()),
}],
..Default::default()
})),
},
PointsUpdateOperation {
operation: Some(Operation::OverwritePayload(OverwritePayload {
points_selector: Some(PointsSelector {
points_selector_one_of: Some(PointsSelectorOneOf::Points(
PointsIdsList {
ids: vec![1.into()],
},
)),
}),
payload: HashMap::from([("test_payload".to_string(), 1.into())]),
..Default::default()
})),
},
],
)
.wait(true),
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/points/#batch-update
sourcepub async fn delete_points(
&self,
request: impl Into<DeletePoints>,
) -> Result<PointsOperationResponse, QdrantError>
pub async fn delete_points( &self, request: impl Into<DeletePoints>, ) -> Result<PointsOperationResponse, QdrantError>
Delete points from a collection.
Delete by point ID:
use qdrant_client::qdrant::{DeletePointsBuilder, PointsIdsList};
client
.delete_points(
DeletePointsBuilder::new("my_collection")
.points(PointsIdsList {
ids: vec![0.into(), 3.into(), 100.into()],
})
.wait(true),
)
.await?;
Or delete by Filter
:
use qdrant_client::qdrant::{Condition, DeletePointsBuilder, Filter};
client
.delete_points(
DeletePointsBuilder::new("my_collection")
.points(Filter::must([Condition::matches(
"color",
"red".to_string(),
)]))
.wait(true),
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/points/#delete-points
sourcepub async fn update_vectors(
&self,
request: impl Into<UpdatePointVectors>,
) -> Result<PointsOperationResponse, QdrantError>
pub async fn update_vectors( &self, request: impl Into<UpdatePointVectors>, ) -> Result<PointsOperationResponse, QdrantError>
Update vectors on points.
Updates the given vectors on points in a collection, leaving existing vectors on these points with a different name in place.
use qdrant_client::qdrant::{PointVectors, UpdatePointVectorsBuilder};
client
.update_vectors(
UpdatePointVectorsBuilder::new(
"my_collection",
vec![
PointVectors {
id: Some(1.into()),
vectors: Some(
HashMap::from([("image".to_string(), vec![0.1, 0.2, 0.3, 0.4])])
.into(),
),
},
PointVectors {
id: Some(2.into()),
vectors: Some(
HashMap::from([(
"text".to_string(),
vec![0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2],
)])
.into(),
),
},
],
)
.wait(true),
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/points/#update-vectors
sourcepub async fn delete_vectors(
&self,
request: impl Into<DeletePointVectors>,
) -> Result<PointsOperationResponse, QdrantError>
pub async fn delete_vectors( &self, request: impl Into<DeletePointVectors>, ) -> Result<PointsOperationResponse, QdrantError>
Delete vectors from points.
Removes specified vectors from points in a collection, leaving existing vectors on these points with a different name in place.
use qdrant_client::qdrant::{DeletePointVectorsBuilder, PointsIdsList, VectorsSelector};
client
.delete_vectors(
DeletePointVectorsBuilder::new("my_collection")
.points_selector(PointsIdsList {
ids: vec![0.into(), 3.into(), 10.into()],
})
.vectors(VectorsSelector {
names: vec!["text".into(), "image".into()],
})
.wait(true),
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/points/#delete-vectors
sourcepub async fn facet(
&self,
request: impl Into<FacetCounts>,
) -> Result<FacetResponse, QdrantError>
pub async fn facet( &self, request: impl Into<FacetCounts>, ) -> Result<FacetResponse, QdrantError>
Get the amount of records for each unique value of a field.
use qdrant_client::qdrant::{Condition, FacetCountsBuilder, Filter};
let ten_countries_with_most_points_in_europe = client
.facet(
FacetCountsBuilder::new("world_data", "country")
.limit(10)
.filter(Filter::must(vec![Condition::matches(
"continent",
"Europe".to_string(),
)])),
)
.await
.unwrap();
sourcepub async fn search_matrix_pairs(
&self,
request: impl Into<SearchMatrixPoints>,
) -> Result<SearchMatrixPairsResponse, QdrantError>
pub async fn search_matrix_pairs( &self, request: impl Into<SearchMatrixPoints>, ) -> Result<SearchMatrixPairsResponse, QdrantError>
Get a (sparse) matrix of points with closest distance, returned as pairs.
use qdrant_client::qdrant::{Condition, SearchMatrixPointsBuilder, Filter};
let matrix = client
.search_matrix_pairs(
SearchMatrixPointsBuilder::new("collection_name")
.filter(Filter::must(vec![Condition::matches(
"color",
"red".to_string(),
)]))
.sample(1000)
.limit(10),
)
.await?;
sourcepub async fn search_matrix_offsets(
&self,
request: impl Into<SearchMatrixPoints>,
) -> Result<SearchMatrixOffsetsResponse, QdrantError>
pub async fn search_matrix_offsets( &self, request: impl Into<SearchMatrixPoints>, ) -> Result<SearchMatrixOffsetsResponse, QdrantError>
Get a (sparse) matrix of points with closest distance.
use qdrant_client::qdrant::{Condition, SearchMatrixPointsBuilder, Filter};
let matrix = client
.search_matrix_offsets(
SearchMatrixPointsBuilder::new("collection_name")
.filter(Filter::must(vec![Condition::matches(
"color",
"red".to_string(),
)]))
.sample(1000)
.limit(10),
)
.await?;
source§impl Qdrant
impl Qdrant
§Query operations
Query points using the universal search API.
Documentation: https://qdrant.tech/documentation/concepts/search/#query-api
sourcepub async fn query(
&self,
request: impl Into<QueryPoints>,
) -> Result<QueryResponse, QdrantError>
pub async fn query( &self, request: impl Into<QueryPoints>, ) -> Result<QueryResponse, QdrantError>
Query points in a collection.
use qdrant_client::qdrant::{Condition, Filter, QueryPointsBuilder};
client
.query(
QueryPointsBuilder::new("my_collection")
.filter(Filter::must([Condition::matches(
"city",
"London".to_string(),
)]))
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/search/#query-api
sourcepub async fn query_batch(
&self,
request: impl Into<QueryBatchPoints>,
) -> Result<QueryBatchResponse, QdrantError>
pub async fn query_batch( &self, request: impl Into<QueryBatchPoints>, ) -> Result<QueryBatchResponse, QdrantError>
Batch multiple point queries in a collection.
use qdrant_client::qdrant::{Condition, Filter, QueryPointsBuilder, QueryBatchPointsBuilder};
client
.query_batch(
QueryBatchPointsBuilder::new("my_collection", vec![
QueryPointsBuilder::new("my_collection")
.filter(Filter::must([Condition::matches(
"city",
"London".to_string(),
)]))
.build(),
QueryPointsBuilder::new("my_collection")
.filter(Filter::must([Condition::matches(
"city",
"Berlin".to_string(),
)]))
.build(),
])
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/search/#query-api
sourcepub async fn query_groups(
&self,
request: impl Into<QueryPointGroups>,
) -> Result<QueryGroupsResponse, QdrantError>
pub async fn query_groups( &self, request: impl Into<QueryPointGroups>, ) -> Result<QueryGroupsResponse, QdrantError>
Query points in a collection and group results by a payload field.
use qdrant_client::qdrant::{PrefetchQueryBuilder, QueryPointGroupsBuilder};
client
.query_groups(
QueryPointGroupsBuilder::new(
"my_collection", // Collection name
"city", // Group by field
)
.add_prefetch(
PrefetchQueryBuilder::default()
.query(vec![0.01, 0.45, 0.67])
.limit(100u64)
)
.query(vec![0.1, 0.2, 0.3, 0.4]) // Query vector
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/search/#query-api
source§impl Qdrant
impl Qdrant
§Search operations
Search and explore points.
Documentation: https://qdrant.tech/documentation/concepts/search/
sourcepub async fn search_points(
&self,
request: impl Into<SearchPoints>,
) -> Result<SearchResponse, QdrantError>
pub async fn search_points( &self, request: impl Into<SearchPoints>, ) -> Result<SearchResponse, QdrantError>
Search points in a collection.
use qdrant_client::qdrant::{Condition, Filter, SearchParamsBuilder, SearchPointsBuilder};
client
.search_points(
SearchPointsBuilder::new("my_collection", vec![0.2, 0.1, 0.9, 0.7], 3)
.filter(Filter::must([Condition::matches(
"city",
"London".to_string(),
)]))
.params(SearchParamsBuilder::default().hnsw_ef(128).exact(false)),
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/search/#search-api
sourcepub async fn search_batch_points(
&self,
request: impl Into<SearchBatchPoints>,
) -> Result<SearchBatchResponse, QdrantError>
pub async fn search_batch_points( &self, request: impl Into<SearchBatchPoints>, ) -> Result<SearchBatchResponse, QdrantError>
Batch multiple points searches in a collection.
use qdrant_client::qdrant::{Condition, Filter, SearchBatchPointsBuilder, SearchPointsBuilder,};
let filter = Filter::must([Condition::matches("city", "London".to_string())]);
let searches = vec![
SearchPointsBuilder::new("my_collection", vec![0.2, 0.1, 0.9, 0.7], 3)
.filter(filter.clone())
.build(),
SearchPointsBuilder::new("my_collection", vec![0.5, 0.3, 0.2, 0.3], 3)
.filter(filter)
.build(),
];
client
.search_batch_points(SearchBatchPointsBuilder::new("my_collection", searches))
.await?;
Documentation: https://qdrant.tech/documentation/concepts/search/#batch-search-api
sourcepub async fn search_groups(
&self,
request: impl Into<SearchPointGroups>,
) -> Result<SearchGroupsResponse, QdrantError>
pub async fn search_groups( &self, request: impl Into<SearchPointGroups>, ) -> Result<SearchGroupsResponse, QdrantError>
Search points in a collection and group results by a payload field.
use qdrant_client::qdrant::SearchPointGroupsBuilder;
client
.search_groups(SearchPointGroupsBuilder::new(
"my_collection", // Collection name
vec![1.1], // Search vector
4, // Search limit
"document_id", // Group by field
2, // Group size
))
.await?;
Documentation: https://qdrant.tech/documentation/concepts/search/#search-groups
sourcepub async fn recommend(
&self,
request: impl Into<RecommendPoints>,
) -> Result<RecommendResponse, QdrantError>
pub async fn recommend( &self, request: impl Into<RecommendPoints>, ) -> Result<RecommendResponse, QdrantError>
Recommend points in a collection.
use qdrant_client::qdrant::{Condition, Filter, RecommendPointsBuilder, RecommendStrategy};
client
.recommend(
RecommendPointsBuilder::new("my_collection", 3)
.add_positive(100)
.add_positive(200)
.add_positive(vec![100.0, 231.0])
.add_negative(718)
.add_negative(vec![0.2, 0.3, 0.4, 0.5])
.strategy(RecommendStrategy::AverageVector)
.filter(Filter::must([Condition::matches(
"city",
"London".to_string(),
)])),
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/explore/#recommendation-api
sourcepub async fn recommend_batch(
&self,
request: impl Into<RecommendBatchPoints>,
) -> Result<RecommendBatchResponse, QdrantError>
pub async fn recommend_batch( &self, request: impl Into<RecommendBatchPoints>, ) -> Result<RecommendBatchResponse, QdrantError>
Batch multiple points recommendations in a collection.
use qdrant_client::qdrant::{Condition, Filter, RecommendBatchPointsBuilder, RecommendPointsBuilder};
let filter = Filter::must([Condition::matches("city", "London".to_string())]);
let recommend_queries = vec![
RecommendPointsBuilder::new("my_collection", 3)
.add_positive(100)
.add_positive(231)
.add_negative(718)
.filter(filter.clone())
.build(),
RecommendPointsBuilder::new("my_collection", 3)
.add_positive(200)
.add_positive(67)
.add_negative(300)
.filter(filter.clone())
.build(),
];
client
.recommend_batch(RecommendBatchPointsBuilder::new(
"my_collection",
recommend_queries,
))
.await?;
Documentation: https://qdrant.tech/documentation/concepts/explore/#batch-recommendation-api
sourcepub async fn recommend_groups(
&self,
request: impl Into<RecommendPointGroups>,
) -> Result<RecommendGroupsResponse, QdrantError>
pub async fn recommend_groups( &self, request: impl Into<RecommendPointGroups>, ) -> Result<RecommendGroupsResponse, QdrantError>
Recommend points in a collection and group results by a payload field.
use qdrant_client::qdrant::{RecommendPointGroupsBuilder, RecommendStrategy};
client
.recommend_groups(
RecommendPointGroupsBuilder::new(
"my_collection", // Collection name
"document_id", // Group by field
2, // Group size
3, // Search limit
)
.add_positive(100)
.add_positive(200)
.add_negative(718)
.strategy(RecommendStrategy::AverageVector),
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/explore/#recommendation-api
sourcepub async fn discover(
&self,
request: impl Into<DiscoverPoints>,
) -> Result<DiscoverResponse, QdrantError>
pub async fn discover( &self, request: impl Into<DiscoverPoints>, ) -> Result<DiscoverResponse, QdrantError>
Discover points in a collection.
use qdrant_client::qdrant::{
target_vector::Target, vector_example::Example, ContextExamplePairBuilder,
DiscoverPointsBuilder, VectorExample,
};
client
.discover(
DiscoverPointsBuilder::new(
"my_collection", // Collection name
vec![
ContextExamplePairBuilder::default()
.positive(Example::Id(100.into()))
.negative(Example::Id(718.into()))
.build(),
ContextExamplePairBuilder::default()
.positive(Example::Id(200.into()))
.negative(Example::Id(300.into()))
.build(),
],
10, // Search limit
)
.target(Target::Single(VectorExample {
example: Some(Example::Vector(vec![0.2, 0.1, 0.9, 0.7].into())),
})),
)
.await?;
Documentation: https://qdrant.tech/documentation/concepts/explore/#discovery-api
sourcepub async fn discover_batch(
&self,
request: &DiscoverBatchPoints,
) -> Result<DiscoverBatchResponse, QdrantError>
pub async fn discover_batch( &self, request: &DiscoverBatchPoints, ) -> Result<DiscoverBatchResponse, QdrantError>
Batch multiple point discoveries in a collection.
use qdrant_client::qdrant::{
vector_example::Example, ContextExamplePairBuilder, DiscoverBatchPointsBuilder,
DiscoverPointsBuilder,
};
let discover_points = DiscoverBatchPointsBuilder::new(
"my_collection",
vec![
DiscoverPointsBuilder::new(
"my_collection",
vec![
ContextExamplePairBuilder::default()
.positive(Example::Id(100.into()))
.negative(Example::Id(718.into()))
.build(),
ContextExamplePairBuilder::default()
.positive(Example::Id(200.into()))
.negative(Example::Id(300.into()))
.build(),
],
10,
)
.build(),
DiscoverPointsBuilder::new(
"my_collection",
vec![
ContextExamplePairBuilder::default()
.positive(Example::Id(342.into()))
.negative(Example::Id(213.into()))
.build(),
ContextExamplePairBuilder::default()
.positive(Example::Id(100.into()))
.negative(Example::Id(200.into()))
.build(),
],
10,
)
.build(),
],
);
client.discover_batch(&discover_points.build()).await?;
Documentation: https://qdrant.tech/documentation/concepts/explore/#discovery-api
source§impl Qdrant
impl Qdrant
§Sharding key operations
Create or delete shard keys for collections.
Documentation: https://qdrant.tech/documentation/guides/distributed_deployment/#user-defined-sharding
sourcepub async fn create_shard_key(
&self,
request: impl Into<CreateShardKeyRequest>,
) -> Result<CreateShardKeyResponse, QdrantError>
pub async fn create_shard_key( &self, request: impl Into<CreateShardKeyRequest>, ) -> Result<CreateShardKeyResponse, QdrantError>
Create new shard key in a collection.
use qdrant_client::qdrant::shard_key::Key;
use qdrant_client::qdrant::{CreateShardKeyBuilder, CreateShardKeyRequestBuilder};
client
.create_shard_key(
CreateShardKeyRequestBuilder::new("my_collection").request(
CreateShardKeyBuilder::default()
.shard_key(Key::Keyword("my_key".to_string())),
),
)
.await?;
Documentation: https://qdrant.tech/documentation/guides/distributed_deployment/#user-defined-sharding
sourcepub async fn delete_shard_key(
&self,
request: impl Into<DeleteShardKeyRequest>,
) -> Result<DeleteShardKeyResponse, QdrantError>
pub async fn delete_shard_key( &self, request: impl Into<DeleteShardKeyRequest>, ) -> Result<DeleteShardKeyResponse, QdrantError>
Delete existing shard key from a collection.
Deleting a shard key destroys all shards and data placed in it.
use qdrant_client::qdrant::shard_key::Key;
use qdrant_client::qdrant::DeleteShardKeyRequestBuilder;
client
.delete_shard_key(
DeleteShardKeyRequestBuilder::new("my_collection")
.key(Key::Keyword("my_key".to_string())),
)
.await?;
Documentation: https://qdrant.tech/documentation/guides/distributed_deployment/#user-defined-sharding
source§impl Qdrant
impl Qdrant
§Snapshot operations
Create, recover and manage snapshots for collections or a full Qdrant instance.
Documentation: https://qdrant.tech/documentation/concepts/snapshots/
sourcepub async fn create_snapshot(
&self,
request: impl Into<CreateSnapshotRequest>,
) -> Result<CreateSnapshotResponse, QdrantError>
pub async fn create_snapshot( &self, request: impl Into<CreateSnapshotRequest>, ) -> Result<CreateSnapshotResponse, QdrantError>
Create snapshot of a collection on this node.
client.create_snapshot("my_collection").await?;
Note: Snapshots are node-local. They only contain data of a single node. In distributed mode you must create a snapshot on each node separately. Each node has their own list of snapshots.
Documentation: https://qdrant.tech/documentation/concepts/snapshots/#create-snapshot
sourcepub async fn list_snapshots(
&self,
request: impl Into<ListSnapshotsRequest>,
) -> Result<ListSnapshotsResponse, QdrantError>
pub async fn list_snapshots( &self, request: impl Into<ListSnapshotsRequest>, ) -> Result<ListSnapshotsResponse, QdrantError>
List collection snapshots on this node.
client.list_snapshots("my_collection").await?;
Note: Snapshots are node-local. They only contain data of a single node. In distributed mode you must create a snapshot on each node separately. Each node has their own list of snapshots.
Documentation: https://qdrant.tech/documentation/concepts/snapshots/#list-snapshot
sourcepub async fn download_snapshot(
&self,
download: impl Into<SnapshotDownload>,
) -> Result<(), QdrantError>
pub async fn download_snapshot( &self, download: impl Into<SnapshotDownload>, ) -> Result<(), QdrantError>
Download a collection snapshot on this node.
use qdrant_client::qdrant::SnapshotDownloadBuilder;
client.download_snapshot(
SnapshotDownloadBuilder::new("./target_path.snapshot", "my_collection")
.snapshot_name("snapshot_name")
.rest_api_uri("http://localhost:6333")
).await?;
let snapshot_file = File::open("./target_path.snapshot")?;
Note: Snapshots are node-local. They only contain data of a single node. In distributed mode you must create a snapshot on each node separately. Each node has their own list of snapshots.
Documentation: https://qdrant.tech/documentation/concepts/snapshots/#retrieve-snapshot
sourcepub async fn delete_snapshot(
&self,
request: impl Into<DeleteSnapshotRequest>,
) -> Result<DeleteSnapshotResponse, QdrantError>
pub async fn delete_snapshot( &self, request: impl Into<DeleteSnapshotRequest>, ) -> Result<DeleteSnapshotResponse, QdrantError>
Delete a collection snapshot on this node.
use qdrant_client::qdrant::DeleteSnapshotRequestBuilder;
client
.delete_snapshot(DeleteSnapshotRequestBuilder::new(
"my_collection",
"snapshot_name",
))
.await?;
Note: Snapshots are node-local. They only contain data of a single node. In distributed mode you must create a snapshot on each node separately. Each node has their own list of snapshots.
Documentation: https://qdrant.tech/documentation/concepts/snapshots/#delete-snapshot
sourcepub async fn create_full_snapshot(
&self,
) -> Result<CreateSnapshotResponse, QdrantError>
pub async fn create_full_snapshot( &self, ) -> Result<CreateSnapshotResponse, QdrantError>
Create full snapshot of this entire node.
client.create_full_snapshot().await?;
Documentation: https://qdrant.tech/documentation/concepts/snapshots/#create-full-storage-snapshot
sourcepub async fn list_full_snapshots(
&self,
) -> Result<ListSnapshotsResponse, QdrantError>
pub async fn list_full_snapshots( &self, ) -> Result<ListSnapshotsResponse, QdrantError>
List full snapshots of this node.
client.list_full_snapshots().await?;
Documentation: https://qdrant.tech/documentation/concepts/snapshots/#list-full-storage-snapshots
sourcepub async fn delete_full_snapshot(
&self,
request: impl Into<DeleteFullSnapshotRequest>,
) -> Result<DeleteSnapshotResponse, QdrantError>
pub async fn delete_full_snapshot( &self, request: impl Into<DeleteFullSnapshotRequest>, ) -> Result<DeleteSnapshotResponse, QdrantError>
Delete full snapshots of this node.
client
.delete_full_snapshot("snapshot_name")
.await?;
Documentation: https://qdrant.tech/documentation/concepts/snapshots/#delete-full-storage-snapshot
source§impl Qdrant
impl Qdrant
§Construct and connect
Methods to construct a new Qdrant client.
sourcepub fn new(config: QdrantConfig) -> Result<Self, QdrantError>
pub fn new(config: QdrantConfig) -> Result<Self, QdrantError>
Create a new Qdrant client.
Constructs the client and connects based on the given QdrantConfig
.
sourcepub fn from_url(url: &str) -> QdrantBuilder
pub fn from_url(url: &str) -> QdrantBuilder
Build a new Qdrant client with the given URL.
use qdrant_client::Qdrant;
let client = Qdrant::from_url("http://localhost:6334").build()?;
See more ways to set up the client here.
sourcepub async fn health_check(&self) -> Result<HealthCheckReply, QdrantError>
pub async fn health_check(&self) -> Result<HealthCheckReply, QdrantError>
Health check.
Do a health check and fetch server information such as the current version and commit.
client.health_check().await?;
Auto Trait Implementations§
impl !Freeze for Qdrant
impl RefUnwindSafe for Qdrant
impl Send for Qdrant
impl Sync for Qdrant
impl Unpin for Qdrant
impl UnwindSafe for Qdrant
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request