pub trait VectorDistance {
// Required methods
fn dot_product(&self, other: &Self) -> f64;
fn cosine_similarity(&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;
// Provided method
fn angular_distance(&self, other: &Self, normalized: bool) -> f64 { ... }
}Expand description
Similarity and distance metrics of embedding vectors. Supply equal-length vectors; the embedding implementation pairs only their shared prefix. Unnormalized cosine requires nonzero magnitudes.
Required Methods§
Sourcefn dot_product(&self, other: &Self) -> f64
fn dot_product(&self, other: &Self) -> f64
The dot product.
Sourcefn cosine_similarity(&self, other: &Self, normalized: bool) -> f64
fn cosine_similarity(&self, other: &Self, normalized: bool) -> f64
Cosine similarity, from -1 to 1.
If normalized is true, the vectors are taken as unit length and the
dot product is returned.
Sourcefn euclidean_distance(&self, other: &Self) -> f64
fn euclidean_distance(&self, other: &Self) -> f64
The straight-line (L2) distance.
Sourcefn manhattan_distance(&self, other: &Self) -> f64
fn manhattan_distance(&self, other: &Self) -> f64
The sum of the coordinates’ absolute differences (L1).
Sourcefn chebyshev_distance(&self, other: &Self) -> f64
fn chebyshev_distance(&self, other: &Self) -> f64
The largest absolute difference of a coordinate (L-infinity).
Provided Methods§
Sourcefn angular_distance(&self, other: &Self, normalized: bool) -> f64
fn angular_distance(&self, other: &Self, normalized: bool) -> f64
The angle between the vectors as a fraction of pi, from 0 (same
direction) to 1 (opposite). normalized is as for
Self::cosine_similarity.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".