Glossary · AI & Data

Cosine Similarity

Cosine similarity measures how alike two vectors are by the cosine of the angle between them, ranging from -1 to 1 regardless of vector length.

Updated October 6, 2026

Cosine similarity is a measure of how similar two vectors are, calculated as their dot product divided by the product of their lengths. It depends on direction, not magnitude: vectors pointing the same way score 1, perpendicular vectors score 0 and opposite vectors score -1.

Why it matters

It is the standard way to compare embeddings in semantic search, recommendation and retrieval-augmented generation. Because it ignores length, a short and a long document about the same topic can still match. Many vector databases offer it as a distance option, and if vectors are normalised to length 1, cosine similarity equals the dot product, which is faster to compute.

Example

a = [1, 2, 3]    b = [2, 4, 6]    c = [3, 0, -1]
cos(a, b) = (2+8+18) / (3.742 * 7.483) = 1.0   (same direction)
cos(a, c) = (3+0-3) / (3.742 * 3.162) = 0.0   (unrelated)

Common mistakes

  • Treating a score as a universal threshold. A "good" value such as 0.8 depends on the embedding model.
  • Using it on vectors from different embedding models, whose spaces are not comparable.
  • Confusing similarity with distance: cosine distance is usually 1 minus the similarity.

Get notified when this term updates

Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.

This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.