AnnScan

Struct AnnScan 

Source
pub struct AnnScan<'a, E: StorageEngine> { /* private fields */ }
Expand description

Approximate nearest neighbor search operator.

Uses an HNSW index to efficiently find the K nearest neighbors to a query vector. The search is approximate, trading some accuracy for speed.

§Example

use manifoldb_vector::ops::{AnnScan, VectorOperator, SearchConfig};

let config = SearchConfig::k_nearest(10).with_ef_search(50);
let mut scan = AnnScan::new(&index, query, config)?;

while let Some(m) = scan.next()? {
    println!("Entity {:?} at distance {}", m.entity_id, m.distance);
}

Implementations§

Source§

impl<'a, E: StorageEngine> AnnScan<'a, E>

Source

pub fn new( index: &'a HnswIndex<E>, query: &Embedding, config: SearchConfig, ) -> Result<Self, VectorError>

Create a new ANN scan operator.

Performs the HNSW search immediately and buffers the results for iteration. This is because HNSW search is most efficient when performed as a single operation.

§Arguments
  • index - Reference to the HNSW index
  • query - The query embedding
  • config - Search configuration (k, max_distance, ef_search)
§Errors

Returns an error if the query dimension doesn’t match the index.

Source

pub fn k_nearest( index: &'a HnswIndex<E>, query: &Embedding, k: usize, ) -> Result<Self, VectorError>

Create an ANN scan with simple k-nearest configuration.

Convenience method for common case of finding K nearest neighbors.

§Arguments
  • index - Reference to the HNSW index
  • query - The query embedding
  • k - Number of nearest neighbors to find
§Errors

Returns an error if the query dimension doesn’t match the index.

Source

pub fn within_distance( index: &'a HnswIndex<E>, query: &Embedding, max_distance: f32, max_results: usize, ) -> Result<Self, VectorError>

Create an ANN scan to find vectors within a distance threshold.

Note: HNSW is optimized for k-NN search. For within-distance queries, this searches for a large k and filters by distance. Consider using ExactKnn for precise distance-based filtering on small sets.

§Arguments
  • index - Reference to the HNSW index
  • query - The query embedding
  • max_distance - Maximum distance threshold
  • max_results - Maximum number of results to return
§Errors

Returns an error if the query dimension doesn’t match the index.

Source

pub const fn index(&self) -> &'a HnswIndex<E>

Get the underlying index.

Source

pub fn len(&self) -> usize

Get the number of results found.

Source

pub fn is_empty(&self) -> bool

Check if no results were found.

Source

pub fn peek(&self) -> Option<&VectorMatch>

Peek at the next result without consuming it.

Source

pub fn reset(&mut self)

Reset the iterator to the beginning.

Trait Implementations§

Source§

impl<E: StorageEngine> VectorOperator for AnnScan<'_, E>

Source§

fn next(&mut self) -> Result<Option<VectorMatch>, VectorError>

Get the next match from the operator. Read more
Source§

fn dimension(&self) -> usize

Get the dimension of vectors this operator works with.
Source§

fn collect_all(&mut self) -> Result<Vec<VectorMatch>, VectorError>

Collect all remaining matches into a vector. Read more

Auto Trait Implementations§

§

impl<'a, E> Freeze for AnnScan<'a, E>

§

impl<'a, E> RefUnwindSafe for AnnScan<'a, E>
where E: RefUnwindSafe,

§

impl<'a, E> Send for AnnScan<'a, E>

§

impl<'a, E> Sync for AnnScan<'a, E>

§

impl<'a, E> Unpin for AnnScan<'a, E>

§

impl<'a, E> UnwindSafe for AnnScan<'a, E>
where E: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more