feat: Implement NATS-based event processing for note smart features and add Qdrant collection auto-creation.

This commit is contained in:
2025-12-26 00:19:41 +01:00
parent 178d59540e
commit 64f8118228
11 changed files with 155 additions and 6 deletions

View File

@@ -47,6 +47,7 @@ pub async fn build_vector_store(
match provider {
VectorProvider::Qdrant { url, collection } => {
let adapter = crate::vector::qdrant::QdrantVectorAdapter::new(url, collection)?;
adapter.create_collection_if_not_exists().await?;
Ok(Arc::new(adapter))
}
}

View File

@@ -2,7 +2,10 @@ use async_trait::async_trait;
use notes_domain::errors::{DomainError, DomainResult};
use notes_domain::ports::VectorStore;
use qdrant_client::Qdrant;
use qdrant_client::qdrant::{PointStruct, SearchPointsBuilder, UpsertPointsBuilder, Value};
use qdrant_client::qdrant::{
CreateCollectionBuilder, Distance, PointStruct, SearchPointsBuilder, UpsertPointsBuilder,
Value, VectorParamsBuilder,
};
use std::collections::HashMap;
use std::sync::Arc;
use uuid::Uuid;
@@ -23,6 +26,31 @@ impl QdrantVectorAdapter {
collection_name: collection_name.to_string(),
})
}
pub async fn create_collection_if_not_exists(&self) -> DomainResult<()> {
if !self
.client
.collection_exists(&self.collection_name)
.await
.map_err(|e| {
DomainError::InfrastructureError(format!(
"Failed to check collection existence: {}",
e
))
})?
{
self.client
.create_collection(
CreateCollectionBuilder::new(self.collection_name.clone())
.vectors_config(VectorParamsBuilder::new(384, Distance::Cosine)),
)
.await
.map_err(|e| {
DomainError::InfrastructureError(format!("Failed to create collection: {}", e))
})?;
}
Ok(())
}
}
#[async_trait]