What is cosine similarity?
Cosine similarity is a number between negative 1 and 1 that measures how aligned two vectors are. It is the dominant similarity metric in vector search because it ignores magnitude and focuses on direction, which is what semantic embeddings actually encode.
The formula
cosine(a, b) = (a · b) / (||a|| × ||b||). The dot product divided by the product of the magnitudes. A score of 1 means the vectors point the same direction. A score of 0 means they are orthogonal. A score of negative 1 means they point opposite directions.
Why not Euclidean distance
Euclidean distance is affected by vector magnitude. A long vector and a short vector can be far apart in Euclidean space even when they point the same direction. Embeddings are typically normalized to unit length so cosine and Euclidean produce the same ranking, but cosine is the canonical choice.
Interpreting scores
For typical dense semantic embeddings, scores above 0.85 indicate a strong match. Scores between 0.7 and 0.85 are weak. Below 0.7 is essentially unrelated. The exact thresholds depend on the model; tune empirically on your corpus.
See it working on message.com.
Unified inbox, grounded AI, flat pricing. 14 days free, no credit card.
Start free trial →