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.