Dot Product vs Cosine Similarity
Two ways to score "how similar", and they disagree the moment length stops being constant. Which one your embedding model was trained for is not optional trivia.
Stretch Doc B
same direction as before, just longer — like a verbose, repetitive document embedding
Rank By
Query: "lightweight training method"
—The Space, 2D For Clarity
Both Scores
Dot Product vs Cosine: A Practical Guide
The same two vectors, two different questions asked of them.
Quick Context
Cosine similarity asks "what angle apart are these two vectors" and ignores length entirely. Dot product asks "how much do these two vectors agree, weighted by how long they both are" — length is part of the answer, not discarded. Most embedding search defaults to cosine, but a growing number of models (some recommendation embeddings, some matryoshka and MIPS-optimised models) are trained so that dot product is the correct similarity, and using cosine on them silently under-uses the model.
The formulas
dot(a,b) = Σ aᵢbᵢ cos(a,b) = dot(a,b) / (‖a‖ ‖b‖)
Cosine is the dot product after dividing out both vectors' lengths — which is exactly why stretching one vector along its own direction changes its dot product with anything but never changes its cosine with anything.
Interactive Exploration Guide
- Start at 1x with cosine ranking. Doc A, the concise on-topic passage, ranks first.
- Stretch Doc B to 5x. Under cosine, nothing about the ranking moves — Doc B's direction, and therefore its angle to the query, never changed.
- Switch to dot product and stretch again. Somewhere around 3-4x, Doc B overtakes Doc A — purely because it got longer, with its actual topical relevance unchanged.
- Read both scores side by side at 5x. Cosine still ranks Doc A first; dot product now ranks Doc B first. Same embeddings, same query, opposite answer.
Which one is "right"?
Neither, in the abstract — it depends on what the embedding model was trained to make meaningful. If length in your model's embeddings correlates with noise (document verbosity, padding, repetition), cosine is safer. If length was trained to carry real signal (popularity, confidence, specificity), dot product is the metric the model actually optimised for, and cosine throws that signal away. Check your model's documentation; do not assume.
Key Takeaway
Cosine similarity divides out vector length and only ever measures direction; dot product does not, so it rewards longer vectors regardless of whether that length means anything. The two metrics agree only when every vector has the same length — true if you normalise your embeddings to unit length, false otherwise. Know which one your embedding model was trained against, because using the wrong one is a silent, hard-to-debug retrieval quality bug.