pub enum VectorMetric {
L2,
Cosine,
InnerProduct,
}Expand description
Distance metric for a Vector(n) similarity search (see
docs/design/extensions.md §6/§7, cratestack#163). Maps 1:1 onto
pgvector’s three distance operators and the opclass names used by
@@index([...], opclass: "...") (cratestack#156’s DDL) — but is
never inferred from an index: an index is only ever an optional
access-path speedup, and AC #2 on cratestack#163 requires distance
ordering/filtering to keep working with no vector index present at
all (a plain sequential scan), so callers state the metric
explicitly at the call site. VectorMetric::from_opclass is a
convenience for callers that already know their index’s opclass and
don’t want to duplicate the mapping by hand — it is never called
automatically.
Variants§
L2
Euclidean (L2) distance — operator <->, opclass vector_l2_ops.
Cosine
Cosine distance — operator <=>, opclass vector_cosine_ops.
InnerProduct
Negative inner product — operator <#>, opclass vector_ip_ops.
Implementations§
Source§impl VectorMetric
impl VectorMetric
Sourcepub const fn sql_operator(self) -> &'static str
pub const fn sql_operator(self) -> &'static str
The Postgres operator pgvector registers for this metric.
Sourcepub fn from_opclass(opclass: &str) -> Option<VectorMetric>
pub fn from_opclass(opclass: &str) -> Option<VectorMetric>
Map a pgvector opclass string, as used in @@index([...], opclass: "vector_l2_ops") (cratestack#156), to the metric it
indexes. Returns None for anything that isn’t one of
pgvector’s three recognized vector opclasses (including a
non-vector opclass on an unrelated index).
Trait Implementations§
Source§impl Clone for VectorMetric
impl Clone for VectorMetric
Source§fn clone(&self) -> VectorMetric
fn clone(&self) -> VectorMetric
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 VectorMetric
Source§impl Debug for VectorMetric
impl Debug for VectorMetric
impl Eq for VectorMetric
Source§impl PartialEq for VectorMetric
impl PartialEq for VectorMetric
impl StructuralPartialEq for VectorMetric
Auto Trait Implementations§
impl Freeze for VectorMetric
impl RefUnwindSafe for VectorMetric
impl Send for VectorMetric
impl Sync for VectorMetric
impl Unpin for VectorMetric
impl UnsafeUnpin for VectorMetric
impl UnwindSafe for VectorMetric
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,
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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