Skip to main content

Search

Trait Search 

Source
pub trait Search: AsyncFriendly {
    type Id: Id;
    type Parameters: Clone + AsyncFriendly;
    type Output: AsyncFriendly;

    // Required methods
    fn num_queries(&self) -> usize;
    fn id_count(&self, parameters: &Self::Parameters) -> IdCount;
    fn search<O>(
        &self,
        parameters: &Self::Parameters,
        buffer: &mut O,
        index: usize,
    ) -> impl Future<Output = ANNResult<Self::Output>> + Send
       where O: SearchOutputBuffer<Self::Id> + Send;
}
Expand description

The core search API for approximate nearest neighbor searches.

This uses a model where queries are stored internally and identified by their index. Queries are numbered from 0 to N-1 where N = Search::num_queries() is the total number of queries.

This trait is used in conjunction with search and search_all. See the documentation of those methods for more details.

Required Associated Types§

Source

type Id: Id

The identifier for the type returned by search. These are canonically the unique IDs associated with indexed vectors.

Source

type Parameters: Clone + AsyncFriendly

Custom input search parameters.

Source

type Output: AsyncFriendly

Custom output parameters. This augments the standard metrics collected by search and allows implementation-specific data to be returned.

Required Methods§

Source

fn num_queries(&self) -> usize

The number of queries that can be searched. The machinery in search and search_all will invoke Search::search for each index in 0..N where N is the returned value of this method.

Source

fn id_count(&self, parameters: &Self::Parameters) -> IdCount

Provide a hint for the number of IDs returned for each query. This is used to optimize internal buffer allocations.

Source

fn search<O>( &self, parameters: &Self::Parameters, buffer: &mut O, index: usize, ) -> impl Future<Output = ANNResult<Self::Output>> + Send
where O: SearchOutputBuffer<Self::Id> + Send,

Perform a search for the query identified by index using parameters. The results must be written into buffer. Customized output is returned.

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§

Source§

impl<DP, T, S> Search for KNN<DP, T, S>
where DP: DataProvider<Context: Default, ExternalId: Id>, S: for<'a> DefaultSearchStrategy<DP, &'a [T], DP::ExternalId> + Clone + AsyncFriendly, T: AsyncFriendly + Clone,

Source§

impl<DP, T, S> Search for MultiHop<DP, T, S>
where DP: DataProvider<Context: Default, ExternalId: Id>, S: for<'a> DefaultSearchStrategy<DP, &'a [T], DP::ExternalId> + Clone + AsyncFriendly, T: AsyncFriendly + Clone,

Source§

impl<DP, T, S> Search for Range<DP, T, S>
where DP: DataProvider<Context: Default, ExternalId: Id>, S: for<'a> DefaultSearchStrategy<DP, &'a [T], DP::ExternalId> + Clone + AsyncFriendly, T: AsyncFriendly + Clone,