Cosine similarity ignores length and compares direction. It is the standard way to compare documents (word-count vectors), user preferences in recommendation systems and embeddings in machine learning.
How to use the Cosine Similarity Calculator
- Vector length (dimension)
- a₁
- b₁
- a₂
- b₂
- a₃
- b₃
- a₄
- b₄
- a₅
- b₅
- a₆
- b₆
- a₇
- b₇
- a₈
- b₈
- a₉
- b₉
- a₁₀
- b₁₀
Results update as you type, and everything is calculated in your browser.
How it works
The dot product is divided by the product of the vector lengths. 1 means the same direction, 0 means perpendicular (unrelated) and −1 means opposite.
Inputs explained
| Field | What to enter |
|---|---|
| Vector length (dimension) | Choose one: 2, 3, 4, 5 … |
| a₁ | A number |
| b₁ | A number |
| a₂ | A number |
| b₂ | A number |
| a₃ | A number |
| b₃ | A number |
| a₄ | A number |
| b₄ | A number |
| a₅ | A number |
| b₅ | A number |
| a₆ | A number |
| b₆ | A number |
| a₇ | A number |
| b₇ | A number |
| a₈ | A number |
| b₈ | A number |
| a₉ | A number |
| b₉ | A number |
| a₁₀ | A number |
| b₁₀ | A number |
Example values
How the main result changes when a₁ changes and everything else stays at the example values above:
| a₁ | Cosine similarity S_C |
|---|---|
| 0.5 | 0.356 |
| 0.75 | 0.398 |
| 1 | 0.4385 |
| 1.25 | 0.4772 |
| 1.5 | 0.514 |
| 2 | 0.5813 |
Formula
S_C = (a · b) ÷ (‖a‖ ‖b‖), θ = arccos S_C, D_C = 1 − S_C
Worked example
Inputs — Vector length (dimension): 3; a₁: 1; b₁: 2; a₂: 3; b₂: 1; a₃: 4; b₃: 0.
Results — Cosine similarity S_C = 0.438529; Angle θ between the vectors = 63.9899 °; Cosine distance D_C = 0.561471; Dot product a · b = 5.
Key terms
- Cosine similarity
- The cosine of the angle between two vectors.
Frequently asked questions
What does a cosine similarity of 0 mean?
The vectors are perpendicular – no similarity in direction.
Why ignore vector length?
A long and a short document on the same topic should be similar.
Can cosine similarity be negative?
Yes, down to −1 for opposite directions; with non-negative data (word counts) it stays between 0 and 1.
Is cosine distance a true metric?
Not strictly – it can violate the triangle inequality.