Trait HNSW

Source
pub trait HNSW {
    // Required methods
    fn search<F>(
        &self,
        txn: &RoTxn<'_>,
        query: &[f64],
        k: usize,
        filter: Option<&[F]>,
        should_trickle: bool,
    ) -> Result<Vec<HVector>, VectorError>
       where F: Fn(&HVector, &RoTxn<'_>) -> bool;
    fn insert<F>(
        &self,
        txn: &mut RwTxn<'_>,
        data: &[f64],
        fields: Option<Vec<(String, Value)>>,
    ) -> Result<HVector, VectorError>
       where F: Fn(&HVector, &RoTxn<'_>) -> bool;
    fn get_all_vectors(
        &self,
        txn: &RoTxn<'_>,
        level: Option<usize>,
    ) -> Result<Vec<HVector>, VectorError>;
    fn get_vector(
        &self,
        txn: &RoTxn<'_>,
        id: u128,
        level: usize,
        with_data: bool,
    ) -> Result<HVector, VectorError>;
}

Required Methods§

Source

fn search<F>( &self, txn: &RoTxn<'_>, query: &[f64], k: usize, filter: Option<&[F]>, should_trickle: bool, ) -> Result<Vec<HVector>, VectorError>
where F: Fn(&HVector, &RoTxn<'_>) -> bool,

Search for the k nearest neighbors of a query vector

§Arguments
  • txn - The transaction to use
  • query - The query vector
  • k - The number of nearest neighbors to search for
§Returns

A vector of tuples containing the id and distance of the nearest neighbors

Source

fn insert<F>( &self, txn: &mut RwTxn<'_>, data: &[f64], fields: Option<Vec<(String, Value)>>, ) -> Result<HVector, VectorError>
where F: Fn(&HVector, &RoTxn<'_>) -> bool,

Insert a new vector into the index

§Arguments
  • txn - The transaction to use
  • data - The vector data
§Returns

An HVector of the data inserted

Source

fn get_all_vectors( &self, txn: &RoTxn<'_>, level: Option<usize>, ) -> Result<Vec<HVector>, VectorError>

Get all vectors from the index at a specific level

§Arguments
  • txn - The read-only transaction to use for retrieving vectors
  • level - A usize for which level to get all vectors from
§Returns

A Result containing a Vec of HVector if successful

Source

fn get_vector( &self, txn: &RoTxn<'_>, id: u128, level: usize, with_data: bool, ) -> Result<HVector, VectorError>

Get specific vector based on id and level

§Arguments
  • txn - The transaction to use
  • id - The id of the vector
  • level - Which level to get the vector from
  • with_data - Whether or not to fetch the vector with data
§Returns

A Result containing a Vec of HVector if successful

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§