Skip to main content

HnswGraph

Struct HnswGraph 

Source
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>

Source

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).

Source

pub fn indexed(&self) -> u32

Number of slots covered by the graph (the flat tail starts here).

Source

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.

Source

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).

Auto Trait Implementations§

§

impl<'a> Freeze for HnswGraph<'a>

§

impl<'a> RefUnwindSafe for HnswGraph<'a>

§

impl<'a> Send for HnswGraph<'a>

§

impl<'a> Sync for HnswGraph<'a>

§

impl<'a> Unpin for HnswGraph<'a>

§

impl<'a> UnsafeUnpin for HnswGraph<'a>

§

impl<'a> UnwindSafe for HnswGraph<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.