pub struct HnswIndex { /* private fields */ }Expand description
Wrapper around usearch::Index providing a typed interface.
Implementations§
Source§impl HnswIndex
impl HnswIndex
Sourcepub fn new(
dim: usize,
vtype: VectorType,
metric: DistanceMetric,
params: Option<HnswParams>,
) -> Result<Self, IndexError>
pub fn new( dim: usize, vtype: VectorType, metric: DistanceMetric, params: Option<HnswParams>, ) -> Result<Self, IndexError>
Create a new empty HNSW index.
pub fn is_empty(&self) -> bool
Sourcepub fn add(&self, key: u64, blob: &[u8]) -> Result<(), IndexError>
pub fn add(&self, key: u64, blob: &[u8]) -> Result<(), IndexError>
Add a vector to the index. The blob must match the index’s type and dimension.
Sourcepub fn search(
&self,
query_blob: &[u8],
k: usize,
) -> Result<Vec<(u64, f32)>, IndexError>
pub fn search( &self, query_blob: &[u8], k: usize, ) -> Result<Vec<(u64, f32)>, IndexError>
Search for k nearest neighbors. Returns vec of (key, distance) pairs sorted by distance ascending.
Sourcepub fn save_to_buffer(&self) -> Result<Vec<u8>, IndexError>
pub fn save_to_buffer(&self) -> Result<Vec<u8>, IndexError>
Serialize the index to a byte buffer.
Sourcepub fn load_from_buffer(&self, buf: &[u8]) -> Result<(), IndexError>
pub fn load_from_buffer(&self, buf: &[u8]) -> Result<(), IndexError>
Load index state from a byte buffer. Replaces current index contents.
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