Sistava

What is Cosine Similarity?

Also called Cosine Distance.

Cosine similarity measures the angle between two vectors, producing a value from negative one to one where one means the vectors point in the same direction. It ignores vector length and compares direction only, which is why it is the standard way to compare text embeddings whose magnitude carries little meaning.

The calculation divides the dot product of two vectors by the product of their lengths. Because that division removes magnitude, a short passage and a long passage on the same subject can score as highly similar. The property suits text retrieval, where document length should not by itself determine whether something matches.

When vectors are normalized to unit length, which many embedding services do by default, cosine similarity and inner product become equivalent, and ranking by Euclidean distance produces the same order. This is why vector stores often list several metrics that behave identically on normalized data, and why the choice matters mainly when vectors are not normalized.

In practice, similarity values from text embedding models occupy a narrow range. Unrelated sentences often score well above zero rather than near it, because embeddings share directional structure. What matters is the ordering and the relative gaps between candidates, not the resemblance of a value to an intuitive percentage of sameness.

Cosine similarity captures directional closeness in the embedding space and nothing more. It cannot reliably distinguish a statement from its negation when both share vocabulary and framing, so a passage saying a feature is unsupported may sit close to a query asking whether it is supported. Downstream verification remains necessary.

Key points

In practice

Embeddings for the sentences the invoice was paid and payment for the invoice cleared yield a cosine similarity near 0.9, while the invoice was paid compared with the office is closed on Fridays yields roughly 0.2. A retriever ranking by this measure places the first pair together and pushes the unrelated sentence far down the list.

Related terms

Back to the AI Glossary