pub struct VectorIndex { /* private fields */ }Expand description
Wraps usearch::Index and a key-map behind a single std::sync::Mutex.
usearch::Index is Send + Sync, and HashMap is Send, so
VectorIndex is Send + Sync via the mutex.
Implementations§
Source§impl VectorIndex
impl VectorIndex
Sourcepub fn new(dimensions: usize) -> Result<Self, MemoryError>
pub fn new(dimensions: usize) -> Result<Self, MemoryError>
Create a new HNSW index with cosine metric.
Sourcepub fn grow_if_needed(&self, additional: usize) -> Result<(), MemoryError>
pub fn grow_if_needed(&self, additional: usize) -> Result<(), MemoryError>
Ensure the index has capacity for at least additional more vectors.
Sourcepub fn find_key_by_name(&self, name: &str) -> Option<u64>
pub fn find_key_by_name(&self, name: &str) -> Option<u64>
Find the vector key associated with a qualified memory name.
Sourcepub fn add_with_next_key(
&self,
vector: &[f32],
name: String,
) -> Result<u64, MemoryError>
pub fn add_with_next_key( &self, vector: &[f32], name: String, ) -> Result<u64, MemoryError>
Atomically allocate the next key and add the vector in one lock acquisition. Returns the assigned key on success. On failure the counter is not advanced.
Sourcepub fn search(
&self,
query: &[f32],
limit: usize,
) -> Result<Vec<(u64, String, f32)>, MemoryError>
pub fn search( &self, query: &[f32], limit: usize, ) -> Result<Vec<(u64, String, f32)>, MemoryError>
Search for the limit nearest neighbours of query.
Returns (key, distance) pairs sorted by ascending distance.
Sourcepub fn commit_sha(&self) -> Option<String>
pub fn commit_sha(&self) -> Option<String>
Return the commit SHA stored in the index metadata (if any).
Sourcepub fn set_commit_sha(&self, sha: Option<&str>)
pub fn set_commit_sha(&self, sha: Option<&str>)
Set the commit SHA in the index metadata.
Sourcepub fn save(&self, path: &Path) -> Result<(), MemoryError>
pub fn save(&self, path: &Path) -> Result<(), MemoryError>
Persist the index to path. Also writes <path>.keys.json.
If commit_sha is Some, it is written to the metadata alongside the
key map so the next load can verify freshness.
Sourcepub fn load(path: &Path) -> Result<Self, MemoryError>
pub fn load(path: &Path) -> Result<Self, MemoryError>
Load an existing index from path. Also reads <path>.keys.json.
Auto Trait Implementations§
impl !Freeze for VectorIndex
impl RefUnwindSafe for VectorIndex
impl Send for VectorIndex
impl Sync for VectorIndex
impl Unpin for VectorIndex
impl UnsafeUnpin for VectorIndex
impl UnwindSafe for VectorIndex
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