#[non_exhaustive]pub enum DistanceMetric {
L2,
InnerProduct,
Cosine,
L1,
}Expand description
Vector distance metric supported by pgvector.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
L2
Euclidean distance (L2 norm).
Operator: <->
Range: [0, ∞)
Use when: comparing absolute distances between vectors.
InnerProduct
Negative inner product.
Operator: <#>
Range: (-∞, ∞)
Use when: vectors are normalized and you want maximum inner product.
Note: pgvector returns negative inner product so that smaller = more similar, consistent with the ORDER BY ASC convention.
Cosine
Cosine distance (1 - cosine similarity).
Operator: <=>
Range: [0, 2]
Use when: comparing direction regardless of magnitude.
L1
Manhattan distance (L1 norm).
Operator: <+>
Range: [0, ∞)
Use when: you need L1 distance, often in recommendation systems.
Implementations§
Source§impl DistanceMetric
impl DistanceMetric
Sourcepub fn prefers_normalized(&self) -> bool
pub fn prefers_normalized(&self) -> bool
Whether this metric benefits from normalized vectors.
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<'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 Display for DistanceMetric
impl Display for DistanceMetric
Source§impl Hash for DistanceMetric
impl Hash for DistanceMetric
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