pub enum DistanceMetric {
L2,
Cosine,
Dot,
}Expand description
Distance metric used by the HNSW index. Must match what the
surrounding vec_distance_* SQL function would compute on the same
pair of vectors — otherwise the index probe and the brute-force
fallback would disagree on which rows are “nearest”. See
src/sql/executor.rs’s vec_distance_l2 / _cosine / _dot for
the canonical implementations.
Variants§
Implementations§
Source§impl DistanceMetric
impl DistanceMetric
Sourcepub fn compute(self, a: &[f32], b: &[f32]) -> f32
pub fn compute(self, a: &[f32], b: &[f32]) -> f32
Computes the configured distance between two equal-dimension
vectors. Returns f32::INFINITY for the cosine/zero-magnitude
edge case; HNSW treats infinity as “worst possible candidate” and
will prefer any finite alternative, which matches the SQL-level
behaviour where vec_distance_cosine errors but the optimizer’s
fallback path simply skips the offending row.
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 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 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