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<Self>
pub fn from_opclass(opclass: &str) -> Option<Self>
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 more