Zenaique

Complete the L2 normalization formula

Fill in blank·Easy·4.0 · 0·~1 min·Asked atLabelboxUberZilliz
Attempt it
To L2-normalize a vector v, divide each component by , which produces a vector of length .
TL;DR

Divide each component by the L2 norm (||v||), and the resulting vector has length 1 (the unit-length vector pointing in the same direction).

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

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.

Key concepts

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:

v2=v12+v22++vd2\|v\|_2 = \sqrt{v_1^2 + v_2^2 + \cdots + v_d^2}

This is the same Euclidean distance you would compute from the origin to the tip of the vector.

L2 normalization

v^i=viv2\hat{v}_i = \frac{v_i}{\|v\|_2}

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

python
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
Why the unit-norm invariant pays off
Failure modes and defenses
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

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.
Sign in to see more production examples.

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?
A

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.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Writing 'sum of squares' as the denominator instead of the square root of the sum of squares. The L2 norm is the square root.

Sign in to see all red flags and common mistakes.

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)

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Why is cosine similarity preferred over Euclidean distance for text embeddings?
Flashcard·Easy