Skip to main content

CodecDistance

Trait CodecDistance 

Source
pub trait CodecDistance {
    // Required method
    fn distance(&self, a: NodeId, b: NodeId) -> f32;
}
Expand description

Distance abstraction that every dynvec ANN container honours.

The trait is intentionally narrow: a single (NodeId, NodeId) -> f32 score is enough to drive the HNSW pruning heuristics (select_neighbours and shrink_connections). Query-to-node scoring during search is handled by each impl directly because the query’s f32 representation is in scope at that layer. Smaller scores mean closer.

Required Methods§

Source

fn distance(&self, a: NodeId, b: NodeId) -> f32

Score the stored vectors at a and b against each other.

The score is in the metric’s smaller-is-closer convention so the same heap comparator works regardless of the underlying distance.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<const BITS: u8> CodecDistance for TurboHnswIndex<BITS>