Cosine similarity
The measure retrieval systems use to score how related two pieces of text are, by comparing the angle between their vectors rather than their distance apart.
In depth
What it really means
Cosine similarity returns a number between -1 and 1. Around 1 means the two texts point the same direction in meaning. Around 0 means unrelated. It uses angle rather than distance so that a short paragraph and a long article about the same thing still score as similar.
You will never calculate one. It is worth knowing because it explains a specific content failure: a section covering four topics averages out into a direction that points at none of them clearly, and therefore scores mediocre against every query.
How it works
- Query and content passage are each converted to vectors.
- The cosine of the angle between the two vectors is computed.
- The result is a similarity score from -1 to 1.
- Passages are ranked by that score and the top ones retrieved.
Pros & cons
Pros
- Length-independent, so a tight 200-word answer competes with a 2,000-word page.
- Cheap to compute at scale, which is why semantic search is viable.
- Rewards focus, which is a fair thing to be rewarded for.
Cons
- It measures topical direction, not correctness or quality.
- Multi-topic sections score poorly against everything.
- Exact terms and numbers are handled badly, which is why keyword matching runs alongside.
Common mistakes
- Assuming longer content scores higher. Length is explicitly factored out.
- Mixing several topics into one section, which blurs its direction.
- Believing a high score means your content is better. It means it is on-topic.
Best practices
- One topic per section, so its vector points somewhere definite.
- Match the vocabulary your buyers use, since their query sets the direction.
- Keep sections tight rather than padding for length.
- Split multi-topic sections into separate headed sections.
FAQs
What is cosine similarity?
A score from -1 to 1 measuring how closely two pieces of text align in meaning, based on the angle between their vectors.
Why use angle instead of distance?
It removes the effect of length, so a short focused answer and a long article on the same topic can score equally. That is why concise content competes fine.
What is a good cosine similarity score?
It depends entirely on the embedding model and the system’s threshold. The number is only meaningful relative to the other candidates in the same retrieval.
Does cosine similarity measure quality?
No. It measures topical alignment only. Quality gets assessed later, at the reranking and reasoning stages.
Keep reading
Related on LymLyt
Beyond LymLyt
Further reading
Want this working on your site?
We build the content behind the term, ranked in search and cited by AI.
Book a 30-min call →