Three measures, and how they relate
Euclidean distance is the straight line between two points. It is small when the vectors are close in both direction and length.
The dot product grows with both the alignment and the magnitudes, so a long vector scores well against everything.
Cosine similarity divides the magnitudes out and keeps only the angle, which is why it is the default for embeddings.
The identity that makes the choice mostly irrelevant
On normalised vectors, Euclidean distance is a decreasing function of cosine similarity, so both produce exactly the same ranking.
The dot product on normalised vectors is cosine similarity by definition, so all three agree once the lengths are 1.
That is why almost every embedding is normalised at write time: it makes the metric choice free, and it lets the index use the cheapest of the three.
When the magnitude carries meaning
On unnormalised vectors, dot product and cosine can rank results differently.
Some models encode confidence or term frequency in the norm, and normalising discards it.
A recommendation model may use length for popularity, so the dot product deliberately favours popular items and cosine deliberately does not.
The rule is to use the metric the model was trained with. A model trained with a contrastive loss on normalised vectors is being misused under raw Euclidean distance.
The others worth knowing
Manhattan distance sums absolute differences and is less sensitive to a single large deviation than L2, which squares it.
Jaccard works on sets rather than vectors and is the right metric for sparse keyword or n-gram representations.
Hamming distance counts differing bits, which is why binary quantised embeddings are compared with it and why that comparison is so fast.
One choice, in order
- Read what loss the embedding model was trained with.
- If it was trained on normalised vectors, normalise at write time and never again.
- Pick the metric the index implements most efficiently, which is usually the inner product.
- Confirm that the index and the query use the same metric, since a mismatch fails silently and returns plausible nonsense.
- Measure recall against a brute-force scan before trusting any of it.
Above a few hundred dimensions every pair of random points sits at almost the same distance.
The absolute value of a similarity score therefore means very little, and only the ranking is worth reading.