Cosine, dot product or normalization: which similarity metric should retrieval actually use
Start with what you observe: same chunking, same prompt, only the embedding model changed from A to B (and B scores higher on MTEB). The top-3 retrieved chunks are completely different, and answer quality drops. Most people then tune chunk size or add a reranker, when what actually changed may just be the similarity basis: whether the new model's vectors are normalized, and whether the vector store is still scoring by raw inner product.
This article answers one question: how cosine, inner product and normalization relate, when they are interchangeable, and when switching one is equivalent to replacing the entire ranking.
The one-paragraph answer
Cosine similarity is simply the inner product after normalization. Inner product counts vector length in the score; cosine divides it out. The two rankings agree only when every vector being compared has the same length (or has already been normalized). Once lengths vary, inner product starts preferring the "longer" vector, while cosine looks only at direction.
Three bases, one hand-checkable example
Take query q = (1, 0), candidates A = (3, 3) and B = (2.2, 0):
| Candidate | Inner product q·x | Cosine cos(q, x) |
|---|---|---|
| A = (3, 3) | 3.00 | 0.7071 |
| B = (2.2, 0) | 2.20 | 1.0000 |
By inner product, A ranks first (3.00 > 2.20); by cosine, B ranks first (1.0000 > 0.7071). A is longer but 45° off; B is shorter but exactly aligned — that is the whole meaning of "length enters the ranking", reproducible with two steps of arithmetic and no model at all.
One more equivalence is worth memorizing: once vectors are normalized, L2 distance and inner product produce the same ranking, because |x − y|² = 2 − 2⟨x, y⟩ (wording from the FAISS docs). So cosine, normalized inner product and normalized Euclidean distance all rank identically; the only variable that can diverge is unnormalized inner product.
Each system's default: do not mistake a library's behavior for common knowledge
| System | Default / recommendation | Normalizes for you? | What it means in practice |
|---|---|---|---|
| OpenAI Embeddings | Cosine recommended; the docs say "the choice of distance function typically doesn't matter much" | Yes — the docs state embeddings "are normalized to length 1" | Cosine, dot product and Euclidean distance give identical rankings |
| FAISS | METRIC_INNER_PRODUCT or METRIC_L2 | No — you call normalize_L2 yourself | Under inner product the query's norm does not affect the ranking, but system vectors' norms do; the docs prescribe cosine as: normalize, then use an IP index |
| Qdrant | Cosine / Dot / Euclid | Cosine normalizes at upload time | Choosing Cosine removes length from the score; Dot keeps it |
| sentence-transformers | Cosine is the default | Depends on whether the model ends with a Normalize module | If the model already normalizes, switch to DOT: dot on normalized vectors equals cosine, and cosine would re-normalize once more |
The line worth remembering: OpenAI's "pick anything" holds because it already normalized for you. The same advice breaks on a self-hosted open model or on FAISS, where nobody normalizes on your behalf. The subtler case is a store like Qdrant: with Cosine it normalizes at upload, with Dot it does not — the same vectors in two collections can score differently.
Cosine is not automatically "more semantic"
A common claim is that cosine "focuses on semantic direction". Steck et al. (WWW 2024 Companion) provide a counterexample: for regularized linear models, cosine similarity can be analytically shown to produce arbitrary, and therefore meaningless, similarities; for some models the similarities are not even unique, while for others they are implicitly controlled by the regularization. In practice cosine works better than unnormalized dot product in some cases and worse in others. The authors caution against blindly defaulting to cosine.
The engineering implication is direct: do not choose a similarity metric by which one sounds more semantic. It is a configuration item that belongs in evaluation, just like chunk size or the reranker, and it should be decided on your own query set.
Three steps to pin the basis down
- Measure vector lengths first: sample 20–50 real texts and print the p5 / p50 / p95 of
||v||. If they all sit near 1.0 (say 0.99–1.01), the model already normalizes and cosine is equivalent to inner product — stop agonizing. If the spread runs from 0.6 to 1.5, the choice is a real decision. - Align the store configuration: model already normalized + Cosine in the store means normalizing twice (one extra computation, same result); model not normalized + Dot in the store means length participates in ranking. Neither combination errors out; both merely let results drift.
- Run an A/B on a labeled set: fix the model, chunking and top-k, change only the metric, compare recall@5 and final answer accuracy on at least 50–100 queries. Without those numbers, any claim that cosine is better is just an impression.
Closing
A similarity metric is not a matter of taste; it is a switch: does length get to participate in the ranking. OpenAI turns it off for you, FAISS hands you the switch, and Qdrant's answer depends on the option you picked when creating the collection. When rankings jump after a model swap, check that switch before questioning the model's capability — it costs far less time.