← Lessons

quiz vs the machine

Silver1240

Machine Learning

Dot Product Versus Cosine Similarity

Two ways to compare vectors and when length should or should not matter.

4 min read · core · beat Silver to climb

Comparing vectors

Many models reduce items to vectors and then ask how similar two of them are. The two most common measures are the dot product and cosine similarity, and the difference comes down to whether vector length counts.

The two measures

  • The dot product multiplies matching components and sums them, so it grows with both the alignment of directions and the magnitudes of the vectors
  • Cosine similarity divides the dot product by both lengths, isolating the angle between the vectors and ignoring magnitude entirely

Cosine ranges from minus one to one. Two vectors pointing the same way score one regardless of length, while perpendicular vectors score zero.

Picking one

Use cosine when only meaning or direction matters, as in text embedding search where document length should not dominate. Use the dot product when magnitude carries signal, such as a learned score where larger norms mean more confident or popular items. If you normalize every vector to unit length first, the two measures become identical.

Key idea

The dot product reacts to both direction and magnitude while cosine similarity cares only about angle, and normalizing vectors makes them equivalent.

Check yourself

Answer to earn rating on the learn ladder.

1. What does cosine similarity ignore that the dot product does not?

2. When do dot product and cosine similarity give the same ranking?