Skip to main content

ANNIndexExternal

Trait ANNIndexExternal 

Source
pub trait ANNIndexExternal<'a, const N: usize> {
    type Index;

    // Required methods
    fn build<R: Rng>(
        num_trees: usize,
        max_leaf_size: usize,
        vectors: &'a [Vector<N>],
        rng: &mut R,
    ) -> Result<Self::Index, &'static str>;
    fn search(&self, query: &Vector<N>, top_k: usize) -> Vec<(usize, f32)>;
    fn memory_usage(&self) -> usize;
}
Expand description

A trait for ANNIndex that references external data. The index is read-only once built.

Required Associated Types§

Required Methods§

Source

fn build<R: Rng>( num_trees: usize, max_leaf_size: usize, vectors: &'a [Vector<N>], rng: &mut R, ) -> Result<Self::Index, &'static str>

Build the index for the given vectors and ids.

§Arguments
  • num_trees - The number of trees to build, higher means more accurate but slower and larger memory usage.
  • max_leaf_size - The maximum number of vectors in a leaf node, lower means higher accuracy but slower search.
  • vectors - The vectors to build the index from.
Source

fn search(&self, query: &Vector<N>, top_k: usize) -> Vec<(usize, f32)>

Search for the top_k nearest neighbors of the query vector.

§Arguments
  • query - The query vector to search for.
  • top_k - The number of nearest neighbors to return.
§Returns
  • Vec<(usize, f32)> - The top_k nearest (index, distance) of the query vector.
Source

fn memory_usage(&self) -> usize

Get the memory usage of the index.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<'a, const N: usize> ANNIndexExternal<'a, N> for LinearSearchExternal<'a, N>

Source§

impl<'a, const N: usize> ANNIndexExternal<'a, N> for LshExternal<'a, N>