use alloc::vec::Vec;
use crate::errors::BackendError;
use crate::types::VectorId;
#[derive(Clone, Debug)]
pub struct SearchResult {
pub vector_id: VectorId,
pub score: f32,
}
impl Ord for SearchResult {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
other
.score
.partial_cmp(&self.score)
.unwrap_or(core::cmp::Ordering::Equal)
.then_with(|| self.vector_id.cmp(&other.vector_id))
}
}
impl PartialOrd for SearchResult {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl PartialEq for SearchResult {
fn eq(&self, other: &Self) -> bool {
self.cmp(other) == core::cmp::Ordering::Equal
}
}
impl Eq for SearchResult {}
pub trait SearchBackend: Send {
fn ingest(&mut self, vectors: &[(VectorId, Vec<f32>)]) -> Result<(), BackendError>;
fn search(&self, query: &[f32], top_k: usize) -> Result<Vec<SearchResult>, BackendError>;
fn remove(&mut self, vector_ids: &[VectorId]) -> Result<(), BackendError>;
fn len(&self) -> usize;
fn is_empty(&self) -> bool {
self.len() == 0
}
fn dim(&self) -> Option<usize>;
}