pub enum Metric {
L2,
InnerProduct,
Cosine,
}Expand description
Distance metric used to compare query and database vectors.
§Ranking convention
Throughout Slate-ANN, search ranks candidates by an ascending score: smaller means closer. Each metric defines how a raw similarity maps onto that convention, so a single “smaller-is-better” priority queue works for every metric:
| Metric | Score computed by kernels | Smaller = closer? |
|---|---|---|
L2 | squared Euclidean distance | yes (natural) |
InnerProduct | negated inner product (-<a,b>) | yes (negated) |
Cosine | 1 - cosine_similarity | yes |
L2 uses the squared distance to avoid a per-comparison sqrt; the
ordering is identical to true Euclidean distance and the square root can be
applied once to final results if an actual distance is needed.
Variants§
L2
Squared Euclidean (L2) distance.
InnerProduct
Inner (dot) product similarity, scored as its negation.
Cosine
Cosine distance (1 - cosine_similarity).
Implementations§
Trait Implementations§
impl Copy for Metric
Source§impl<'de> Deserialize<'de> for Metric
impl<'de> Deserialize<'de> for Metric
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
impl Eq for Metric
impl StructuralPartialEq for Metric
Auto Trait Implementations§
impl Freeze for Metric
impl RefUnwindSafe for Metric
impl Send for Metric
impl Sync for Metric
impl Unpin for Metric
impl UnsafeUnpin for Metric
impl UnwindSafe for Metric
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