Two vectors can be close in one sense and far apart in another. Choosing a similarity rule is therefore part of the model, not a detail added after the representation is built.
For vectors , Euclidean distance is
It measures the straight-line distance between two points. Cosine similarity is
which is the cosine of the angle between them. It equals for vectors pointing in the same direction, for perpendicular vectors, and for opposite directions.
A ranking disagreement
Let , , and . Cosine similarity ranks above because points in exactly the same direction as :
Euclidean distance gives
so it ranks as closer. Neither answer is automatically wrong. If length records confidence or amount, Euclidean distance may preserve useful information. If length mainly reflects document size, cosine similarity may be more appropriate.
Why normalization connects the two
Normalize each nonzero vector to unit length:
Then
The derivation follows by expanding the squared norm:
Therefore, on unit-normalized vectors, ranking by smallest Euclidean distance is equivalent to ranking by largest cosine similarity. This fact is useful when a search system supports one metric more efficiently than another.
Metric questions
Euclidean distance is a metric: it is nonnegative, symmetric, zero only for identical points, and obeys the triangle inequality. Cosine similarity is a similarity score rather than a distance metric. The quantity is often called cosine distance, but it does not satisfy every metric property in every setting.
That distinction matters when an algorithm relies on the triangle inequality to avoid unnecessary comparisons. It matters less when the system simply scores every candidate.
A useful classroom test
Plot a query point and several candidates in two dimensions. Ask students to predict the Euclidean and cosine rankings before calculating them. Then multiply one candidate by . Its direction stays fixed, so cosine similarity does not change, while Euclidean distance usually changes greatly.
Follow with three questions:
- Should magnitude matter for this data?
- Were the coordinates measured on comparable scales?
- Does the chosen score produce useful neighbors on actual examples?
The final question is decisive. Geometry supplies several reasonable comparisons; evaluation tells us which geometry fits the task.