Trait DistanceMetric

Source
pub trait DistanceMetric: Send + Sync {
    // Required methods
    fn distance(&self, a: &[f32], b: &[f32]) -> f32;
    fn name(&self) -> &str;
}
Expand description

A distance metric over vectors.

Implementations must satisfy metric properties:

  • Non-negativity: $d(a, b) \geq 0$
  • Identity: $d(a, a) = 0$
  • Symmetry: $d(a, b) = d(b, a)$

Triangle inequality is desired but not required (cosine distance violates it).

Required Methods§

Source

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

Compute the distance between two vectors.

§Panics

Implementations should panic if a.len() != b.len().

Source

fn name(&self) -> &str

Human-readable name of this metric (e.g., "cosine", "l2").

Implementors§