Audited 29 Jul 2026·Last updated 28 Oct 2026·5 citations·Tier 2·0 uses

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

Comma-separated numbers — an embedding, a TF-IDF row, a term-count vector, anything. Any length from 2 components upward. Must not be all zeros.
Comma-separated numbers, the same length as vector A. Component 1 of A is compared with component 1 of B, and so on.
Cosine similarity
0.6667
The dot product divided by the product of the two lengths: a number from −1 to 1 measuring how closely the vectors point the same way.
Cosine distance
0.3333
Direction relationship
same general direction — the angle is under 90°
Angle between the vectors
48.1897°
Dot product A·B
4
Norm ‖A‖
2.4495
Norm ‖B‖
2.4495
Components (n)
4

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.

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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‖) , distance = 1 − sim

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.

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.

vector A1, 2, 0, 1
vector B2, 1, 1, 0

Frequently asked questions.

What cosine similarity counts as similar?
It depends on how the vectors were made. Many neural embedding models place almost all of their vectors inside a narrow cone, so even unrelated texts score well above zero, while sparse word-count vectors of related documents can score low because they share few exact words. A cut-off has to be calibrated on pairs you have labelled, using the same model and data.
Why can't I get a negative similarity from word counts?
Counts and TF-IDF weights are never negative, so every term in the dot product is zero or positive and the similarity is confined to 0 through 1. Negative values need components with opposite signs, which dense embeddings routinely have. If counts you believed were raw give a negative result, something upstream has centred or standardised them.
Is cosine similarity the same as Pearson correlation?
No. Pearson's r first subtracts each list's own mean, then computes the cosine of what is left. The default lists show the difference: both have mean 1, the centred lists are 0, 1, −1, 0 and 1, 0, 0, −1, their products sum to zero, so r is exactly 0 while the cosine similarity is 0.6667.
Is cosine distance a true distance?
Not in the strict mathematical sense, because 1 − cos θ can break the triangle inequality. Plenty of clustering and nearest-neighbour code accepts it anyway. If you need a proper metric on directions, divide the angle by 180° (or by π in radians); that angular distance does satisfy the triangle inequality, and the angle is among the outputs.
If my vectors are already normalised, do I need cosine similarity at all?
For vectors of length 1 the denominator is 1, so the plain dot product already is the cosine similarity. Euclidean distance then carries the same information: the squared distance between two unit vectors equals 2 − 2 cos θ, so ranking neighbours by either gives the same order.
When is cosine similarity the wrong tool?
When size itself means something. Two customers whose spending is split identically across categories score 1 even if one spends a hundred times more, and two sensors with the same pattern but very different signal strength look identical. If magnitude matters to your question, compare with Euclidean distance or look at the lengths alongside the similarity.
How can I check the result against another tool?
SciPy's documentation for scipy.spatial.distance.cosine gives worked values: the distance between 1, 0, 0 and 0, 1, 0 is 1, and between 1, 1, 0 and 0, 1, 0 it is about 0.2929, a similarity of about 0.7071 and an angle of 45°. Entering those lists here reproduces them; note that SciPy reports distance, not similarity.

How this page was produced

Published by
Quanta Calculator
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
Coming soon