Skip to main content

NswGraph

Struct NswGraph 

Source
pub struct NswGraph {
    pub m: usize,
    pub m_max_0: usize,
    pub entry: Option<usize>,
    pub entry_level: u8,
    pub levels: PersistentVec<u8>,
    pub layers: Vec<PersistentVec<Vec<u32>>>,
}
Expand description

Multi-layer HNSW graph (v2.13). Each node is assigned a top_level; it appears in layers 0..=top_level. Higher layers are sparser, so search starts from the entry at the top layer, greedy-descends to layer 0, and beam-searches there. Layer 0 keeps a larger neighbour budget (m_max_0 = 2 * m per the HNSW paper); upper layers cap at m. The struct name stays NswGraph so external users / on-disk callers don’t have to track a rename — the algorithm changed, the data slot didn’t.

Fields§

§m: usize

Max neighbours per node on layers ≥ 1.

§m_max_0: usize

Max neighbours on layer 0 (the dense bottom layer). HNSW convention: m_max_0 = 2 * m.

§entry: Option<usize>

Entry point — the node that sits on the topmost layer. Search always starts here.

§entry_level: u8

Top layer of the entry node (== layers.len() - 1 when populated).

§levels: PersistentVec<u8>

levels[i] = top layer of node i. Nodes whose vector cell is NULL / non-Vector have levels[i] = 0 and no neighbour entries.

v5.5.0: backed by PersistentVec so NswGraph::clone (and the Catalog::clone on every group-commit write that contains it) is O(1) structural-sharing instead of an O(N) element copy.

§layers: Vec<PersistentVec<Vec<u32>>>

layers[l][i] = neighbours of node i at layer l. Inner vec is empty when node i doesn’t reach layer l.

v5.5.0: the per-node middle dimension (the O(N) one) is a PersistentVec; the outer layer dimension stays a plain Vec (layer count ≤ 8, so its clone is O(1) in practice) and the inner neighbour list stays a Vec (bounded by m_max_0).

v6.1.x: neighbour slot widened from usize (8 B on 64-bit) to u32 (4 B). Row indices are catalog-bounded by u32::MAX (4G rows per table); the cast at the NSW boundary asserts this. At 1M dim-128 SQ8, layer 0 adjacency alone shrinks by ~128 MiB — the largest single contribution to the v6.0.5-measured 624 MiB ambition gap. On-disk format already used u32 LE, so this is a pure in-memory layout change; no FILE_VERSION bump.

Implementations§

Source§

impl NswGraph

Source

pub const fn cap_for_layer(&self, layer: u8) -> usize

Max-neighbour budget for layer l.

Trait Implementations§

Source§

impl Clone for NswGraph

Source§

fn clone(&self) -> NswGraph

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NswGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.