pub trait VectorGraphExt {
// Required methods
fn configure_vector_index(
&self,
opts: VectorIndexOptions,
) -> Result<(), VectorError>;
fn reindex_vector_index(
&self,
opts: VectorIndexOptions,
) -> Result<(), VectorError>;
fn upsert_vector(&self, n: NodeId, v: &[f32]) -> Result<(), VectorError>;
fn remove_vector(&self, n: NodeId) -> Result<(), VectorError>;
fn vector_search(
&self,
q: &[f32],
k: usize,
) -> Result<Vec<Hit>, VectorError>;
fn vector_search_with(
&self,
q: &[f32],
opts: &VectorSearchOptions,
) -> Result<Vec<Hit>, VectorError>;
fn node_vector(&self, n: NodeId) -> Result<Option<Vec<f32>>, VectorError>;
fn vector_distance(&self, a: &[f32], b: &[f32]) -> Result<f32, VectorError>;
}Expand description
Vector search operations for Graph.
Required Methods§
Sourcefn configure_vector_index(
&self,
opts: VectorIndexOptions,
) -> Result<(), VectorError>
fn configure_vector_index( &self, opts: VectorIndexOptions, ) -> Result<(), VectorError>
Set the metric and quantization for this graph’s vector index.
The choice is persisted, so reopening the graph rebuilds the index with
the same configuration. Call this before upserting the first vector. The
HNSW graph is built per-metric, so the configuration cannot change once
vectors exist: a call that would change the persisted metric or
quantization while embeddings are present returns
VectorError::AlreadyConfigured. Re-applying the identical configuration
is a no-op. When no graph configuration is set, the index defaults to
Cosine and Float32.
Sourcefn reindex_vector_index(
&self,
opts: VectorIndexOptions,
) -> Result<(), VectorError>
fn reindex_vector_index( &self, opts: VectorIndexOptions, ) -> Result<(), VectorError>
Change the metric and quantization and rebuild the index from the persisted embeddings under the new configuration.
Unlike configure_vector_index, this accepts a change after vectors
exist. The raw f32 embeddings are stored in LMDB independently of the
metric, so they are re-indexed under opts; switching back to Float32
recovers full precision from storage. This rebuilds the entire in-memory
HNSW index, so it is O(n) in the number of stored vectors and is intended
as an administrative operation, not a concurrent one: running it while
other threads upsert may drop an in-flight write from the snapshot, which
the next Graph::open rebuild reconciles.
Sourcefn upsert_vector(&self, n: NodeId, v: &[f32]) -> Result<(), VectorError>
fn upsert_vector(&self, n: NodeId, v: &[f32]) -> Result<(), VectorError>
Persist v under n.
Sourcefn remove_vector(&self, n: NodeId) -> Result<(), VectorError>
fn remove_vector(&self, n: NodeId) -> Result<(), VectorError>
Remove the embedding for n from the index and from persistent storage.
Sourcefn vector_search(&self, q: &[f32], k: usize) -> Result<Vec<Hit>, VectorError>
fn vector_search(&self, q: &[f32], k: usize) -> Result<Vec<Hit>, VectorError>
Return the k approximate nearest neighbors to q by cosine distance.
Sourcefn vector_search_with(
&self,
q: &[f32],
opts: &VectorSearchOptions,
) -> Result<Vec<Hit>, VectorError>
fn vector_search_with( &self, q: &[f32], opts: &VectorSearchOptions, ) -> Result<Vec<Hit>, VectorError>
Return the opts.k approximate nearest neighbors that satisfy the label
and property filters in opts.
When neither opts.label nor opts.properties is set the call is
identical to vector_search(q, opts.k). When a filter is set, it is
applied during the HNSW traversal through a predicate, so the search
keeps expanding until it has opts.k matching neighbors rather than
post-filtering a fixed over-fetch (which silently under-returns for
selective filters). A node matches when it carries opts.label (if set)
and every entry in opts.properties (if set) equals the node’s value for
that property. Fewer than opts.k results are returned only when the
index genuinely contains fewer matching nodes.
Sourcefn node_vector(&self, n: NodeId) -> Result<Option<Vec<f32>>, VectorError>
fn node_vector(&self, n: NodeId) -> Result<Option<Vec<f32>>, VectorError>
Return the full-precision embedding stored for n, or None when the
node has no embedding. This is a point lookup against LMDB and does not
build or consult the in-memory HNSW index.
Sourcefn vector_distance(&self, a: &[f32], b: &[f32]) -> Result<f32, VectorError>
fn vector_distance(&self, a: &[f32], b: &[f32]) -> Result<f32, VectorError>
Distance between two vectors under this graph’s configured metric
(default Cosine). The convention matches vector_search: squared L2 for
L2 and 1 - dot for Dot. Returns DimensionMismatch when the two
vectors differ in length.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".