pub enum DistanceMetric {
Cosine,
L2,
InnerProduct,
}Expand description
Distance metric for vector similarity calculations.
Each metric has a corresponding pgvector operator:
- Cosine:
<=>(most common for text embeddings) - L2:
<->(Euclidean distance) InnerProduct:<#>(dot product, negate for similarity)
Variants§
Cosine
Cosine distance (1 - cosine similarity).
Best for normalized embeddings (OpenAI, most text embeddings).
Operator: <=>
L2
L2 (Euclidean) distance.
Good for image embeddings and when magnitude matters.
Operator: <->
InnerProduct
Inner product (negative for similarity).
Use when embeddings are already normalized and you want max inner product.
Operator: <#>
Implementations§
Source§impl DistanceMetric
impl DistanceMetric
Sourcepub const fn operator(&self) -> &'static str
pub const fn operator(&self) -> &'static str
Get the pgvector operator for this distance metric.
Sourcepub const fn hnsw_ops_class(&self) -> &'static str
pub const fn hnsw_ops_class(&self) -> &'static str
Get the HNSW index operator class.
Sourcepub const fn ivfflat_ops_class(&self) -> &'static str
pub const fn ivfflat_ops_class(&self) -> &'static str
Get the IVFFlat index operator class.
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 Default for DistanceMetric
impl Default for DistanceMetric
Source§fn default() -> DistanceMetric
fn default() -> DistanceMetric
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for DistanceMetric
impl<'de> Deserialize<'de> for DistanceMetric
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for DistanceMetric
impl PartialEq for DistanceMetric
Source§impl Serialize for DistanceMetric
impl Serialize 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
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
Compare self to
key and return true if they are equal.