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 connectivity(&self) -> ConnectivityStats
pub fn connectivity(&self) -> ConnectivityStats
Component structure and reachability of the bottom layer.
Sourcepub fn add_escape_edges(&mut self) -> Result<ConnectivityStats, WarmError>
pub fn add_escape_edges(&mut self) -> Result<ConnectivityStats, WarmError>
Adds one edge from each small sink component to the nearest row of the largest component, then reports the structure after the repair. Deterministic.
Sourcepub fn add_reach_edges(&mut self) -> Result<ConnectivityStats, WarmError>
pub fn add_reach_edges(&mut self) -> Result<ConnectivityStats, WarmError>
Gives every vertex the entry cannot reach an in-edge from the nearest reachable vertex, then reports the structure after the repair. A source with no free slot swaps its farthest out-edge whose target keeps another in-edge, so no vertex is orphaned by the swap and the encoding keeps its size. Uses no queries or truth.
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 apply_training_queries_keeping(
&mut self,
queries: &[f32],
limit: usize,
neighbors: usize,
projected_degree: usize,
) -> Result<(ProjectionStats, Vec<u32>, usize), WarmError>
pub fn apply_training_queries_keeping( &mut self, queries: &[f32], limit: usize, neighbors: usize, projected_degree: usize, ) -> Result<(ProjectionStats, Vec<u32>, usize), WarmError>
Graph::apply_training_queries_with, also returning the exact neighbour lists it
projected (row ids, nearest first) and their length per query; the lists cover the
first ids.len() / per_query queries.
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
impl Graph
Sourcepub fn build_with_repair(
data: &[f32],
dim: usize,
params: &BuildParams,
repair: Option<(&[f32], &RepairParams)>,
) -> Result<Self, WarmError>
pub fn build_with_repair( data: &[f32], dim: usize, params: &BuildParams, repair: Option<(&[f32], &RepairParams)>, ) -> Result<Self, WarmError>
Builds a graph and, when repair is given, applies Graph::apply_query_repair.
None is the legacy build.
Sourcepub fn apply_query_repair(
&mut self,
queries: &[f32],
params: &RepairParams,
) -> Result<RepairStats, WarmError>
pub fn apply_query_repair( &mut self, queries: &[f32], params: &RepairParams, ) -> Result<RepairStats, WarmError>
Applies query-reinforced repair with the first 32768 construction queries (graph
coordinates), whose exact neighbours are found by scoring every base row. Every
existing edge is kept; added edges go to the end of their lists. The result can be
encoded and saved as a VGraph; its graph cache is refused.
Sourcepub fn apply_query_repair_with_neighbors(
&mut self,
queries: &[f32],
truth: &[u32],
params: &RepairParams,
) -> Result<RepairStats, WarmError>
pub fn apply_query_repair_with_neighbors( &mut self, queries: &[f32], truth: &[u32], params: &RepairParams, ) -> Result<RepairStats, WarmError>
Graph::apply_query_repair with the caller’s exact neighbours of every query,
params.k ids per query, nearest first. They 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 release_structure(&mut self)
pub fn release_structure(&mut self)
Frees the topology (lists, upper layers) once the graph is encoded, keeping the rows and build parameters that a persisted base still needs. The graph can no longer be searched, saved or repaired.
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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 more§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§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).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.