Complete the identity: when do dot product and cosine coincide?
Dot product equals cosine exactly when both vectors are L2-normalized to unit length, because the cosine denominator collapses to 1.
Imagine the cosine formula has a fraction with the dot product on top and a 'length stuff' on the bottom. If both vectors have length one, the bottom of the fraction is one times one, which is just one. Dividing by one does nothing, so what is left is exactly the dot product. The whole point of normalization is to make that fraction disappear so the cheap operation (dot product) replaces the expensive one (cosine) at no quality cost.
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 dot product equals cosine identity is one of the most useful one-liners in production retrieval. It collapses two metrics into one when a single condition is met, and that condition is cheap to maintain. The trade is simple: normalize once at index and query time, then run the rest of your retrieval pipeline on the faster dot-product path.
This short deep dive states the identity, derives it from the cosine formula, walks through the production pattern, and ends with the contract you must keep alive for the identity to hold in practice.
The derivation
Starting from cosine
The cosine similarity is:
The numerator is the dot product. The denominator is the product of the L2 norms.
Substituting unit norm
If both vectors are L2-normalized to unit length, ||u|| = ||v|| = 1 and the denominator is 1. The expression simplifies to:
Why this is exact, not approximate
The simplification follows from algebra, not from any approximation. If norms are exactly 1, the cosine and dot product are exactly equal. If norms are exactly c, the dot product equals c² times cosine. This is still a positive monotone transform that preserves rankings, but absolute scores differ.
The practical contract
Normalize at index time, normalize at query time, store normalized, search with dot product. The identity guarantees the results match cosine exactly.
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 L2-normalized vectors by default.
- FAISS IndexFlatIP is the recommended index type for normalized vectors and runs faster than IndexFlatL2.
What an interviewer would ask next. Try answering before peeking at the approach.
QIf two vectors share an arbitrary common norm c (not just 1), does the identity generalize?
Cosine = (u · v) / c^2. Dot product alone is c^2 times cosine, which is a positive monotone transform. So rankings agree even at common norm c, but the absolute scores differ by a factor.
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 the answer as 'unit vectors' without realizing both vectors must share unit norm, not just one of them.
60 second bullets to scan on the way to the call.
The algebraic step that collapses cosine to dot product
Why both vectors must be unit-norm, not just one
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.