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§
Sourcefn dot_product(&self, other: &Self) -> f64
fn dot_product(&self, other: &Self) -> f64
Dot product of two vectors.
Sourcefn cosine_similarity(&self, other: &Self, normalized: bool) -> f64
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.
Sourcefn angular_distance(&self, other: &Self, normalized: bool) -> f64
fn angular_distance(&self, other: &Self, normalized: bool) -> f64
Angular distance in [0, 1] (0 = identical direction).
Sourcefn euclidean_distance(&self, other: &Self) -> f64
fn euclidean_distance(&self, other: &Self) -> f64
Euclidean (L2) distance.
Sourcefn manhattan_distance(&self, other: &Self) -> f64
fn manhattan_distance(&self, other: &Self) -> f64
Manhattan (L1) distance.
Sourcefn chebyshev_distance(&self, other: &Self) -> f64
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".