Skip to content

Commit

Permalink
Create Qdrant indexes when creating collection (#5249)
Browse files Browse the repository at this point in the history
  • Loading branch information
flvndvd authored May 23, 2024
1 parent 6662037 commit 1f6959b
Showing 1 changed file with 68 additions and 1 deletion.
69 changes: 68 additions & 1 deletion core/bin/qdrant/create_collection.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;

use anyhow::{anyhow, Result};
use clap::Parser;
use dust::{
Expand All @@ -8,7 +10,7 @@ use dust::{
},
utils,
};
use qdrant_client::qdrant;
use qdrant_client::{client::QdrantClient, qdrant};
use tokio;

#[derive(Parser, Debug)]
Expand All @@ -27,6 +29,69 @@ struct Args {
cluster: QdrantCluster,
}

async fn create_indexes_for_collection(
raw_client: &Arc<QdrantClient>,
cluster: &QdrantCluster,
collection_name: &String,
) -> Result<()> {
let _ = raw_client
.create_field_index(
collection_name,
"document_id_hash",
qdrant::FieldType::Keyword,
None,
None,
)
.await?;

let _ = raw_client
.create_field_index(
collection_name,
"data_source_internal_id",
qdrant::FieldType::Keyword,
None,
None,
)
.await?;

let _ = raw_client
.create_field_index(
collection_name,
"tags",
qdrant::FieldType::Keyword,
None,
None,
)
.await?;

let _ = raw_client
.create_field_index(
collection_name,
"parents",
qdrant::FieldType::Keyword,
None,
None,
)
.await?;

let _ = raw_client
.create_field_index(
collection_name,
"timestamp",
qdrant::FieldType::Integer,
None,
None,
)
.await?;

println!(
"Done creating indexes for collection {} on cluster {}",
collection_name, cluster
);

Ok(())
}

async fn create_qdrant_collection(
cluster: QdrantCluster,
provider_id: ProviderID,
Expand Down Expand Up @@ -141,6 +206,8 @@ async fn create_qdrant_collection(
}?;
}

create_indexes_for_collection(&raw_client, &cluster, &collection_name).await?;

Ok(())
}

Expand Down

0 comments on commit 1f6959b

Please sign in to comment.