Cosine vs Euclidean
When direction matters, and when distance does.
💡 The intuition
Two hikers point their compasses. Cosine similarity only cares which way they point, not how far they've walked. Euclidean distance only cares how far apart their feet are. Two arrows can point the exact same direction yet start miles apart — identical by cosine, distant by Euclid. The ruler you pick decides what “similar” even means.
Cosine similarity
1.000
1 = same direction, 0 = unrelated, −1 = opposite
Euclidean distance
5.000
0 = same point, bigger = farther apart
A tiny worked example
A = [3, 4], B = [6, 8] (B is A doubled)
cosine(A, B) = 1.0 → same direction exactly
euclidean(A, B) = √((3−6)² + (4−8)²) = √25 = 5.0 → far apart
A vs C = [4, 3]: cosine ≈ 0.96, euclidean ≈ 1.414
Free lesson complete
Continue with the complete Core AI Intuitions path.
Pro unlocks the surrounding lessons, runnable practice, and the full build-ready sequence.
Why it matters in AI
- ▸Embedding search usually uses cosine because meaning lives in direction, not length.
- ▸A long document and a short one on the same topic point the same way — cosine catches that.
- ▸Euclidean is sensitive to magnitude, so unnormalized embeddings can mislead it.
- ▸Many systems normalize vectors so cosine and Euclidean rankings agree.
Things people get wrong
✗ Cosine and Euclidean always agree on “closest”.
✓ A and B have cosine 1.0 but distance 5 — they can disagree.
✗ Cosine 1.0 means the vectors are identical.
✓ It means same direction; magnitudes can differ.
✗ Bigger vectors are more similar.
✓ Cosine ignores size entirely — only the angle counts.
Related reading · Knowledge Lab