#[non_exhaustive]pub enum DistanceMetric {
Cosine,
L2,
Dot,
L1,
Hamming,
Jaccard,
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Cosine
L2
Dot
L1
L1 / Manhattan distance (Σ|xᵢ − yᵢ|). Exact/brute-force only — Lance
ANN indexes do not support it, so an L1 column cannot build an ANN index.
Hamming
Hamming distance over binary vectors: the number of differing bits
(Σ popcount(aᵢ ⊕ bᵢ) across u8 lanes). Applies only to
DataType::BinaryVector columns. Exact/brute-force only — Lance ANN
over binary metrics is not wired here.
Jaccard
Jaccard distance over binary vectors: 1 − |A ∩ B| / |A ∪ B| computed
bitwise (two all-zero vectors are defined as distance 0). Applies only
to DataType::BinaryVector columns. Exact/brute-force only — Lance has
no Jaccard ANN.
Implementations§
Source§impl DistanceMetric
impl DistanceMetric
Sourcepub fn compute_distance(&self, a: &[f32], b: &[f32]) -> f32
pub fn compute_distance(&self, a: &[f32], b: &[f32]) -> f32
Computes the distance between two vectors using this metric.
All metrics follow LanceDB conventions so that lower values indicate greater similarity:
- L2: squared Euclidean distance.
- Cosine:
1.0 - cosine_similarity(range [0, 2]). - Dot: negative dot product.
- L1: Manhattan distance (
Σ|xᵢ − yᵢ|).
§Panics
Panics if a and b have different lengths.
Sourcepub fn is_binary(&self) -> bool
pub fn is_binary(&self) -> bool
Returns true if this metric operates on binary vectors (&[u8] lanes)
rather than float vectors — i.e. DistanceMetric::Hamming or
DistanceMetric::Jaccard.
Callers use this to route between DistanceMetric::compute_distance
and DistanceMetric::compute_distance_binary, and to decide that a
column is scored exact/brute-force (binary metrics have no ANN backend).
Sourcepub fn compute_distance_binary(&self, a: &[u8], b: &[u8]) -> f32
pub fn compute_distance_binary(&self, a: &[u8], b: &[u8]) -> f32
Computes the distance between two binary vectors (u8 lanes) using this
metric, following the LanceDB “lower is more similar” convention.
- Hamming: number of differing bits,
Σ popcount(aᵢ ⊕ bᵢ). - Jaccard:
1 − |A ∩ B| / |A ∪ B|computed bitwise; two all-zero vectors are defined as distance0.
§Panics
Panics if a and b have different lengths, or if self is a
float metric (DistanceMetric::L2, Cosine, Dot, or L1) — those
are computed via DistanceMetric::compute_distance.
Trait Implementations§
Source§impl Clone for DistanceMetric
impl Clone for DistanceMetric
Source§fn clone(&self) -> DistanceMetric
fn clone(&self) -> DistanceMetric
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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>,
Source§impl PartialEq for DistanceMetric
impl PartialEq for DistanceMetric
Source§impl Serialize for DistanceMetric
impl Serialize 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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