pub struct AnnIndex { /* private fields */ }Expand description
A built RP-forest index over L2-normalized vectors.
Implementations§
Source§impl AnnIndex
impl AnnIndex
Sourcepub fn build(data: &[Vec<f64>], config: &AnnConfig) -> Self
pub fn build(data: &[Vec<f64>], config: &AnnConfig) -> Self
Build the index from raw (un-normalized) vectors. Each vector is
L2-normalized internally. All vectors must have the same
dimensionality. Panics if data is empty or dimensions
disagree.
Sourcepub fn build_normalized(normalized: Vec<Vec<f64>>, config: &AnnConfig) -> Self
pub fn build_normalized(normalized: Vec<Vec<f64>>, config: &AnnConfig) -> Self
Build from pre-normalized vectors (avoids a redundant
normalization pass when the caller already has unit vectors).
Enforces the same contract as Self::build: panics if
normalized is empty or dimensions disagree.
Sourcepub fn query(&self, query: &[f64], k: usize) -> Vec<(usize, f64)>
pub fn query(&self, query: &[f64], k: usize) -> Vec<(usize, f64)>
Find the k approximate nearest neighbors of query by cosine
similarity. Returns (index, similarity) pairs sorted by
descending similarity. query is L2-normalized internally.
Sourcepub fn query_by_index(&self, index: usize, k: usize) -> Vec<(usize, f64)>
pub fn query_by_index(&self, index: usize, k: usize) -> Vec<(usize, f64)>
Find the k approximate nearest neighbors of the item at
index (excludes self from results).
Sourcepub fn knn_graph(&self, k: usize) -> Vec<Vec<usize>>
pub fn knn_graph(&self, k: usize) -> Vec<Vec<usize>>
Build a full k-NN adjacency list for all items. Returns
knn[i] = indices of the k nearest neighbors of item i
(excluding self), sorted by descending similarity.
Sourcepub fn knn_graph_with_sims(&self, k: usize) -> Vec<Vec<(usize, f64)>>
pub fn knn_graph_with_sims(&self, k: usize) -> Vec<Vec<(usize, f64)>>
Like Self::knn_graph, but keeps each neighbor’s cosine
similarity: graph[i] = (index, similarity) pairs for the k
nearest neighbors of item i (excluding self), sorted by
descending similarity.
Auto Trait Implementations§
impl Freeze for AnnIndex
impl RefUnwindSafe for AnnIndex
impl Send for AnnIndex
impl Sync for AnnIndex
impl Unpin for AnnIndex
impl UnsafeUnpin for AnnIndex
impl UnwindSafe for AnnIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more