pub struct VectorIndex { /* private fields */ }Expand description
Persistent vector index backed by HNSW. Open with VectorIndex::open or
create with VectorIndex::build.
Implementations§
Source§impl VectorIndex
impl VectorIndex
Sourcepub fn build(
path: impl AsRef<Path>,
entries: Vec<(String, Vec<f32>)>,
m: usize,
ef_construct: usize,
) -> Result<Self, DBError>
pub fn build( path: impl AsRef<Path>, entries: Vec<(String, Vec<f32>)>, m: usize, ef_construct: usize, ) -> Result<Self, DBError>
Build a new index from entries, write it to path, and return it.
m (graph connectivity) and ef_construct (build-time beam width)
control quality/speed. Typical values: m=16, ef_construct=200.
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self, DBError>
pub fn open(path: impl AsRef<Path>) -> Result<Self, DBError>
Open a previously built index from path.
Sourcepub fn save(&self) -> Result<(), DBError>
pub fn save(&self) -> Result<(), DBError>
Write this index to disk, overwriting any existing files atomically.
Sourcepub fn search(&self, query: &[f32], top_k: usize) -> Vec<(String, f32)>
pub fn search(&self, query: &[f32], top_k: usize) -> Vec<(String, f32)>
Search for the top_k nearest neighbours to query.
Returns (id, score) pairs sorted by descending score (higher = closer).
Sourcepub fn search_with_ef(
&self,
query: &[f32],
top_k: usize,
ef_search: usize,
) -> Vec<(String, f32)>
pub fn search_with_ef( &self, query: &[f32], top_k: usize, ef_search: usize, ) -> Vec<(String, f32)>
Like [search] but with an explicit ef_search beam width.
pub fn is_empty(&self) -> bool
Sourcepub fn id_at(&self, i: usize) -> Option<&str>
pub fn id_at(&self, i: usize) -> Option<&str>
Return the ID of the vector at internal index position i, if any.
Sourcepub fn position_of(&self, id: &str) -> Option<u64>
pub fn position_of(&self, id: &str) -> Option<u64>
Return the internal index position for a document ID, if present.
Auto Trait Implementations§
impl !Freeze for VectorIndex
impl !RefUnwindSafe for VectorIndex
impl !UnwindSafe for VectorIndex
impl Send for VectorIndex
impl Sync for VectorIndex
impl Unpin for VectorIndex
impl UnsafeUnpin 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
Mutably borrows from an owned value. Read more