Cosine Distance
Cosine similarity measures the cosine of the angle between two vectors, and cosine distance is 1 minus that similarity. We explain the difference between them, that they measure orientation and not magnitude, their use for comparing text embeddings, and a technical caveat: cosine distance is not a metric in the strict sense.
Cosine similarity between two vectors is the cosine of the angle they form; it is computed by dividing their dot product by the product of their magnitudes. It takes values between -1 and 1: it is 1 when the vectors point in the same direction, 0 when they are perpendicular and -1 when they are opposite. Cosine distance is simply 1 minus cosine similarity: it turns a measure of likeness into one of difference.
What it measures
The key is that the cosine measures the orientation of the vectors, not their size. Two parallel vectors have maximum similarity even if their lengths differ greatly, because dividing by the magnitudes cancels any difference in scale. In this it differs from Euclidean distance, which does depend on magnitude.
What it is used for
It is the reference measure for comparing text embeddings—the vectors that encode meaning—in semantic search, retrieval-augmented generation (RAG) and recommendation systems. It is preferred because magnitude should not matter: two documents of very different length can mean the same thing, and the cosine treats them equally, attending only to direction. It is also more robust than the Euclidean in high-dimensional spaces, and on already-normalized vectors it reduces to a simple dot product, very efficient at scale. That choice remains a modeling assumption: cosine alone does not guarantee semantic equivalence or remove high-dimensional problems.
A technical caveat
Cosine distance is not a metric in the strict sense: it does not satisfy the triangle inequality, a property on which some efficient search techniques rely. On normalized vectors, however, ranking by cosine similarity gives the same result as ranking by Euclidean distance. This is a ranking equivalence under L2 normalization, not equality of the numerical values.
This article was produced with artificial intelligence under human editorial oversight.