Interview Q&A / AI & Generative AI

IntermediateQuick answer1 min readUpdated 3 Oct 2026

What is the difference between cosine similarity, dot product and Euclidean distance for vectors?

SHORT ANSWER

Cosine similarity compares only direction, dot product mixes direction and length, and Euclidean distance measures straight-line gap. For normalised vectors, cosine and dot product give the same ranking, and Euclidean distance ranks the same way too.

Explain it simply

Two arrows on a floor. Cosine similarity asks how closely they point the same way, ignoring how long they are. Dot product also rewards length, so a long arrow scores higher. Euclidean distance asks how far apart the arrow tips are.

For text embeddings, direction usually carries the meaning, which is why cosine is the common default. If an embedding model outputs vectors scaled to length 1, the dot product equals cosine, and ranking by smallest Euclidean distance gives the same order as ranking by highest cosine. That is why many vector databases let you pick any of them once vectors are normalised.

Use the metric your embedding model was trained with. A mismatch can quietly hurt ranking.

Example

python
a = [1, 0]
b = [2, 0]      # same direction as a, twice as long
c = [0, 1]      # different direction

# cosine(a, b) = 1.0   cosine(a, c) = 0.0
# dot(a, b)    = 2     dot(a, c)    = 0
# euclid(a, b) = 1.0   euclid(a, c) = 1.414...

Note that a and b are "far" by Euclidean distance although they point the same way.

What to say in the interview

"Cosine compares angle, dot product depends on magnitude too, and Euclidean measures absolute distance. With normalised embeddings they agree on ranking. I follow the metric the embedding model recommends and keep it consistent between indexing and querying."

#embeddings#vectors#similarity

Related questions

Practise more AI & Generative AI questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open AI & Generative AI quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.