pub enum DistanceMetric {
Cosine,
Euclidean,
DotProduct,
Manhattan,
}Expand description
Distance metrics supported by HNSW index
Different distance metrics are appropriate for different types of vector data and use cases. The choice affects both search quality and performance.
§Variants
Cosine- Cosine similarity, ideal for normalized vectors and text embeddingsEuclidean- L2 distance, suitable for general-purpose similarityDotProduct- Raw dot product, fast for normalized vectorsManhattan- L1 distance, robust to outliers
§Performance Characteristics
| Metric | SIMD Support | Typical Use Case | Normalization Required |
|---|---|---|---|
| Cosine | Yes | Text embeddings | Recommended |
| Euclidean | Yes | General similarity | Optional |
| DotProduct | Yes | Fast approximate cosine | Required |
| Manhattan | Yes | Robust similarity | Optional |
Variants§
Cosine
Cosine similarity (1 - normalized dot product) Range: [0, 2] where 0 = identical, 2 = opposite
Euclidean
Euclidean (L2) distance Range: [0, ∞) where 0 = identical
DotProduct
Dot product similarity Range: (-∞, ∞), higher values indicate greater similarity
Manhattan
Manhattan (L1) distance Range: [0, ∞) where 0 = identical
Implementations§
Trait Implementations§
Source§impl Clone for DistanceMetric
impl Clone for DistanceMetric
Source§fn clone(&self) -> DistanceMetric
fn clone(&self) -> DistanceMetric
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DistanceMetric
impl Debug for DistanceMetric
Source§impl Default for DistanceMetric
impl Default for DistanceMetric
Source§impl Display for DistanceMetric
impl Display for DistanceMetric
Source§impl PartialEq for DistanceMetric
impl PartialEq for DistanceMetric
impl Copy for DistanceMetric
impl Eq for DistanceMetric
impl StructuralPartialEq for DistanceMetric
Auto Trait Implementations§
impl Freeze for DistanceMetric
impl RefUnwindSafe for DistanceMetric
impl Send for DistanceMetric
impl Sync for DistanceMetric
impl Unpin for DistanceMetric
impl UnwindSafe for DistanceMetric
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more