pub trait Index: Send + Sync {
type Vector: Storage + ?Sized;
type Error: Error + Display + Send + Sync + 'static;
// Required methods
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>;
// Provided method
fn train(
&mut self,
_ctx: &mut RuntimeResourceRef<'_>,
_samples: &[&Self::Vector],
_completion: CompletionHandle<(), Self::Error>,
) -> ContractResponse<(), Self::Error> { ... }
}Expand description
User-facing Contract trait for a vector index.
Required Associated Types§
Required Methods§
Sourcefn add(
&mut self,
ctx: &mut RuntimeResourceRef<'_>,
vec: &Self::Vector,
completion: CompletionHandle<u64, Self::Error>,
) -> ContractResponse<u64, Self::Error>
fn add( &mut self, ctx: &mut RuntimeResourceRef<'_>, vec: &Self::Vector, completion: CompletionHandle<u64, Self::Error>, ) -> ContractResponse<u64, Self::Error>
Insert a vector. Return Now(Ok(id)) if the assignment is
inline, or retain completion and return Later to deliver
the id off-thread. ctx exposes the per-dispatch runtime
surface, including the
RuntimeResourceRef::dependency lookup for declared
#[depends(...)] siblings.
Sourcefn search(
&self,
ctx: &mut RuntimeResourceRef<'_>,
query: &Self::Vector,
k: u32,
completion: CompletionHandle<Vec<(u64, f32)>, Self::Error>,
) -> ContractResponse<Vec<(u64, f32)>, 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>
Top-k nearest-neighbor search. Return inline results via
Now(Ok(pairs)) or retain completion for off-thread delivery.
ctx carries the runtime surface so the search can resolve
#[depends(...)] siblings (e.g. a bound Backend supplying
distance kernels).
Sourcefn remove(
&mut self,
ctx: &mut RuntimeResourceRef<'_>,
id: u64,
completion: CompletionHandle<(), Self::Error>,
) -> ContractResponse<(), Self::Error>
fn remove( &mut self, ctx: &mut RuntimeResourceRef<'_>, id: u64, completion: CompletionHandle<(), Self::Error>, ) -> ContractResponse<(), Self::Error>
Remove a vector by id. Return Now(Ok(())) if the removal is
synchronous, or retain completion and return Later.
Provided Methods§
Sourcefn train(
&mut self,
_ctx: &mut RuntimeResourceRef<'_>,
_samples: &[&Self::Vector],
_completion: CompletionHandle<(), Self::Error>,
) -> ContractResponse<(), Self::Error>
fn train( &mut self, _ctx: &mut RuntimeResourceRef<'_>, _samples: &[&Self::Vector], _completion: CompletionHandle<(), Self::Error>, ) -> ContractResponse<(), Self::Error>
Optional training pass — IVF needs centroid k-means, PQ needs
sub-vector codebook learning, flat / hand-tuned indexes skip
this. Default returns Now(Ok(())) so impls that do not train
pay zero cost.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".