#[repr(u8)]pub enum DistanceMetric {
Cosine = 0,
DotProduct = 1,
L2 = 2,
}Expand description
Distance metric for vector similarity.
The #[repr(u8)] and explicit discriminants pin the on-disk byte
encoding used by HNSW and quantized-vector segment blobs. Adding a
new variant requires picking the next unused discriminant and
updating Self::from_byte in the same change. See
[[code-must-not-lie]].
Variants§
Cosine = 0
Cosine distance: 1 - cosine_similarity. Lower = more similar.
DotProduct = 1
Negative dot product. Lower = more similar (for pre-normalized vectors).
L2 = 2
Euclidean (L2) distance. Lower = more similar.
Implementations§
Source§impl DistanceMetric
impl DistanceMetric
Sourcepub fn from_byte(byte: u8) -> Self
pub fn from_byte(byte: u8) -> Self
Decode a metric byte written by metric as u8. Panics on unknown
bytes — these mean the segment is corrupted or was written by a
newer Luci version with an unfamiliar metric. Silently mapping
unknown bytes to a default (e.g., L2) would produce wrong recall
and scoring without any signal to the caller.
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 moreimpl Copy for DistanceMetric
Source§impl Debug for DistanceMetric
impl Debug for DistanceMetric
impl Eq for DistanceMetric
Source§impl PartialEq for DistanceMetric
impl PartialEq for DistanceMetric
Source§fn eq(&self, other: &DistanceMetric) -> bool
fn eq(&self, other: &DistanceMetric) -> bool
self and other values to be equal, and is used by ==.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
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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
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>
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