Skip to main content

Index

Trait Index 

Source
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§

Source

type Vector: Storage + ?Sized

Vector storage. Library makers pick the tree position by picking the type: [f32] for an f32-native index, bb_ir::types::AnyTensor for a generic algorithm-class index that outsources distance math to a bound Backend, a custom packed type for specialized dtypes.

Source

type Error: Error + Display + Send + Sync + 'static

Library-maker-defined error type. The handle serializes the error’s Display rendering on completion failure.

Required Methods§

Source

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.

Source

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).

Source

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§

Source

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".

Implementors§