Skip to main content

Similarity metrics

A similarity metric (or distance metric) is the rule Ahnlich uses to decide how close two vectors are during a similarity search. You pick the metric per query via the algorithm field.

θ (cosine)distanceAB
Cosine compares the angle θ; Euclidean compares the distance between the tips.

The metrics

MetricMeasuresGood when
Cosine similaritythe angle between vectors (ignores magnitude)text/semantic embeddings, where direction matters more than length
Euclidean distancethe straight-line distance between pointsvectors where magnitude is meaningful (e.g. spatial data)
Dot productangle and magnitude togetherwhen larger vectors should score higher (some recommender setups)

Choosing one

  • Start with cosine similarity for embeddings from language or vision models — it's the most common default and is unaffected by vector length.
  • Use Euclidean when the absolute position of a vector carries meaning.
  • Use dot product when your model was trained to encode relevance in the vector's magnitude.

The metric only affects ranking — it doesn't change what's stored, so you can issue different queries against the same store with different metrics.