शब्दकोश · AI और डेटा

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.

अपडेट: अक्टूबर 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.

यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.