Skip to main content

VectorGraphExt

Trait VectorGraphExt 

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

Source

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.

A build without hnsw accepts a non-Float32 quantization and persists it, but cannot honor it: that backend keeps the raw f32, so the memory reduction the quantization names does not happen. The tag is still recorded rather than rejected, because it is honored by any later build that does have hnsw opening the same directory.

Source

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 index, so it is O(n) in the number of stored vectors and is intended as an administrative operation. It is serialized against concurrent upserts and removes, which block for the duration of the rebuild.

Source

fn upsert_vector(&self, n: NodeId, v: &[f32]) -> Result<(), VectorError>

Persist v under n.

Source

fn remove_vector(&self, n: NodeId) -> Result<(), VectorError>

Remove the embedding for n from the index and from persistent storage.

Return the k nearest neighbors to q under this graph’s configured metric (default Cosine). Approximate with hnsw, exact without it.

Returns VectorError::EmptyIndex when the graph holds no embeddings at all, so a caller can distinguish “no semantic matches” from “there is nothing to search”.

Source

fn vector_search_with( &self, q: &[f32], opts: &VectorSearchOptions, ) -> Result<Vec<Hit>, VectorError>

Return the opts.k 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 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.

Source

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 index.

Source

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".

Implementations on Foreign Types§

Source§

impl VectorGraphExt for Graph

Implementors§