pub struct HnswGraph<'a> { /* private fields */ }Expand description
The navigable small-world graph. See the module docs.
The upper-level pools carry a lifetime so a read-only open can borrow
them from an mmap; level0 stays owned (it is rebuilt into
a Vec<u32> on load — small metadata, not content-scaled). The owned
build/load paths are 'static.
Implementations§
Source§impl<'a> HnswGraph<'a>
impl<'a> HnswGraph<'a>
Sourcepub fn new(m: usize, m0: usize, max_bytes: usize) -> Result<Self, Error>
pub fn new(m: usize, m0: usize, max_bytes: usize) -> Result<Self, Error>
An empty graph for the given degree caps (m >= 2, m0 >= m —
enforced by Config::validate).
Sourcepub fn insert_bulk(
&mut self,
pool: &VecPool<'_>,
upto: u32,
ef_construction: usize,
scratch: &mut HnswScratch,
) -> Result<(), Error>
pub fn insert_bulk( &mut self, pool: &VecPool<'_>, upto: u32, ef_construction: usize, scratch: &mut HnswScratch, ) -> Result<(), Error>
Inserts every slot in [indexed, upto) into the graph (
Alg. 1). Called from maintain — bulk, deterministic, never from
remember.
Sourcepub fn search(
&self,
pool: &VecPool<'_>,
query: &[f32],
ef: usize,
vec_scratch: &mut VecScratch,
scratch: &mut HnswScratch,
out: &mut Vec<(u32, f32)>,
) -> Result<(), Error>
pub fn search( &self, pool: &VecPool<'_>, query: &[f32], ef: usize, vec_scratch: &mut VecScratch, scratch: &mut HnswScratch, out: &mut Vec<(u32, f32)>, ) -> Result<(), Error>
k-NN query over a raw embedding: quantizes it through the pool
(into vec_scratch) and runs the level-descending beam search.
Results land in out as (slot, cosine), best first — the
caller filters and merges with the flat tail.
§Errors
The pool’s quantization errors (crate::Error::DimMismatch,
crate::Error::Invalid for non-finite or zero vectors).