Skip to content

Commit

Permalink
feat: add collection_exists and delete_collection
Browse files Browse the repository at this point in the history
Signed-off-by: Xin Liu <[email protected]>
  • Loading branch information
apepkuss committed Nov 21, 2024
1 parent ed59328 commit 43f600c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ impl Qdrant {
}

pub async fn create_collection(&self, collection_name: &str, size: u32) -> Result<(), Error> {
if self.collection_exists(collection_name).await? {
bail!("Collection '{}' already exists", collection_name);
}

let params = json!({
"vectors": {
"size": size,
Expand All @@ -81,6 +85,18 @@ impl Qdrant {
self.create_collection_api(collection_name, &params).await
}

pub async fn collection_exists(&self, collection_name: &str) -> Result<bool, Error> {
self.collection_exists_api(collection_name).await
}

pub async fn delete_collection(&self, collection_name: &str) -> Result<(), Error> {
if !self.collection_exists(collection_name).await? {
bail!("Collection '{}' does not exist", collection_name);
}

self.delete_collection_api(collection_name).await
}

pub async fn upsert_points(
&self,
collection_name: &str,
Expand Down Expand Up @@ -209,6 +225,13 @@ impl Qdrant {
}
}

pub async fn collection_exists_api(&self, collection_name: &str) -> Result<bool, Error> {
let url = format!("{}/collections/{}/exists", self.url_base, collection_name,);
let client = reqwest::Client::new();
let res = client.get(&url).send().await?;
Ok(res.status().is_success())
}

pub async fn delete_collection_api(&self, collection_name: &str) -> Result<(), Error> {
let url = format!("{}/collections/{}", self.url_base, collection_name,);

Expand Down

0 comments on commit 43f600c

Please sign in to comment.