pub struct Hnsw { /* private fields */ }Expand description
One shard’s ANN graph for one index.
Implementations§
Source§impl Hnsw
impl Hnsw
Sourcepub fn new(dim: usize, params: HnswParams) -> Self
pub fn new(dim: usize, params: HnswParams) -> Self
Empty graph for dim-dimensional vectors.
Sourcepub fn apply(&mut self, key: &[u8], vector: Option<Vec<f32>>)
pub fn apply(&mut self, key: &[u8], vector: Option<Vec<f32>>)
Insert or replace key’s vector (None = remove). Replace =
detach old key (tombstone the node once keyless) + insert new.
Keys sharing one exact vector share one graph node.
Sourcepub fn knn(&self, query: &[f32], k: usize, ef: usize) -> Vec<(Vec<u8>, f32)>
pub fn knn(&self, query: &[f32], k: usize, ef: usize) -> Vec<(Vec<u8>, f32)>
k nearest LIVING vectors to query (raw form; prepared here).
ef = query beam width (0 → the max(4k, 100) default); larger
beams trade latency for recall — the canonical HNSW knob.
Sourcepub fn vectors(&self) -> u64
pub fn vectors(&self) -> u64
Live (non-tombstoned) vectors — already tracked, so O(1).
Self::stats walks every node and every link to estimate bytes;
a caller that only wants the count should not trigger that walk.
Sourcepub fn stats(&self) -> VectorStats
pub fn stats(&self) -> VectorStats
Counters.
Auto Trait Implementations§
impl Freeze for Hnsw
impl RefUnwindSafe for Hnsw
impl Send for Hnsw
impl Sync for Hnsw
impl Unpin for Hnsw
impl UnsafeUnpin for Hnsw
impl UnwindSafe for Hnsw
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