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 from_sql_name(name: &str) -> Option<Self>
pub fn from_sql_name(name: &str) -> Option<Self>
Parses the metric name from the CREATE INDEX … WITH (metric = '<name>') clause. Case-insensitive. Returns None
for unknown values; the parser surfaces that as a user-visible
error so a typo doesn’t silently fall back to L2.
Sourcepub fn sql_name(self) -> &'static str
pub fn sql_name(self) -> &'static str
The canonical SQL-surface name for this metric. Used when
synthesizing CREATE INDEX SQL back into sqlrite_master.
Sourcepub fn matching_distance_fn(self) -> &'static str
pub fn matching_distance_fn(self) -> &'static str
The vec_distance_* SQL function whose result this metric
orders by. The optimizer’s HNSW shortcut only fires when the
query’s ORDER BY expression names this exact function.
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
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 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 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
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.