Skip to main content

Graph

Struct Graph 

Source
pub struct Graph { /* private fields */ }
Expand description

A built proximity graph, before any encoding: over normalized vectors (angular) or the vectors as given (Euclidean). Holds a full-precision copy of the data, so it is a build-time object; the indexes keep only their encodings.

Implementations§

Source§

impl Graph

Source

pub fn build_with_training_queries( data: &[f32], dim: usize, params: &BuildParams, training_queries: Option<&[f32]>, ) -> Result<Self, WarmError>

Builds a graph with optional construction queries in the graph’s input coordinates. Queries must be independent of evaluation data. The first 32768 rows guide additional projected edges; all supplied rows are validated. None preserves the legacy build. MIPS callers must augment base rows and append zero to queries before this call.

Source

pub fn build_owned_with_training_queries( data: Vec<f32>, dim: usize, params: &BuildParams, training_queries: Option<&[f32]>, ) -> Result<Self, WarmError>

Owned-data equivalent of Graph::build_with_training_queries.

Source

pub fn apply_training_queries_with( &mut self, queries: &[f32], limit: usize, neighbors: usize, projected_degree: usize, ) -> Result<ProjectionStats, WarmError>

Applies the first limit construction queries, with the exact neighbours scored per query and the projected degree as arguments; each is capped by the graph size. The neighbours are found by exact scoring of every base row, so the cost grows with limit * n.

Source

pub fn project_training_neighbors( &mut self, queries: &[f32], query_neighbor_ids: &[u32], neighbors_per_query: usize, projected_degree: usize, ) -> Result<ProjectionStats, WarmError>

Projects neighbour lists the caller found for construction queries (for example by an approximate search of an index encoded from this graph), neighbors_per_query ids per query, nearest first. queries are in graph coordinates and only validated; the lists must come from construction queries, never evaluation data.

Source§

impl Graph

Benchmark support: the graph structure (not the vectors) on disk, so that search experiments on one graph need not rebuild it.

Source

pub fn save(&self, path: &Path) -> Result<()>

Writes the header (n, dim, degree, build_ef, alpha, seed, entry, data fingerprint, quantized_search, metric), the adjacency and the upper layers; the vectors are not stored.

Source

pub fn load( data: &[f32], dim: usize, path: &Path, params: &BuildParams, ) -> Result<Self>

Reads a graph written by Graph::save for the same data (prepared here exactly as Graph::build does) and the same params. Any mismatch in the vector count, dimension, degree, build_ef, alpha, seed, quantized search, metric or the data fingerprint is an error, so a stale cache never stands in for a build; delete the file to rebuild.

Source§

impl Graph

Source

pub fn metric(&self) -> Metric

The metric the graph was built for.

Source

pub fn structure_hash(&self) -> u64

Stable 64-bit hash of the structure (adjacency, upper layers, entry): equal values mean a bit-identical graph, across builds, binaries and cache round trips.

Source

pub fn build( data: &[f32], dim: usize, params: &BuildParams, ) -> Result<Self, WarmError>

Build over data (row-major, dim floats per vector). Angular rows are normalized; zero rows stay zero. Uses the rayon pool; the result depends only on the data and params (code_bits is not used).

Source

pub fn build_owned( data: Vec<f32>, dim: usize, params: &BuildParams, ) -> Result<Self, WarmError>

Graph::build over an owned matrix, prepared in place: the caller’s copy is the one the graph keeps, so the vectors are resident once during construction instead of twice (the build’s own copy next to the caller’s).

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnsafeUnpin for Graph

§

impl UnwindSafe for Graph

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more