Cosine Similarity Calculator
Paste two equal-length lists of numbers to get their cosine similarity, cosine distance and the angle between them, with the dot product and both norms.
Cosine Similarity Calculator
Background.
Two documents about the same topic can differ wildly in length. A ten-page report and a one-paragraph summary use the same words in roughly the same proportions, but the report uses each of them far more often, so any measure that simply multiplies word counts together will rate the long report as closer to everything. Cosine similarity fixes that by asking only which way two vectors point. It divides their dot product by the product of their lengths, which leaves the cosine of the angle between them: 1 when they point the same way, 0 when they are at right angles, −1 when they point in opposite directions.
That single idea runs through much of modern search. Manning, Raghavan and Schütze's Introduction to Information Retrieval builds document ranking on it, scikit-learn describes it as the L2-normalised dot product, and nearest-neighbour search over text or image embeddings, including the retrieval step in many question-answering systems, usually ranks candidates by it.
Any two lists of the same length will do, from term counts to TF-IDF weights to rows of an embedding. Alongside the similarity you see the raw dot product and both lengths, which shows how much of the raw overlap was just size.
What you will not get is a verdict on whether your number is high. No textbook or standard defines a cut-off for 'similar', and the scale shifts from one embedding model to the next, so the reading beside the result is geometric only: identical direction, same general direction, orthogonal, opposing or exactly opposite.
What is cosine similarity calculator?
Cosine similarity is the cosine of the angle between two non-zero vectors, obtained from their components without ever measuring the angle: the dot product A·B divided by the product of the Euclidean lengths ‖A‖ and ‖B‖. The Cauchy–Schwarz inequality guarantees |A·B| ≤ ‖A‖‖B‖, so the result always lies between −1 and 1. Scaling either vector by a positive number leaves it unchanged, which is the property that makes it useful for comparing items of very different size.
How to use this calculator.
- Paste the first list into Vector A as numbers separated by commas, for example 1, 2, 0, 1. Spaces or line breaks around the commas and a trailing comma are ignored.
- Paste the second list into Vector B. It needs the same number of components, in the same order: position 3 of A is compared only with position 3 of B, so both must be built over the same vocabulary or feature list.
- Use at least two components and make sure neither list is all zeros; a zero vector has no direction, so the similarity is undefined and an error is shown instead.
- Read the similarity first, then the angle and the direction reading. If your clustering or nearest-neighbour code expects a distance to minimise, use the cosine distance.
- To choose a threshold for your own task, score a few dozen pairs you have already judged as related or unrelated and see where the two groups separate.
The formula.
sim(A, B) = (A·B) ÷ (‖A‖ ‖B‖), where A·B = Σ aᵢbᵢ adds up the products of matching components and ‖A‖ = √(Σ aᵢ²) is the ordinary straight-line length of A. This is Equation 24 in §6.3 of Manning, Raghavan and Schütze, and the same expression scikit-learn documents. It equals cos θ because the dot product can also be written ‖A‖‖B‖ cos θ, the identity proved in OpenStax Calculus Volume 3. The angle is recovered as θ = arccos(sim) and the cosine distance as 1 − sim, the convention SciPy uses. The similarity is computed as the dot product over the square root of the product of the two squared lengths, so proportional lists such as 1, 2, 3 and 2, 4, 6 come out at exactly 1. With non-negative data such as counts every product aᵢbᵢ is at least zero, so the similarity cannot fall below 0 and the angle cannot exceed 90°. The direction reading uses a tolerance of 10⁻¹² around 1, 0 and −1, so floating-point dust does not turn an exact match into 'same general direction'.
A worked example.
Two listeners' play counts are recorded across four genres, in the order jazz, rock, folk and classical. Listener A played 1, 2, 0 and 1 tracks; listener B played 2, 1, 1 and 0. The dot product multiplies matching positions and adds: 1 × 2 + 2 × 1 + 0 × 1 + 1 × 0 = 2 + 2 + 0 + 0 = 4. The lengths are √(1 + 4 + 0 + 1) = √6 and √(4 + 1 + 1 + 0) = √6, each about 2.4495. Their product is exactly 6, so the cosine similarity is 4 ÷ 6 = 0.6667, the cosine distance is 1 − 0.6667 = 0.3333, and the angle is arccos(2/3) = 48.1897°. Because every count is non-negative the result could only land between 0 and 1, and at 0.6667 the reading is 'same general direction', the angle being under 90°. The overlap comes entirely from jazz and rock, which both listeners played; the folk and classical plays, each made by only one of them, add to the lengths but nothing to the dot product, and that is what holds the score below 1.
Frequently asked questions.
What cosine similarity counts as similar?
Why can't I get a negative similarity from word counts?
Is cosine similarity the same as Pearson correlation?
Is cosine distance a true distance?
If my vectors are already normalised, do I need cosine similarity at all?
When is cosine similarity the wrong tool?
How can I check the result against another tool?
References& sources.
- [1]Manning, C.D., Raghavan, P. & Schütze, H. (2008). Introduction to Information Retrieval. Cambridge University Press, §6.3 ‘Dot products’, Equation (24): sim(d₁,d₂) = V(d₁)·V(d₂)/(|V(d₁)||V(d₂)|). Retrieved 2026-07-29 from the authors' free HTML edition.
- [2]scikit-learn developers, User Guide — ‘Pairwise metrics, Affinities and Kernels’, §‘Cosine similarity’ (stable channel, retrieved 2026-07-29): k(x, y) = x yᵀ ⁄ (‖x‖‖y‖), described as the L2-normalized dot product, with the tf-idf use case noted.
- [3]OpenStax, Calculus Volume 3 (2016 ed.), §2.3 ‘The Dot Product’, Theorem 2.4 — u·v = ‖u‖‖v‖cos θ, which establishes that the normalised dot product computed here is exactly the cosine of the angle between the vectors.
- [4]Wolfram Research, MathWorld — ‘Dot Product’ (live revision retrieved 2026-07-29), Equation 1 (X·Y = |X||Y|cos θ) and Equations 8–10 (component form Σxᵢyᵢ), the two forms this page reconciles.
- [5]SciPy developers, scipy.spatial.distance.cosine reference documentation (retrieved 2026-07-29) — defines cosine distance as 1 − (u·v)/(‖u‖₂‖v‖₂) and publishes the docstring examples 1.0, 1.0 and 0.29289321881345254. Used as the independent cross-check for this page; all three values are reproduced to 10 decimal places.
How this page was produced
- Published by
- Quanta Calculator
- Overseen by
- Daniel, Quanta Calculator Researcher
- Primary sources
- 5 cited below
- Method
- sim(A, B) = (A·B) ⁄ (‖A‖ ‖B‖) , distance = 1 − sim
- Published
- Last verified
Built with AI assistance and verified by automated tests against the cited sources — every worked example on this page is computed by the same code that runs the calculator. How we build and check calculators.
In this category
Embed
Quanta Pro
Paid features are coming later.
- All 1560 calculators remain free
- No billing is enabled