Which distance metric should you use for embedding search - cosine, dot product, or Euclidean - and does the choice actually matter?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Use whatever metric the embedding model was trained with, which for nearly every modern text embedder is cosine similarity. The detail that matters: if vectors are L2-normalized, cosine, dot product and Euclidean all produce the same ranking, because for unit vectors squared Euclidean distance is 2 - 2*cos, a monotone function of cosine. So on normalized vectors the choice is a performance decision, not a quality one, and dot product is cheapest since it skips the norm computation.
Full worked answer
Use whatever metric the embedding model was trained with, which for nearly every modern text embedder is cosine similarity. The detail that matters: if vectors are L2-normalized, cosine, dot product and Euclidean all produce the same ranking, because for unit vectors squared Euclidean distance is 2 - 2*cos, a monotone function of cosine. So on normalized vectors the choice is a performance decision, not a quality one, and dot product is cheapest since it skips the norm computation.
The choice bites when vectors are not normalized. Then dot product rewards magnitude, so a long document with a large-norm vector outranks a short precise one regardless of direction. Cosine strips magnitude out and compares direction only. Most embedding APIs return normalized vectors already, but open-source models vary, so check rather than assume.
import numpy as np
v = v / np.linalg.norm(v, axis=-1, keepdims=True) # then dot == cosine
Two traps I would flag. First, mismatching the index metric and the model: configuring an index for Euclidean while the model was trained for cosine, on unnormalized vectors, silently degrades recall and nobody notices for months. Second, treating the score as a probability. Cosine scores are not calibrated, and many embedders are anisotropic, so even unrelated pairs sit well above zero and pack into a narrow positive band, which means an absolute value like 0.75 tells you little on its own. Threshold on rank, or calibrate a cutoff against a labelled set, and never hardcode 'score > 0.8 means relevant' out of a tutorial.
What a good answer covers
- Use whatever metric the embedding model was trained with, which for nearly every modern text embedder is…
- The detail that matters: if vectors are L2-normalized, cosine, dot product and Euclidean all produce the…
- So on normalized vectors the choice is a performance decision, not a quality one, and dot product is…
- The choice bites when vectors are not normalized
- Then dot product rewards magnitude, so a long document with a large-norm vector outranks a short precise…
Key terms: same ranking
In the glossary: Cosine similarity
Interviewer follow-ups to expect
If your index reports Euclidean distance but your model is cosine-trained, when would you actually see a quality difference?
How would you pick a relevance cutoff for a 'no good answer found' path?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep