Mathematical intuition
How vector length changes dot product and cosine similarity
Dot product vs cosine similarity, explained visually. See how vector length changes a similarity score, with a worked example and the normalization formula.
In this article
a = (3, 1) and b = (1, 3). Their dot product is 6; their cosine similarity is 0.6.
Illustrative vectors; values calculated from the coordinates shown.A vector can get twice as long without changing its direction. Should that make it twice as similar to another vector?
Your answer determines which comparison you want. The dot product keeps vector magnitude in the score. Cosine similarity divides it out. They are closely related operations that answer different questions.
That distinction matters when you compare embeddings, build a nearest-neighbor search, or try to understand what a model means by “similar.” We can see it with two small vectors and one change.
Start with two vectors
Let and . Think of the entries as coordinates: three units right and one up for ; one right and three up for .
Their dot product multiplies matching entries and adds the results:
This is the one-dimensional dot product in NumPy’s terminology: the inputs are arrays of scalar entries. Geometrically, our two-entry arrays describe vectors in a two-dimensional plane.
The angle between these arrows is the part of the relationship we want to isolate. To do that, first work out their lengths:
Cosine similarity is their dot product divided by the product of those lengths:
Both scores describe the same pair. The numbers differ because one includes the lengths and the other removes them.
Change the length, keep the direction
Now replace with . Every coordinate doubles. The arrow points the same way and reaches twice as far.
Scaling b to 2b doubles its dot product with a, while cosine similarity stays at 0.6.
Illustrative vectors; values calculated from the coordinates shown.The new dot product is . It doubled. But the denominator in cosine similarity doubled too: .
| Comparison | Dot product | Cosine similarity |
|---|---|---|
| with | 6 | 0.6 |
| with | 12 | 0.6 |
This is a useful diagnostic question for a similarity system: if the candidate vector grows without turning, should its score change? A dot product says yes. Cosine similarity says no, provided the scaling is positive and both vectors are nonzero.
Where the angle enters
For real, nonzero vectors, the dot product has a geometric form:
The formula has three ingredients: the length of , the length of , and the cosine of their angle. Dividing by the two lengths leaves just .
That gives cosine similarity an interpretable range. A value of 1 means the vectors point in exactly the same direction; 0 means they are perpendicular; −1 means opposite directions. A negative score is possible when the coordinates allow it. It is not a negative probability.
Our value of 0.6 tells us about an angle. It does not mean “60% likely to be relevant,” nor does it say that two texts share 60% of their meaning. Interpreting relevance still depends on the embedding model and the task.
Normalization connects the two
You can separate length from direction before comparing vectors. Divide a nonzero vector by its own length to make a unit vector:
Taking the dot product of these normalized vectors gives:
This is why scikit-learn describes cosine similarity as a normalized dot product. Once both inputs have unit length, the two calculations give the same score, apart from numerical rounding.
Normalization makes a specific tradeoff: it deliberately removes magnitude from this comparison. It does not automatically improve an embedding or make every retrieval system more accurate.
Which one should an embedding search use?
Start with the model’s documentation and training setup. Use the similarity measure the model is intended to support, and evaluate it on examples that represent your retrieval task.
Then check what is actually stored. Some pipelines store unit vectors. Others store vectors with different lengths. Two implementations can have similar names while applying normalization at different stages.
For a fixed nonzero query, if every candidate has the same positive length, dot product and cosine similarity produce the same ranking. The denominator then differs only by a common positive factor. If candidate lengths vary, the rankings can differ.
That is a narrower and more useful statement than “cosine is always better.” The correct choice depends on whether magnitude is meaningful to the model and whether your system preserves it.
Try the distinction yourself
Suppose you multiply by 5 while leaving unchanged. Before calculating, predict what happens to each score.
Show the answer
The dot product becomes . The cosine similarity stays at 0.6: multiplying by a positive constant multiplies both the numerator and its length in the denominator by that constant.
If you multiply by a negative constant, the arrow reverses direction. In that case, the cosine similarity changes sign.
If this feels clear, the next step is to work through the normalization lesson. If the geometric identity still feels mysterious, return to the dot product and connect the coordinate calculation to the arrows.
The distinction to keep is small: direction is one part of a vector. Length is another. A similarity score decides how much of each to retain.
Check the reasoning
Sources & notes
- scikit-learn: cosine_similarity ↗
Defines cosine similarity as the normalized dot product and describes its relationship to the linear kernel on normalized data.
- NumPy: dot ↗
Defines the dot product for one-dimensional arrays.
Our figures use illustrative mathematical examples unless a dataset is explicitly identified. You can share the original Glacius figures with attribution and a link to this article; linked third-party material retains its own terms.
Make the connection
Practice these concepts
- Dot productsCompute the dot product of two equal-length vectors.
- Cosine similarityCompute directional similarity for two nonzero vectors.
- Unit vectorsNormalize a nonzero vector to unit length.
- Embedding similarityInterpret a supplied embedding ranking within its stated representation.