pub enum DistanceMetric {
Euclidean,
Cosine,
DotProduct,
Manhattan,
Chebyshev,
}Expand description
Distance metric for comparing vectors.
Variants§
Euclidean
Euclidean (L2) distance.
Cosine
Cosine distance (1 - cosine similarity).
DotProduct
Dot product (negative, for max similarity).
Manhattan
Manhattan (L1) distance - sum of absolute differences.
Chebyshev
Chebyshev (L∞) distance - maximum absolute difference.
Implementations§
Source§impl DistanceMetric
impl DistanceMetric
Sourcepub fn calculate(&self, a: &[f32], b: &[f32]) -> f32
pub fn calculate(&self, a: &[f32], b: &[f32]) -> f32
Calculate the distance between two vectors using this metric.
Sourcepub fn calculate_with_norms(
&self,
a: &[f32],
b: &[f32],
norm_a: f32,
norm_b: f32,
) -> f32
pub fn calculate_with_norms( &self, a: &[f32], b: &[f32], norm_a: f32, norm_b: f32, ) -> f32
Calculate distance using cached norms (more efficient for repeated queries).
Note: Norms are only used for Cosine distance. For other metrics, the norms are ignored and the standard calculation is performed.
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<'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 From<DistanceMetric> for DistanceMetricSerde
impl From<DistanceMetric> for DistanceMetricSerde
Source§fn from(metric: DistanceMetric) -> Self
fn from(metric: DistanceMetric) -> Self
Converts to this type from the input type.
Source§impl From<DistanceMetricSerde> for DistanceMetric
impl From<DistanceMetricSerde> for DistanceMetric
Source§fn from(metric: DistanceMetricSerde) -> Self
fn from(metric: DistanceMetricSerde) -> Self
Converts to this type from the input type.
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 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