pub struct HnswIndex { /* private fields */ }Expand description
HNSW vector index backed by usearch.
Implementations§
Source§impl HnswIndex
impl HnswIndex
Sourcepub fn new(config: VectorConfig) -> Result<Self, CodememError>
pub fn new(config: VectorConfig) -> Result<Self, CodememError>
Create a new HNSW index with the given configuration.
Sourcepub fn with_defaults() -> Result<Self, CodememError>
pub fn with_defaults() -> Result<Self, CodememError>
Create a new index with default configuration (768-dim, cosine).
Sourcepub fn rebuild_from_entries(
&mut self,
entries: &[(String, Vec<f32>)],
) -> Result<(), CodememError>
pub fn rebuild_from_entries( &mut self, entries: &[(String, Vec<f32>)], ) -> Result<(), CodememError>
Rebuild the index from scratch using the provided entries.
This eliminates ghost entries left behind by remove() (usearch marks
removed keys but does not free their memory). The caller should collect
all live (id, embedding) pairs — typically from SQLite — and pass them
here.
Sourcepub fn needs_compaction(&self) -> bool
pub fn needs_compaction(&self) -> bool
Returns true if ghost entries exceed 20% of live entries, suggesting a rebuild.
Sourcepub fn ghost_count(&self) -> usize
pub fn ghost_count(&self) -> usize
Returns the number of ghost entries in the index.
Trait Implementations§
Source§impl VectorBackend for HnswIndex
impl VectorBackend for HnswIndex
Source§fn insert(&mut self, id: &str, embedding: &[f32]) -> Result<(), CodememError>
fn insert(&mut self, id: &str, embedding: &[f32]) -> Result<(), CodememError>
Insert a vector with associated ID.
Source§fn insert_batch(
&mut self,
items: &[(String, Vec<f32>)],
) -> Result<(), CodememError>
fn insert_batch( &mut self, items: &[(String, Vec<f32>)], ) -> Result<(), CodememError>
Batch insert vectors.
Source§fn search(
&self,
query: &[f32],
k: usize,
) -> Result<Vec<(String, f32)>, CodememError>
fn search( &self, query: &[f32], k: usize, ) -> Result<Vec<(String, f32)>, CodememError>
Search for k nearest neighbors. Returns (id, distance) pairs.
Source§fn stats(&self) -> VectorStats
fn stats(&self) -> VectorStats
Get index statistics.
Auto Trait Implementations§
impl Freeze for HnswIndex
impl !RefUnwindSafe for HnswIndex
impl Send for HnswIndex
impl Sync for HnswIndex
impl Unpin for HnswIndex
impl UnsafeUnpin for HnswIndex
impl !UnwindSafe for HnswIndex
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