25 November 2026 · 3 min readInteractive 3D
What is cosine similarity? How alike two things are
Search engines, recommendations and chatbots all ask “how similar are these?” The answer is an angle. See it between words in 3D.
If two things are described by lists of numbers, how do you measure how alike they are? One popular answer ignores how long the lists are and looks only at the direction they point. That measure is cosine similarity.
The recipe
- Take the dot product: multiply matching numbers and add.
- Divide by the length of each list.
- The result is the cosine of the angle between the two arrows.
- 1 means pointing exactly the same way: very similar.
- 0 means at right angles: unrelated.
- −1 means pointing opposite ways.
Why direction and not distance?
Two documents about cricket might be very different lengths. A long one has bigger numbers everywhere, so it sits far from a short one. But both point in the same direction, towards “cricket”. Cosine similarity sees that they are about the same thing.
When you search for something online, your question is often turned into an embedding, and the results are the pages whose embeddings have the highest cosine similarity to it.
A worked example
Two students rate three films out of 5. Asha gives [5, 1, 4] and Ben gives [4, 2, 5]. How similar is their taste?
- Dot product: 5×4 + 1×2 + 4×5 = 42
- Length of Asha’s list: √(25 + 1 + 16) = √42 ≈ 6.48
- Length of Ben’s list: √(16 + 4 + 25) = √45 ≈ 6.71
- Cosine similarity = 42 ÷ (6.48 × 6.71) ≈ 0.97, very similar
Reading the number
- 1: exactly the same direction (same taste, maybe stronger).
- 0: unrelated (at right angles).
- −1: opposite (one loves what the other hates).
Ratings that are all positive can never point in opposite directions, so in practice values sit between 0 and 1. Centring the ratings (subtracting each person’s average) lets disagreement show up as negative values.
Why not just use distance?
A long article and a short summary about the same topic can be far apart in distance, simply because the long one has bigger word counts. Their directions are almost the same, so cosine similarity correctly calls them alike. That is why search engines and recommendation systems use it.
Cosine similarity = dot product ÷ (length × length). It is the cosine of the angle between the two arrows.
Search with embeddings
A modern search system stores an embedding for every document. When you search, your query becomes an embedding and the system returns the documents with the highest cosine similarity. Special databases called vector databases make this fast across millions of documents.
Glossary
- Cosine: the trigonometric ratio linked to the angle between arrows.
- Normalise: scale a vector to length 1.
- Vector database: storage designed for fast similarity search.
Try these yourself
- Q1. [1, 0] and [0, 1]: 0, unrelated
- Q2. [2, 2] and [5, 5]: 1, same direction
- Q3. [1, 2] and [−1, −2]: −1, opposite
- Q4. [3, 4] and [4, 3]: 24 ÷ 25 = 0.96
Common mistakes
- Forgetting to divide by both lengths.
- Thinking a high score means equal size; it only means the same direction.
- Comparing vectors made by different models; their numbers do not match up.
In short
Cosine similarity compares direction, not size, so it measures how alike two things are regardless of scale. It is the backbone of search and recommendations.
Keep going
Questions people ask
What is cosine similarity used for?
Comparing documents, words, songs or users by the direction of their number lists, regardless of size. It is central to search and recommendations.
What is a good cosine similarity score?
It depends on the data, but values above about 0.8 usually mean very similar, and values near 0 mean unrelated.
How is cosine similarity calculated?
Divide the dot product of the two vectors by the product of their lengths.