pub struct NeighborhoodSearch { /* private fields */ }Expand description
HNSW neighborhood search algorithms
Provides high-performance k-nearest neighbor search using the HNSW algorithm with dynamic candidate management and layer-based navigation.
Implementations§
Source§impl NeighborhoodSearch
impl NeighborhoodSearch
Sourcepub fn new(distance_metric: DistanceMetric) -> Self
pub fn new(distance_metric: DistanceMetric) -> Self
Create a new neighborhood search instance
§Arguments
distance_metric- Distance metric to use for similarity computation
§Returns
New NeighborhoodSearch instance
§Examples
use sqlitegraph::hnsw::{NeighborhoodSearch, DistanceMetric};
let search = NeighborhoodSearch::new(DistanceMetric::Cosine);
// Ready for k-NN search operationsSourcepub fn search_layer(
&self,
layer: &HnswLayer,
query_vector: &[f32],
vectors: &[Vec<f32>],
entry_points: &[u64],
k: usize,
) -> Result<SearchResult, HnswError>
pub fn search_layer( &self, layer: &HnswLayer, query_vector: &[f32], vectors: &[Vec<f32>], entry_points: &[u64], k: usize, ) -> Result<SearchResult, HnswError>
Find k-nearest neighbors in a single layer
Performs greedy search within a specific layer to find the nearest neighbors to the query vector.
§Arguments
layer- Target layer for searchquery_vector- Query vector for similarity comparisonvectors- Vector storage (node_id -> vector mapping)entry_points- Initial entry points for searchk- Number of neighbors to find
§Returns
SearchResult with k nearest neighbors or error
§Examples
use sqlitegraph::hnsw::{NeighborhoodSearch, DistanceMetric};
let search = NeighborhoodSearch::new(DistanceMetric::Cosine);
let vectors: Vec<Vec<f32>> = create_test_vectors();
let layer = create_test_layer();
let result = search.search_layer(
&layer,
&query_vector,
&vectors,
&[0, 1], // entry points
5 // k = 5
)?;Trait Implementations§
Auto Trait Implementations§
impl Freeze for NeighborhoodSearch
impl RefUnwindSafe for NeighborhoodSearch
impl Send for NeighborhoodSearch
impl Sync for NeighborhoodSearch
impl Unpin for NeighborhoodSearch
impl UnwindSafe for NeighborhoodSearch
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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