L2 Distance vs Cosine Similarity: The Hidden Connection
When we talk about comparing vectors, two measures usually come up: L2 Distance (Euclidean distance) and Cosine Similarity.
L2 Distance vs Cosine Similarity: The Hidden Connection
When we talk about comparing vectors, two measures usually come up: L2 Distance (Euclidean distance) and Cosine Similarity.
At first, they look like two very different ideas. One tells us how far apart vectors are, the other tells us how aligned they are. But once we normalize vectors, they turn out to be two sides of the same coin.
L2 Distance (Euclidean Distance)
The Euclidean distance between two vectors A and B is defined as:

It measures the straight-line distance between the two points. If the value is small, the vectors are close; if it’s large, they’re far apart.
Cosine Similarity
Cosine similarity focuses on the angle between two vectors:

If cos(θ)= 1, the vectors point in the same direction.
If cos(θ)= 0, they are orthogonal.
If cos(θ)= -1, they point in opposite directions.
Unlike Euclidean distance, cosine similarity ignores magnitude and only captures orientation.
The Connection After Normalization
Here’s where things get interesting. If we normalize both vectors so that ∥A∥ = ∥B∥ = 1, then they lie on the unit sphere.
In that case, the Euclidean distance formula simplifies to:

This shows that on the unit sphere, Euclidean distance and cosine similarity are directly related. Minimizing one is equivalent to maximizing the other.
Why This Matters
In practice, this connection has important implications:
- In vector databases and search engines (like FAISS, Pinecone, or Milvus), L2 distance is often the default because it is computationally efficient.
- If your embeddings are normalized (which is common in NLP and computer vision), then ranking results by Euclidean distance gives the same ordering as ranking them by cosine similarity.
So, with normalization, the choice between L2 and cosine isn’t about meaning — it’s about convenience.
Takeaway
- Without normalization: L2 distance depends on magnitude, cosine similarity depends on direction.
- With normalization: they describe the same relationship in different ways.
After normalization, every vector is scaled to have length 1. Geometrically, this means all vectors now lie on the surface of a unit circle (in 2D) or a unit sphere (in higher dimensions). On this surface, the only thing that distinguishes one vector from another is the angle between them — which is exactly what cosine similarity measures. This is why, once normalized, cosine similarity and L2 distance become tightly connected: L2 distance on the unit sphere is just another way of capturing angular difference. So the next time you’re deciding between Euclidean distance and cosine similarity, normalize your vectors first. Once you do, both measures will lead you to the same conclusions.
메타데이터
- post_id
- 35c1ae121392
- slug
- l2-distance-vs-cosine-similarity-the-hidden-connection-35c1ae121392
- url
- https://medium.com/@ishankgera.work/l2-distance-vs-cosine-similarity-the-hidden-connection-35c1ae121392
- canonical_url
- https://medium.com/@ishankgera.work/l2-distance-vs-cosine-similarity-the-hidden-connection-35c1ae121392
- author_url
- https://medium.com/@ishankgera.work
- status
- ok
- fetched_at
- 2026-08-02 22:05:46