Zenaique

Complete the identity: when do dot product and cosine coincide?

Fill in blank·Easy·4.0 · 0·~1 min·Asked atGroqSnapSnorkel Ai·Relevant atHugging Face
Attempt it
For two vectors u and v, cosine similarity equals the dot product u·v exactly when both vectors are , i.e. when ||u|| = ||v|| = .
TL;DR

Dot product equals cosine exactly when both vectors are L2-normalized to unit length, because the cosine denominator collapses to 1.

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

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.

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 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:

cos(u,v)=uvu2v2\cos(u, v) = \frac{u \cdot v}{\|u\|_2 \, \|v\|_2}

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:

cos(u,v)=uvwhen u=v=1\cos(u, v) = u \cdot v \quad \text{when } \|u\| = \|v\| = 1

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.

Why production stacks normalize
Maintaining the invariant
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 L2-normalized vectors by default.
  • FAISS IndexFlatIP is the recommended index type for normalized vectors and runs faster than IndexFlatL2.
Sign in to see more production examples.

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

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.

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 the answer as 'unit vectors' without realizing both vectors must share unit norm, not just one of them.

Sign in to see all red flags and common mistakes.

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

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