AnswerOrbitDocs
Glossary
Glossary

Cosine similarity

Cosine similarity scores how close two pieces of text are in meaning, using the lists of numbers an AI model turns them into.

Cosine similarity is a way of scoring how close two pieces of text are in meaning. An AI model turns each piece of text into a long list of numbers, called an embedding. Cosine similarity compares two of those lists and gives a score: close to 1 when the texts mean much the same thing, lower the further apart they are.

You'll never calculate it yourself. It's worth knowing because it's one of the ways AI search decides which passages from the web are relevant to a question.

How it works, roughly

Picture each embedding as an arrow pointing in some direction. Texts with similar meaning point in similar directions. Cosine similarity measures the angle between two arrows. A small angle gives a high score.

When a platform searches for passages to answer a question, it can turn the question into an arrow too, and look for passages whose arrows point the same way.

Meaning over matching words

For example, take the question "coffee for a small office." The passage "We deliver beans every week to teams of 10 to 50 people" shares almost no words with it, and still scores high, because it means something close. The passage "Our story began in a garden shed in 2012" scores low, however many times the page says "coffee."

That's why repeating a phrase doesn't help much. What helps is passages that clearly say what they're about and answer the question in plain words.

Where it fits

Cosine similarity is usually the first, fast step. It narrows millions of passages down to a shortlist. A slower, more careful model, such as a cross-encoder, may then reread the shortlist and pick the best few for the answer.

On this page