Cosine Similarity
Cosine similarity is a measure of how closely two vectors point in the same direction, ignoring how long either vector is — the cosine of the angle between them.
It is computed as the dot product of the two vectors divided by the product of their lengths. That division is the whole idea: it removes magnitude from the comparison so that only orientation remains.
The value falls between −1 and 1. One means the vectors point the same way, zero means they are at right angles and share no direction, and −1 means they point exactly opposite. For text embeddings from most models the observed range is narrower and sits well above zero, because the vectors a single model produces occupy a limited region of the space rather than spreading over all of it.
Ignoring magnitude is what makes it suitable for embeddings. A long passage and a short one about the same subject may produce vectors of noticeably different length while pointing in nearly the same direction, and it is the direction that carries the meaning.
The related quantity cosine distance is conventionally one minus the similarity, converting a score where higher is better into a distance where lower is better.
In practice
Cosine similarity is the default comparison in most retrieval systems, and vector indexes expose it as a selectable metric alongside dot product and Euclidean distance.
Two facts about those alternatives matter more than the formulas.
On unit-length vectors, cosine similarity and dot product are the same number. Normalising a vector means scaling it to length one; once every vector is normalised, the denominator in the cosine formula is one and the division does nothing. Many embedding models emit normalised vectors already, in which case choosing “dot product” and choosing “cosine” produce identical rankings — and dot product is cheaper, since it skips the division.
On unit-length vectors, Euclidean distance ranks identically too. Straight-line distance and angle are monotonically related when all vectors sit on the same sphere, so the ordering of nearest neighbours is the same. The scores differ; the ranking does not.
The consequence is that the metric choice is only consequential when vectors are not normalised. There, dot product rewards long vectors and cosine does not, and the two can disagree about which neighbour is closest. Whether a given model normalises its output is a documented property worth checking, because the answer decides whether the metric setting matters at all.
A mismatch between the metric used to build an index and the metric used to query it produces results that are wrong rather than merely worse, and the symptom — plausible but poor neighbours — looks like ordinary quality trouble.
Commonly confused with
Dot product. The unnormalised numerator: the sum of element-wise products. Sensitive to magnitude as well as direction, so it can rank a long vaguely related vector above a short precisely related one. Equal to cosine similarity only on normalised inputs.
Euclidean distance. Straight-line separation between the two points. A distance, so lower is better — the opposite convention, which is a frequent source of inverted sorts when switching metrics.
Correlation. Statistically related to cosine similarity, and equal to it once each vector has had its own mean subtracted. Embeddings are not usually mean-centred, so the two are not interchangeable here.
Relevance. A similarity score measures resemblance between representations. It does not measure whether one text answers the question asked in the other. High cosine similarity between a query and a chunk is evidence of topical closeness only. See semantic search.
Index recall. How often approximate search finds the true nearest vectors, which is a property of the index, not of the metric. See approximate nearest neighbour.
Usage notes
Scores are not calibrated and do not transfer. A value of 0.82 has no fixed meaning. Different embedding models produce different characteristic ranges, and some compress almost all pairs into a narrow band near the top, so a threshold that separates relevant from irrelevant on one model may accept everything on another. Any cut-off has to be established against a specific model and collection.
Negative values are rare with text embeddings and their absence is normal rather than a sign of trouble. Models are not trained to place unrelated texts in opposition, only apart.
“Cosine distance” is defined inconsistently. One minus similarity is the common convention, but the angle itself, and one minus similarity halved, both appear. When a system reports a distance, whether values near zero mean similar or dissimilar should be confirmed rather than assumed.
Similarity is symmetric; usefulness is not. The measure gives the same value in both directions, while a question and its answer are not equally good matches for one another. Models trained specifically for query-to-passage retrieval encode that asymmetry, and cosine similarity over their output is still the comparison used.