use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use crate::document::{Document, ScoredDocument};
use crate::error::Result;
pub trait VectorStore: Send + Sync {
fn upsert(
&self,
id: &str,
embedding: Vec<f32>,
document: Document,
) -> impl Future<Output = Result<()>> + Send;
fn query(
&self,
embedding: Vec<f32>,
top_k: usize,
) -> impl Future<Output = Result<Vec<ScoredDocument>>> + Send;
fn delete(&self, id: &str) -> impl Future<Output = Result<bool>> + Send;
fn count(&self) -> impl Future<Output = Result<usize>> + Send;
}
pub trait ErasedVectorStore: Send + Sync {
fn upsert_erased<'a>(
&'a self,
id: &'a str,
embedding: Vec<f32>,
document: Document,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>;
fn query_erased<'a>(
&'a self,
embedding: Vec<f32>,
top_k: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<ScoredDocument>>> + Send + 'a>>;
fn delete_erased<'a>(
&'a self,
id: &'a str,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'a>>;
fn count_erased(&self) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + '_>>;
}
impl<T: VectorStore> ErasedVectorStore for T {
fn upsert_erased<'a>(
&'a self,
id: &'a str,
embedding: Vec<f32>,
document: Document,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>> {
Box::pin(self.upsert(id, embedding, document))
}
fn query_erased<'a>(
&'a self,
embedding: Vec<f32>,
top_k: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<ScoredDocument>>> + Send + 'a>> {
Box::pin(self.query(embedding, top_k))
}
fn delete_erased<'a>(
&'a self,
id: &'a str,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'a>> {
Box::pin(self.delete(id))
}
fn count_erased(&self) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + '_>> {
Box::pin(self.count())
}
}
pub type SharedVectorStore = Arc<dyn ErasedVectorStore>;