Concept guide · Embeddings and vector search
What is the difference between cosine similarity, dot product, and Euclidean distance?
A slower explanation for when the short interview answer is not enough. Start with the intuition, then connect it to the technical idea and the way an interviewer expects you to reason about it.
ML area
Generative AI → Similarity metrics
Interview format
Core · Concept
Question
GENAI-035
Start with the idea
In simple terms
Cosine similarity compares the direction of two vectors, dot product considers direction and magnitude, and Euclidean distance measures straight-line separation. The right metric depends on how the embedding model expects its vectors to be compared.
Make it concrete
If all vectors are normalised to length one, dot product and cosine similarity produce the same ordering. Without normalisation, vector length can change dot-product rankings.
Build the answer
How to reason about it
- 1Check the embedding model’s training and normalisation assumptions.
- 2Understand what signal the chosen metric rewards or ignores.
- 3Benchmark ranking quality and latency on real queries before changing it.
Go one level deeper
The technical explanation
A distance metric is part of the retrieval contract. Cosine is often useful when direction represents meaning and magnitude should not dominate. Dot product can be appropriate when vector magnitude carries signal or when the model was trained for it. Euclidean distance is sensitive to both direction and length. Do not change the metric or normalisation policy during an index migration without measuring ranking changes.
Say this in the interview
Cosine compares vector direction, dot product combines direction and magnitude, and Euclidean distance measures geometric separation. The correct choice depends on how the embedding model is trained and normalised. Use the metric expected by the model and verify it empirically instead of swapping metrics casually.
Keep preparing