Trait usearch::VectorType

source ·
pub trait VectorType {
    // Required methods
    fn add(index: &Index, key: Key, vector: &[Self]) -> Result<(), Exception>
       where Self: Sized;
    fn get(
        index: &Index,
        key: Key,
        buffer: &mut [Self]
    ) -> Result<usize, Exception>
       where Self: Sized;
    fn search(
        index: &Index,
        query: &[Self],
        count: usize
    ) -> Result<Matches, Exception>
       where Self: Sized;
    fn filtered_search<F>(
        index: &Index,
        query: &[Self],
        count: usize,
        filter: F
    ) -> Result<Matches, Exception>
       where Self: Sized,
             F: Fn(Key) -> bool;
    fn change_metric(
        index: &mut Index,
        metric: Box<dyn Fn(*const Self, *const Self) -> Distance + Send + Sync>
    ) -> Result<(), Exception>
       where Self: Sized;
}
Expand description

The VectorType trait defines operations for managing and querying vectors in an index. It supports generic operations on vectors of different types, allowing for the addition, retrieval, and search of vectors within an index.

Required Methods§

source

fn add(index: &Index, key: Key, vector: &[Self]) -> Result<(), Exception>
where Self: Sized,

Adds a vector to the index under the specified key.

§Parameters
  • index: A reference to the Index where the vector is to be added.
  • key: The key under which the vector should be stored.
  • vector: A slice representing the vector to be added.
§Returns
  • Ok(()) if the vector was successfully added to the index.
  • Err(cxx::Exception) if an error occurred during the operation.
source

fn get(index: &Index, key: Key, buffer: &mut [Self]) -> Result<usize, Exception>
where Self: Sized,

Retrieves a vector from the index by its key.

§Parameters
  • index: A reference to the Index from which the vector is to be retrieved.
  • key: The key of the vector to retrieve.
  • buffer: A mutable slice where the retrieved vector will be stored. The size of the buffer determines the maximum number of elements that can be retrieved.
§Returns
  • Ok(usize) indicating the number of elements actually written into the buffer.
  • Err(cxx::Exception) if an error occurred during the operation.
source

fn search( index: &Index, query: &[Self], count: usize ) -> Result<Matches, Exception>
where Self: Sized,

Performs a search in the index using the given query vector, returning up to count closest matches.

§Parameters
  • index: A reference to the Index where the search is to be performed.
  • query: A slice representing the query vector.
  • count: The maximum number of matches to return.
§Returns
  • Ok(ffi::Matches) containing the matches found.
  • Err(cxx::Exception) if an error occurred during the search operation.

Performs a filtered search in the index using a query vector and a custom filter function, returning up to count matches that satisfy the filter.

§Parameters
  • index: A reference to the Index where the search is to be performed.
  • query: A slice representing the query vector.
  • count: The maximum number of matches to return.
  • filter: A closure that takes a Key and returns true if the corresponding vector should be included in the search results, or false otherwise.
§Returns
  • Ok(ffi::Matches) containing the matches that satisfy the filter.
  • Err(cxx::Exception) if an error occurred during the filtered search operation.
source

fn change_metric( index: &mut Index, metric: Box<dyn Fn(*const Self, *const Self) -> Distance + Send + Sync> ) -> Result<(), Exception>
where Self: Sized,

Changes the metric used for distance calculations within the index.

§Parameters
  • index: A mutable reference to the Index for which the metric is to be changed.
  • metric: A boxed closure that defines the new metric for distance calculation. The closure must take two pointers to elements of type Self and return a Distance.
§Returns
  • Ok(()) if the metric was successfully changed.
  • Err(cxx::Exception) if an error occurred during the operation.

Implementations on Foreign Types§

source§

impl VectorType for f32

source§

fn search( index: &Index, query: &[Self], count: usize ) -> Result<Matches, Exception>

source§

fn get(index: &Index, key: Key, vector: &mut [Self]) -> Result<usize, Exception>

source§

fn add(index: &Index, key: Key, vector: &[Self]) -> Result<(), Exception>

source§

fn change_metric( index: &mut Index, metric: Box<dyn Fn(*const Self, *const Self) -> Distance + Send + Sync> ) -> Result<(), Exception>

source§

impl VectorType for f64

source§

fn search( index: &Index, query: &[Self], count: usize ) -> Result<Matches, Exception>

source§

fn get(index: &Index, key: Key, vector: &mut [Self]) -> Result<usize, Exception>

source§

fn add(index: &Index, key: Key, vector: &[Self]) -> Result<(), Exception>

source§

fn filtered_search<F>( index: &Index, query: &[Self], count: usize, filter: F ) -> Result<Matches, Exception>
where Self: Sized, F: Fn(Key) -> bool,

source§

fn change_metric( index: &mut Index, metric: Box<dyn Fn(*const Self, *const Self) -> Distance + Send + Sync> ) -> Result<(), Exception>

source§

impl VectorType for i8

source§

fn search( index: &Index, query: &[Self], count: usize ) -> Result<Matches, Exception>

source§

fn get(index: &Index, key: Key, vector: &mut [Self]) -> Result<usize, Exception>

source§

fn add(index: &Index, key: Key, vector: &[Self]) -> Result<(), Exception>

source§

fn filtered_search<F>( index: &Index, query: &[Self], count: usize, filter: F ) -> Result<Matches, Exception>
where Self: Sized, F: Fn(Key) -> bool,

source§

fn change_metric( index: &mut Index, metric: Box<dyn Fn(*const Self, *const Self) -> Distance + Send + Sync> ) -> Result<(), Exception>

Implementors§