Glossary

Cosine similarity

Cosine similarity scores how closely two embeddings point in the same direction - the standard way semantic search ranks which passages are most relevant to a query.

Cosine similarity is a measure of how closely two vectors point in the same direction. In the context of text search, those vectors are embeddings - numeric representations of meaning - and a high cosine similarity score means two pieces of text are semantically close, regardless of whether they share any words.

Why it matters

When a semantic search system embeds your query and every passage in a document, it needs a way to decide which passages are most relevant. Cosine similarity provides that: it computes the angle between the query vector and each passage vector. Passages that sit close to the query in meaning - expressing the same idea, from different angles - score near 1.0; passages on unrelated topics score near 0.

The intuition is geometric. A passage about "terminating a contract" and a query for "cancelling an agreement" encode similar meanings, so their vectors point roughly the same way through the high-dimensional space embeddings live in. Cosine similarity captures that alignment directly, which is why it's the standard scoring function for vector-based retrieval.

Cosine similarity vs. Euclidean distance

Cosine similarity isn't the only way to compare two vectors - the other common option is Euclidean distance, the straight-line distance you'd measure with a ruler between two points. The two behave differently, and the difference is exactly why embeddings use cosine similarity almost universally.

Cosine similarityEuclidean distance
What it measuresThe angle between two vectors - direction, not magnitudeThe straight-line distance between two points in space
Sensitive to vector lengthNo - a short vector and a long vector pointing the same way score identicallyYes - longer vectors can appear "farther away" even if they mean the same thing
Typical score range-1 to 1 (in practice usually 0 to 1 for text embeddings)0 to unbounded - depends entirely on the scale of the vectors
Best suited forComparing meaning when only direction matters, e.g. text embeddingsComparing points where absolute magnitude is meaningful, e.g. physical coordinates
Standard choice for semantic searchYesRarely - length differences would distort the ranking

The practical reason cosine wins for text: two embeddings can point in nearly the same direction - meaning nearly the same thing - while having different lengths, because embedding models don't guarantee every vector comes out the same magnitude. Cosine similarity ignores length entirely and looks only at direction, so it isn't fooled by that variation. Euclidean distance would be, penalizing a passage for having a "longer" vector even when its meaning is a near-perfect match.

For most retrieval systems, cosine similarity produces a good but imperfect first-pass ranking. That's where reranking comes in: a second-pass model re-scores the top candidates by reading query and passage together, correcting the cases where cosine similarity ranked a topically-adjacent-but-wrong passage ahead of the one that actually answers the question.

Together, cosine similarity and reranking form the relevance backbone that lets a system surface the right passage - and cite the sentence behind the answer. Neither step needs to be perfect on its own; cosine similarity only has to get the right passage into the shortlist, and reranking only has to sort a small shortlist correctly. Splitting the work this way is what makes retrieval both fast (a cheap vector comparison narrows millions of passages down to a handful) and accurate (a slower, smarter model makes the final call on that handful).

Frequently asked questions
It's the standard way to score how relevant a passage is to a search query once both are converted into embeddings. A retrieval system computes the cosine similarity between the query's vector and every passage's vector, then returns the passages with the highest scores as the most relevant.
A score of 1 means the two vectors point in exactly the same direction - as close to identical in meaning as the embedding model can represent. A score of 0 means they're at a right angle: unrelated, with no meaningful overlap in what they express. Real passage-to-query scores usually land somewhere in between, and relative ranking matters more than the raw number.
All terms
Ready when you are

Stop digging. Start asking.

Add Sidenote to your browser, open any page in your wiki, and ask it the question you’ve been Slacking the team about.

7-day Pro trial · No card required · Free plan forever