pub struct ScopedIndex { /* private fields */ }Expand description
Manages multiple VectorIndex instances — one per scope (global, each
project) plus a combined “all” index. Every memory exists in exactly two
indexes: its scope-specific index + the “all” index.
ScopedIndex is Send + Sync because all inner state is protected by
RwLock / Mutex.
Implementations§
Source§impl ScopedIndex
impl ScopedIndex
Sourcepub fn new(dimensions: usize) -> Result<Self, MemoryError>
pub fn new(dimensions: usize) -> Result<Self, MemoryError>
Create a new ScopedIndex with empty global + all indexes.
Sourcepub fn add(
&self,
scope: &Scope,
vector: &[f32],
qualified_name: String,
) -> Result<u64, MemoryError>
pub fn add( &self, scope: &Scope, vector: &[f32], qualified_name: String, ) -> Result<u64, MemoryError>
Insert vector into both the scope-specific index and the all-index.
Handles upserts: if qualified_name already exists in either index, the
old entry is removed after the new one is successfully inserted.
Returns the key assigned in the all-index.
Sourcepub fn remove(
&self,
scope: &Scope,
qualified_name: &str,
) -> Result<(), MemoryError>
pub fn remove( &self, scope: &Scope, qualified_name: &str, ) -> Result<(), MemoryError>
Remove a memory by qualified name from both the scope-specific index and the all-index.
Both removals are best-effort: an error in one does not prevent the
other from running. Returns Ok(()) regardless of individual failures.
Sourcepub fn search(
&self,
filter: &ScopeFilter,
query: &[f32],
limit: usize,
) -> Result<Vec<(u64, String, f32)>, MemoryError>
pub fn search( &self, filter: &ScopeFilter, query: &[f32], limit: usize, ) -> Result<Vec<(u64, String, f32)>, MemoryError>
Search for the nearest neighbours of query, routing to the correct
indexes based on filter.
filter | Indexes searched | Merge strategy |
|---|---|---|
GlobalOnly | global | Direct top-k |
ProjectAndGlobal(p) | global + projects/p | Merge by distance, top-k |
All | all combined index | Direct top-k |
Sourcepub fn find_key_by_name(&self, qualified_name: &str) -> Option<u64>
pub fn find_key_by_name(&self, qualified_name: &str) -> Option<u64>
Find the key for a given qualified name in the all-index (not scope-specific).
This is the canonical lookup — the all-index contains every memory regardless of scope.
Sourcepub fn grow_if_needed(&self, additional: usize) -> Result<(), MemoryError>
pub fn grow_if_needed(&self, additional: usize) -> Result<(), MemoryError>
Grow all indexes to accommodate additional more vectors.
Reserved for future batch-insert operations; no production callers currently exist.
Sourcepub fn save(&self, dir: &Path) -> Result<(), MemoryError>
pub fn save(&self, dir: &Path) -> Result<(), MemoryError>
Persist all indexes to subdirectories under dir.
Layout:
dir/
all/index.usearch (+ .keys.json)
global/index.usearch
projects/foo/index.usearchSourcepub fn load(dir: &Path, dimensions: usize) -> Result<Self, MemoryError>
pub fn load(dir: &Path, dimensions: usize) -> Result<Self, MemoryError>
Load all indexes from subdirectories under dir.
Missing subdirectories are treated as empty — those scopes will be rebuilt incrementally on next use.
Sourcepub fn commit_sha(&self) -> Option<String>
pub fn commit_sha(&self) -> Option<String>
Read the commit SHA from the all-index metadata.
Sourcepub fn set_commit_sha(&self, sha: Option<&str>)
pub fn set_commit_sha(&self, sha: Option<&str>)
Set the commit SHA on all sub-indexes.
Auto Trait Implementations§
impl !Freeze for ScopedIndex
impl RefUnwindSafe for ScopedIndex
impl Send for ScopedIndex
impl Sync for ScopedIndex
impl Unpin for ScopedIndex
impl UnsafeUnpin for ScopedIndex
impl UnwindSafe for ScopedIndex
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