Skip to content

Commit

Permalink
add collection_exists
Browse files Browse the repository at this point in the history
  • Loading branch information
agourlay committed Mar 1, 2024
1 parent c3c83ab commit 3a4911c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ use crate::qdrant::with_payload_selector::SelectorOptions;
use crate::qdrant::{
qdrant_client, shard_key, with_vectors_selector, AliasOperations, ChangeAliases,
ClearPayloadPoints, CollectionClusterInfoRequest, CollectionClusterInfoResponse,
CollectionOperationResponse, CollectionParamsDiff, CountPoints, CountResponse, CreateAlias,
CreateCollection, CreateFieldIndexCollection, CreateFullSnapshotRequest, CreateShardKey,
CreateShardKeyRequest, CreateShardKeyResponse, CreateSnapshotRequest, CreateSnapshotResponse,
DeleteAlias, DeleteCollection, DeleteFieldIndexCollection, DeleteFullSnapshotRequest,
DeletePayloadPoints, DeletePointVectors, DeletePoints, DeleteShardKey, DeleteShardKeyRequest,
DeleteShardKeyResponse, DeleteSnapshotRequest, DeleteSnapshotResponse, DiscoverBatchPoints,
DiscoverBatchResponse, DiscoverPoints, DiscoverResponse, FieldType, GetCollectionInfoRequest,
CollectionExistsRequest, CollectionOperationResponse, CollectionParamsDiff, CountPoints,
CountResponse, CreateAlias, CreateCollection, CreateFieldIndexCollection,
CreateFullSnapshotRequest, CreateShardKey, CreateShardKeyRequest, CreateShardKeyResponse,
CreateSnapshotRequest, CreateSnapshotResponse, DeleteAlias, DeleteCollection,
DeleteFieldIndexCollection, DeleteFullSnapshotRequest, DeletePayloadPoints, DeletePointVectors,
DeletePoints, DeleteShardKey, DeleteShardKeyRequest, DeleteShardKeyResponse,
DeleteSnapshotRequest, DeleteSnapshotResponse, DiscoverBatchPoints, DiscoverBatchResponse,
DiscoverPoints, DiscoverResponse, FieldType, GetCollectionInfoRequest,
GetCollectionInfoResponse, GetPoints, GetResponse, HealthCheckReply, HealthCheckRequest,
HnswConfigDiff, ListAliasesRequest, ListAliasesResponse, ListCollectionAliasesRequest,
ListCollectionsRequest, ListCollectionsResponse, ListFullSnapshotsRequest,
Expand Down Expand Up @@ -484,6 +485,7 @@ impl QdrantClient {
.await?)
}

#[deprecated(since = "1.8.0", note = "Please use the `collection_exists` instead")]
pub async fn has_collection(&self, collection_name: impl ToString) -> Result<bool> {
let collection_name = collection_name.to_string();
let response = self.list_collections().await?;
Expand All @@ -495,6 +497,23 @@ impl QdrantClient {
Ok(result)
}

pub async fn collection_exists(&self, collection_name: impl ToString) -> Result<bool> {
let collection_name_ref = &collection_name.to_string();
Ok(self
.with_collections_client(|mut collection_api| async move {
let request = CollectionExistsRequest {
collection_name: collection_name_ref.clone(),
};
let result = collection_api.collection_exists(request).await?;
Ok(result
.into_inner()
.result
.map(|r| r.exists)
.unwrap_or(false))
})
.await?)
}

pub async fn create_collection(
&self,
details: &CreateCollection,
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,9 @@ mod tests {
})
.await?;

let exists = client.collection_exists(collection_name).await?;
assert!(exists);

let collection_info = client.collection_info(collection_name).await?;
println!("{:#?}", collection_info);

Expand Down

0 comments on commit 3a4911c

Please sign in to comment.