Skip to main content

VectorDistance

Trait VectorDistance 

Source
pub trait VectorDistance {
    // Required methods
    fn dot_product(&self, other: &Self) -> f64;
    fn cosine_similarity(&self, other: &Self, normalized: bool) -> f64;
    fn angular_distance(&self, other: &Self, normalized: bool) -> f64;
    fn euclidean_distance(&self, other: &Self) -> f64;
    fn manhattan_distance(&self, other: &Self) -> f64;
    fn chebyshev_distance(&self, other: &Self) -> f64;
}
Expand description

Similarity and distance metrics for embedding vectors.

Required Methods§

Source

fn dot_product(&self, other: &Self) -> f64

Dot product of two vectors.

Source

fn cosine_similarity(&self, other: &Self, normalized: bool) -> f64

Cosine similarity in [-1, 1].

Pass normalized = true if both vectors are already unit-length (e.g. models like text-embedding-3-small with dimensions set) — this skips the magnitude computation and just returns the dot product.

Source

fn angular_distance(&self, other: &Self, normalized: bool) -> f64

Angular distance in [0, 1] (0 = identical direction).

Source

fn euclidean_distance(&self, other: &Self) -> f64

Euclidean (L2) distance.

Source

fn manhattan_distance(&self, other: &Self) -> f64

Manhattan (L1) distance.

Source

fn chebyshev_distance(&self, other: &Self) -> f64

Chebyshev (L∞) distance — maximum absolute difference across dimensions.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§