pub enum VectorMetric {
SquaredEuclidean,
Cosine,
NegativeInnerProduct,
}Expand description
Distance metric for native dense vectors.
All metrics return a score where lower is better. NegativeInnerProduct
is the max-inner-product-search adapter: vectors with larger dot products
produce smaller, more favorable scores.
Variants§
SquaredEuclidean
Squared Euclidean distance (sum((lhs_i - rhs_i)^2)).
Cosine
Cosine distance (1 - cosine_similarity).
NegativeInnerProduct
Negated dot product (-sum(lhs_i * rhs_i)), lower-is-better MIPS.
Implementations§
Source§impl VectorMetric
impl VectorMetric
Sourcepub fn bind_query(
self,
query: &VectorValue,
) -> CoreResult<VectorMetricQuery<'_>>
pub fn bind_query( self, query: &VectorValue, ) -> CoreResult<VectorMetricQuery<'_>>
Bind this metric to one query vector for repeated candidate scoring.
This precomputes metric-specific query state, such as cosine query norm, so exact scans and ANN traversals do not redo invariant work for every candidate.
§Errors
VectorMetric::Cosine returns CoreError::VectorZeroNorm when the
query has zero magnitude.
Sourcepub fn bind_query_with_squared_norm(
self,
query: &VectorValue,
query_squared_norm: f64,
) -> CoreResult<VectorMetricQuery<'_>>
pub fn bind_query_with_squared_norm( self, query: &VectorValue, query_squared_norm: f64, ) -> CoreResult<VectorMetricQuery<'_>>
Bind this metric to one query vector with a precomputed query squared norm.
When query_squared_norm is the query’s actual squared norm, this is
equivalent to Self::bind_query. It lets ANN indexes cache entry
norms for cosine centroid assignment while preserving the canonical
metric kernels and error behavior. Non-cosine metrics ignore
query_squared_norm.
§Errors
VectorMetric::Cosine returns CoreError::VectorZeroNorm when the
supplied query squared norm is not positive and finite.
Sourcepub fn distance(self, lhs: &VectorValue, rhs: &VectorValue) -> CoreResult<f64>
pub fn distance(self, lhs: &VectorValue, rhs: &VectorValue) -> CoreResult<f64>
Compute this metric for two vectors.
§Errors
Returns CoreError::VectorDimensionMismatch if dimensions differ.
VectorMetric::Cosine also returns CoreError::VectorZeroNorm
when either vector has zero magnitude.
Trait Implementations§
Source§impl Archive for VectorMetric
impl Archive for VectorMetric
Source§type Archived = ArchivedVectorMetric
type Archived = ArchivedVectorMetric
Source§type Resolver = VectorMetricResolver
type Resolver = VectorMetricResolver
Source§fn resolve(
&self,
resolver: <Self as Archive>::Resolver,
out: Place<<Self as Archive>::Archived>,
)
fn resolve( &self, resolver: <Self as Archive>::Resolver, out: Place<<Self as Archive>::Archived>, )
Source§const COPY_OPTIMIZATION: CopyOptimization<Self> = _
const COPY_OPTIMIZATION: CopyOptimization<Self> = _
serialize. Read moreSource§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
Source§impl<'de> Deserialize<'de> for VectorMetric
impl<'de> Deserialize<'de> for VectorMetric
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>,
Source§impl<__D: Fallible + ?Sized> Deserialize<VectorMetric, __D> for Archived<VectorMetric>
impl<__D: Fallible + ?Sized> Deserialize<VectorMetric, __D> for Archived<VectorMetric>
Source§fn deserialize(
&self,
deserializer: &mut __D,
) -> Result<VectorMetric, <__D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut __D, ) -> Result<VectorMetric, <__D as Fallible>::Error>
impl Eq for VectorMetric
Source§impl Hash for VectorMetric
impl Hash for VectorMetric
Source§impl PartialEq for VectorMetric
impl PartialEq for VectorMetric
Source§fn eq(&self, other: &VectorMetric) -> bool
fn eq(&self, other: &VectorMetric) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for VectorMetric
impl Serialize 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> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> ArchiveUnsized for Twhere
T: Archive,
impl<T> ArchiveUnsized for Twhere
T: Archive,
Source§type Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
Archive, it may be
unsized. Read moreSource§fn archived_metadata(
&self,
) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
fn archived_metadata( &self, ) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
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§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.