#[non_exhaustive]pub enum DistanceMetric {
Cosine,
L2,
InnerProduct,
Hamming,
Jaccard,
}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 (Non-exhaustive)§
This enum is marked as non-exhaustive
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: <#>
Hamming
Hamming distance — the number of differing bits (#959).
Binary vectors (FieldType::BitVector) only.
Operator: <~>
Jaccard
Jaccard distance — 1 - |intersection| / |union| over set bits (#959).
Binary vectors (FieldType::BitVector) only; unlike hamming it
normalises by how many bits are set, so a sparse near-match beats a
dense one.
Operator: <%>
Implementations§
Trait Implementations§
Source§impl Clone for DistanceMetric
impl Clone for DistanceMetric
impl Copy for DistanceMetric
Source§impl Debug for DistanceMetric
impl Debug for DistanceMetric
Source§impl Default for DistanceMetric
impl Default for DistanceMetric
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>,
impl Eq for DistanceMetric
Source§impl PartialEq for DistanceMetric
impl PartialEq for DistanceMetric
Source§impl Serialize for DistanceMetric
impl Serialize 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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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.