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
impl Graph
Sourcepub fn build_with_training_queries(
data: &[f32],
dim: usize,
params: &BuildParams,
training_queries: Option<&[f32]>,
) -> Result<Self, WarmError>
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.
Sourcepub fn build_owned_with_training_queries(
data: Vec<f32>,
dim: usize,
params: &BuildParams,
training_queries: Option<&[f32]>,
) -> Result<Self, WarmError>
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.
Sourcepub fn apply_training_queries_with(
&mut self,
queries: &[f32],
limit: usize,
neighbors: usize,
projected_degree: usize,
) -> Result<ProjectionStats, WarmError>
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.
Sourcepub fn project_training_neighbors(
&mut self,
queries: &[f32],
query_neighbor_ids: &[u32],
neighbors_per_query: usize,
projected_degree: usize,
) -> Result<ProjectionStats, WarmError>
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.
impl Graph
Benchmark support: the graph structure (not the vectors) on disk, so that search experiments on one graph need not rebuild it.
Sourcepub fn save(&self, path: &Path) -> Result<()>
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.
Sourcepub fn load(
data: &[f32],
dim: usize,
path: &Path,
params: &BuildParams,
) -> Result<Self>
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
impl Graph
Sourcepub fn structure_hash(&self) -> u64
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.
Sourcepub fn build(
data: &[f32],
dim: usize,
params: &BuildParams,
) -> Result<Self, WarmError>
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).
Sourcepub fn build_owned(
data: Vec<f32>,
dim: usize,
params: &BuildParams,
) -> Result<Self, WarmError>
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> 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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.