Cosine Similarity Calculator
Find the cosine similarity between two vectors or two texts, in your browser. See the similarity score, the cosine distance, the angle in degrees, and the full dot-product and magnitude working behind every result. No signup, nothing uploaded.
How it works
Cosine similaritymeasures the angle between two vectors while ignoring how long they are. Two vectors that point the same way score 1, vectors at right angles score 0, and vectors pointing in opposite directions score −1. The definition is the one used by scikit-learn and by Manning, Raghavan & Schütze's Introduction to Information Retrieval, Chapter 6.
For two equal-length vectors A = [a₁…aₙ] and B = [b₁…bₙ], the similarity is the dot product divided by the product of the two magnitudes:
cos(A, B) = (A · B) / (‖A‖ · ‖B‖) = Σ aᵢbᵢ / ( √(Σ aᵢ²) · √(Σ bᵢ²) )
The tool computes this in four steps:
- Dot product. Multiply the vectors component by component and add the results:
A · B = Σ aᵢbᵢ. - Magnitudes.Take the square root of each vector's sum of squares:
‖A‖ = √(Σ aᵢ²)and likewise for‖B‖. - Divide. The similarity is
(A·B) / (‖A‖·‖B‖). If either magnitude is zero the vector has no direction, so the result is undefined and the tool shows a clear message instead of a divide-by-zero. - Derive distance and angle. Cosine distance is
1 − similarity, and the angle isarccos(similarity)in degrees, clamping the input to [−1, 1] first to guard against floating-point drift.
Text mode applies the vector-space model from the same IR textbook. Each text is tokenised into words, a shared vocabulary is built from both texts, and every text becomes a raw term-frequency vector — one count per vocabulary word — over that shared vocabulary. Those two vectors are then fed into exactly the steps above. Because both texts are projected onto the same vocabulary, their vectors are always the same length. This version uses raw counts, not TF-IDF weighting, so the working stays transparent; for model-based semantic comparison, the embedding tools linked below go further. As a credibility check, the calculator also computes the similarity a second way — by normalising each vector to unit length and taking the dot product, which is how scikit-learn implements it internally — and confirms the two routes agree.
Worked examples
Frequently asked questions
Sources & references
- scikit-learn — sklearn.metrics.pairwise.cosine_similarity (definition and 1 − similarity distance convention)
- Manning, Raghavan & Schütze — Introduction to Information Retrieval, Ch. 6: the vector space model and cosine measure
The formulas on this page were last cross-checked against these sources on 2026-06-10. Cosine similarity is a stable mathematical definition, so this tool needs no rate or schedule updates — only the worked examples are periodically re-reconciled.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.