Divide each component by the L2 norm (||v||), and the resulting vector has length 1 (the unit-length vector pointing in the same direction).
Imagine you measured the height of an arrow with a ruler. To make all your arrows the same length, divide each one's coordinates by that ruler reading. Whatever the original length was, the new length is exactly one unit. The direction does not change; only the length does. Now every arrow lives on the same circle and is easy to compare with the others.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
The L2 normalization formula is one of the smallest operations in linear algebra and one of the most important contracts in production retrieval. The whole reason embedding stacks can search billions of vectors with millisecond latency is that they have committed to keeping every vector on the unit sphere.
This short deep dive walks through the formula, a numerical example, the production payoff, and the failure modes that come from forgetting to guard the zero-vector edge case.
The formula and a worked example
The L2 norm
For a vector v = (v_1, v_2, ..., v_d), the L2 norm is:
This is the same Euclidean distance you would compute from the origin to the tip of the vector.
L2 normalization
Apply this to every component. The result has length 1.
Worked example
v = (3, 4, 0)
- L2 norm: sqrt(9 + 16 + 0) = sqrt(25) = 5
- Normalized: (3/5, 4/5, 0) = (0.6, 0.8, 0)
- Check: sqrt(0.36 + 0.64 + 0) = sqrt(1.0) = 1.0 ✓
The direction of (3, 4, 0) is preserved; only the magnitude changed.
What this looks like in code
import numpy as np
def l2_normalize(v):
n = np.linalg.norm(v)
if n < 1e-12:
raise ValueError('cannot normalize zero vector')
return v / n
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- OpenAI text-embedding-3 returns vectors with ||v|| ≈ 1 to 1e-6 tolerance.
- BGE-M3 normalize_embeddings=True is the recommended call site for retrieval.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy is the L2 norm the natural choice for normalizing embeddings vs L1 or L-infinity?
L2 is rotation-invariant, plays nicely with dot products (which is how attention and similarity scoring work), and produces a sphere geometry that ANN indexes are optimized for. L1 produces a hyper-octahedron geometry that is less suited to inner-product search.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Writing 'sum of squares' as the denominator instead of the square root of the sum of squares. The L2 norm is the square root.
60 second bullets to scan on the way to the call.
Formula for the L2 norm of a vector
Formula for L2 normalization (component-wise divide)
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.