Cosine Similarity
A method to measure how close two embeddings are in meaning. It compares the angle between vectors, not their length.
How It Is Calculated
The cosine of the angle between two vectors takes values:
| Value | Meaning |
|---|---|
| 1 | Vectors point in the same direction — most similar |
| 0 | Perpendicular — unrelated |
| −1 | Opposite — opposite meaning |
Why It Works for Text
Embeddings are structured such that phrases close in meaning give vectors pointing roughly in the same direction. The length of the vector depends on the frequency of the word — so the angle is compared, not the length.
Where It Is Used
- semantic search in vector DBs;
- document comparison;
- recommendations.
Other Measures of Closeness
- Euclidean distance — the usual distance between points;
- Dot product (scalar product) — a fast alternative, popular in Qdrant.