#[cfg(feature = "vector-memory")]
use std::sync::Arc;
#[cfg(feature = "vector-memory")]
use xz_memory_core::StoreError;
#[cfg(feature = "vector-memory")]
pub struct VectorStore {
inner: Arc<dyn xz_embed::traits::VectorStore>,
}
#[cfg(feature = "vector-memory")]
impl VectorStore {
pub fn new(inner: Arc<dyn xz_embed::traits::VectorStore>) -> Self {
Self { inner }
}
pub async fn store(
&self,
entry: xz_memory_core::types::vector::VectorEntry,
) -> Result<(), StoreError> {
self.inner.insert(entry).await.map_err(|e| StoreError::Backend(e.to_string()))
}
pub async fn search(
&self,
query: &[f32],
limit: usize,
threshold: f32,
) -> Result<Vec<xz_memory_core::types::vector::SearchResult>, StoreError> {
let mut results = self
.inner
.search(query, limit)
.await
.map_err(|e| StoreError::Backend(e.to_string()))?;
results.retain(|r| r.score >= threshold);
Ok(results)
}
pub async fn delete(&self, id: &str) -> Result<(), StoreError> {
self.inner
.delete(&[id.to_string()])
.await
.map_err(|e| StoreError::Backend(e.to_string()))?;
Ok(())
}
}