← Lessons

quiz vs the machine

Gold1400

Machine Learning

The Dot Product Versus Cosine

Two similarity scores that agree only when vectors are normalized.

4 min read · core · beat Gold to climb

The two scores

The dot product multiplies matching components and sums them. Cosine similarity is that same dot product divided by both vector lengths. The key difference is whether magnitude affects the score.

When they differ

The dot product grows with vector length, so a long vector can score high on similarity just by being big, even if its direction is only loosely aligned. Cosine removes that effect and reports pure direction agreement.

  • Use cosine when magnitude is noise and only direction should matter.
  • Use the dot product when magnitude carries real signal, such as confidence or popularity baked into the vector.

The normalization bridge

If you L2 normalize every vector to unit length first, the dot product and cosine similarity become identical. Many vector databases exploit this: they normalize once at index time so a fast dot product search returns cosine ranked results.

Key idea

The dot product is sensitive to magnitude while cosine is not, but once vectors are L2 normalized the two become identical, which is why normalization is a common preprocessing step.

Check yourself

Answer to earn rating on the learn ladder.

1. When do the dot product and cosine similarity give identical rankings?

2. When might you prefer the raw dot product over cosine?