pub enum DistanceMetric {
Cosine,
Euclidean,
DotProduct,
Manhattan,
}Expand description
Distance metric for vector similarity computation.
Different metrics are suited for different embedding types:
- Cosine: Best for normalized embeddings (most text embeddings)
- Euclidean: Best for raw embeddings where magnitude matters
- DotProduct: Best for maximum inner product search
- Manhattan: Alternative to Euclidean, less sensitive to outliers
Variants§
Cosine
Cosine distance: 1 - cosine_similarity.
Range: [0, 2], where 0 = identical direction, 2 = opposite direction. Best for normalized embeddings (most text/sentence embeddings).
Euclidean
Euclidean (L2) distance: sqrt(sum((a[i] - b[i])^2)).
Range: [0, infinity), where 0 = identical vectors. Best when magnitude matters.
DotProduct
Negative dot product: -sum(a[i] * b[i]).
Returns negative so that smaller = more similar (for min-heap). Best for maximum inner product search (MIPS).
Manhattan
Manhattan (L1) distance: sum(|a[i] - b[i]|).
Range: [0, infinity), where 0 = identical vectors. Less sensitive to outliers than Euclidean.
Implementations§
Source§impl DistanceMetric
impl DistanceMetric
Sourcepub fn from_str(s: &str) -> Option<Self>
pub fn from_str(s: &str) -> Option<Self>
Parses a metric from a string (case-insensitive).
§Examples
use grafeo_core::index::vector::DistanceMetric;
assert_eq!(DistanceMetric::from_str("cosine"), Some(DistanceMetric::Cosine));
assert_eq!(DistanceMetric::from_str("EUCLIDEAN"), Some(DistanceMetric::Euclidean));
assert_eq!(DistanceMetric::from_str("l2"), Some(DistanceMetric::Euclidean));
assert_eq!(DistanceMetric::from_str("invalid"), None);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§fn default() -> DistanceMetric
fn default() -> DistanceMetric
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for DistanceMetric
impl<'de> Deserialize<'de> for DistanceMetric
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Hash for DistanceMetric
impl Hash for DistanceMetric
Source§impl PartialEq for DistanceMetric
impl PartialEq for DistanceMetric
Source§impl Serialize for DistanceMetric
impl Serialize 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 UnsafeUnpin 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§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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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