use crate::completion::{CompletionHandle, ContractResponse};
use crate::runtime::RuntimeResourceRef;
pub trait Index: Send + Sync {
type Vector: ?Sized + bb_ir::types::Storage;
type Error: std::error::Error + std::fmt::Display + Send + Sync + 'static;
fn add(
&mut self,
ctx: &mut RuntimeResourceRef<'_>,
vec: &Self::Vector,
completion: CompletionHandle<u64, Self::Error>,
) -> ContractResponse<u64, Self::Error>;
fn search(
&self,
ctx: &mut RuntimeResourceRef<'_>,
query: &Self::Vector,
k: u32,
completion: CompletionHandle<Vec<(u64, f32)>, Self::Error>,
) -> ContractResponse<Vec<(u64, f32)>, Self::Error>;
fn remove(
&mut self,
ctx: &mut RuntimeResourceRef<'_>,
id: u64,
completion: CompletionHandle<(), Self::Error>,
) -> ContractResponse<(), Self::Error>;
fn train(
&mut self,
_ctx: &mut RuntimeResourceRef<'_>,
_samples: &[&Self::Vector],
_completion: CompletionHandle<(), Self::Error>,
) -> ContractResponse<(), Self::Error> {
ContractResponse::Now(Ok(()))
}
}