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

Cosine Similarity Calculator

Cosine similarity between two vectors of any length. Paste two comma-separated lists and get the similarity, cosine distance, the angle 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
(A·B) ⁄ (‖A‖‖B‖), always in [−1, 1]. There is no universal threshold for 'similar' — a 0.8 that means near-duplicate under one embedding model is unremarkable under another, so calibrate against your own labelled pairs rather than a rule of thumb.
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.

The Quanta cosine similarity calculator compares the direction of two vectors of any length, ignoring how long they are. Paste two comma-separated lists of the same length — text embeddings, TF-IDF rows, term counts, user-item ratings, anything numeric — and it returns the cosine similarity, the cosine distance, the angle between the vectors in degrees, the raw dot product, both Euclidean norms, and the number of components it read. With the default lists A = 1, 2, 0, 1 and B = 2, 1, 1, 0 the calculator returns a dot product of 4, norms of √6 each, and a cosine similarity of 0.6666666667, which corresponds to an angle of 48.1896851042°.

Cosine similarity is the standard similarity measure in information retrieval and in almost every system built on text or image embeddings. Manning, Raghavan and Schütze define it in Introduction to Information Retrieval as the dot product of two document vectors divided by the product of their Euclidean lengths, and scikit-learn describes the same operation as 'the L2-normalized dot product of vectors', noting that normalising projects both vectors onto the unit sphere so their dot product becomes the cosine of the angle between them. Search engines use it to rank documents against a query; recommender systems use it to find users with similar taste profiles; retrieval-augmented generation pipelines use it to pull the passages closest to a question.

The reason it beats a plain dot product is length invariance. A long document repeats its terms more often, so its raw vector is longer and its dot product with anything is larger — which would make length, not topic, the dominant ranking signal. Dividing by both norms removes that entirely: doubling every component of one vector leaves the similarity unchanged, which this page demonstrates directly, since multiplying vector A by 1000 gives the identical result. That invariance is also the metric's main limitation. If length genuinely carries meaning in your data — total spend, absolute counts, signal strength — cosine similarity throws away exactly the information you care about, and Euclidean distance is the better choice.

One thing this page deliberately does not do is tell you whether your number is good. There is no universal threshold for 'similar'. A similarity of 0.8 can mean near-duplicate under one embedding model and be entirely unremarkable under another, because different models occupy different regions of the sphere and different corpora have different baseline similarities. No standards body or textbook publishes a threshold, so inventing bands here would be manufacturing a constant. What the page reports instead is the number, the angle, and an objective geometric reading: identical direction, same general direction, orthogonal, opposing, or exactly opposite. Calibrate the cutoff against your own labelled pairs.

Two more facts worth knowing before you read the result. First, if every component of both vectors is non-negative — the normal case for term counts and TF-IDF weights — the similarity can only fall in [0, 1] and the angle can never exceed 90°; negative similarities require signed components, as modern embeddings have. Second, cosine similarity is not Pearson correlation. Correlation centres each vector on its own mean before comparing, which is a different computation with a different answer: on the two default lists here, cosine similarity is 0.6666666667 while Pearson's r is exactly 0. Use correlation when you are asking whether two variables co-vary, and cosine similarity when you are asking whether two vectors point the same way.

What is cosine similarity calculator?

Cosine similarity is the cosine of the angle between two non-zero vectors, computed without ever finding the angle: sim(A, B) = (A·B)/(‖A‖‖B‖), where A·B is the dot product and ‖A‖, ‖B‖ are the Euclidean (L2) norms. Manning, Raghavan and Schütze give it as Equation (24) of §6.3 of Introduction to Information Retrieval, in the form sim(d₁,d₂) = V(d₁)·V(d₂)/(|V(d₁)||V(d₂)|), where V(d) is a document's vector of term weights. The scikit-learn User Guide states the identical formula as k(x, y) = x yᵀ/(‖x‖‖y‖) and explains the geometry: L2 normalisation projects both vectors onto the unit sphere, so their dot product is the cosine of the angle between the points they mark. By the Cauchy–Schwarz inequality |A·B| ≤ ‖A‖‖B‖, so the value always lies in [−1, 1]: +1 means the vectors are positive multiples of each other and point in exactly the same direction, 0 means they are orthogonal and share no direction at all, and −1 means they point in exactly opposite directions. Cosine distance is defined as 1 − similarity, which is the convention used by scipy.spatial.distance.cosine; it is a dissimilarity score rather than a true metric, since it does not satisfy the triangle inequality — the metric version is the angular distance θ/π. The measure is scale-invariant by construction: multiplying either vector by any positive number leaves the result unchanged, which is exactly why it is preferred over the raw dot product for comparing documents of different lengths. It is undefined when either vector is all zeros, because a zero vector has no direction and the denominator collapses.

How to use this calculator.

  1. Paste your first vector into the Vector A box as comma-separated numbers. Spaces, tabs, newlines and a trailing comma are all fine.
  2. Paste your second vector into Vector B. It must have the same number of components as A — component 1 is compared with component 1, and so on.
  3. Read the cosine similarity at the top. It ranges from −1 to +1, and for non-negative data such as term counts it can only be between 0 and 1.
  4. Read the direction relationship line for the objective geometric reading: identical, same general direction, orthogonal, opposing, or exactly opposite.
  5. Use the cosine distance (1 − similarity) if your pipeline expects a dissimilarity, for example when feeding a clustering algorithm that minimises distance.
  6. Compare the dot product with the two norms to see how much of the raw score was just vector length — that difference is precisely what cosine similarity removes.
  7. Do not treat any particular value as a pass mark. Calibrate a threshold against pairs you have labelled yourself, in the same embedding model and the same corpus.

The formula.

sim(A, B) = (A·B) ⁄ (‖A‖ ‖B‖) , distance = 1 − sim

The calculator reads both lists, checks they are the same length, and accumulates three running totals in one pass: the dot product Σ aᵢbᵢ, the squared norm of A (Σ aᵢ²) and the squared norm of B (Σ bᵢ²). The similarity is the dot product divided by the square root of the product of the two squared norms — this is Equation (24) of Manning, Raghavan and Schütze §6.3, and the same expression scikit-learn documents as k(x, y) = x yᵀ/(‖x‖‖y‖).

For the worked example A = (1, 2, 0, 1) and B = (2, 1, 1, 0): the dot product is (1)(2) + (2)(1) + (0)(1) + (1)(0) = 2 + 2 + 0 + 0 = 4. The squared norms are 1 + 4 + 0 + 1 = 6 and 4 + 1 + 1 + 0 = 6, so both norms are √6 ≈ 2.4494897428. The similarity is 4 divided by √(6 × 6) = 6, which is 4/6 = 2/3 = 0.6666666667 exactly as a rational number. The cosine distance is 1 − 2/3 = 0.3333333333, and the angle is arccos(2/3) = 48.1896851042°.

Why divide by both norms: the dot product on its own is the sum of componentwise products, so it grows whenever either vector grows, regardless of direction. Dividing by ‖A‖‖B‖ rescales both vectors to unit length first, which leaves only the directional agreement. That is the whole design of the measure, and it is why a document repeated ten times over has exactly the same cosine similarity to a query as the original.

Bounds and sign: the Cauchy–Schwarz inequality guarantees |A·B| ≤ ‖A‖‖B‖, so the similarity can never leave [−1, 1] and arccos is always defined. A negative value requires at least one component of one vector to be negative; with non-negative data the dot product is a sum of non-negative terms and the similarity is confined to [0, 1].

Numerical care: the similarity is formed as (A·B)/√(‖A‖²‖B‖²) — one square root over the product of the squared norms rather than a quotient of two separate square roots — which removes a rounding site and lets proportional integer inputs such as (1, 2, 3) and (2, 4, 6) return exactly 1 instead of 0.9999999999999999. The value is clamped into [−1, 1] before the inverse cosine, and the cosine distance is computed from the unrounded similarity so that similarity plus distance still equals 1 at the last displayed digit.

Rounding stage and classification: every intermediate is carried at 40 significant digits and rounded once, at the return boundary, to 10 decimal places. The direction relationship is decided on the unrounded similarity with a declared floating-point tolerance of 1e-12, so a pair whose similarity is within 1e-12 of 1 is reported as identical, within 1e-12 of 0 as orthogonal, and within 1e-12 of −1 as exactly opposite. No numeric 'high similarity' bands are shipped, because no authority defines one and a threshold that is meaningful for one embedding model is misleading for another.

A worked example.

Example

A support desk indexes its articles over a four-word vocabulary — refund, shipping, tracking, warranty — and wants to know how close two articles are in topic. Article A uses those words 1, 2, 0 and 1 times, so its vector is (1, 2, 0, 1); article B uses them 2, 1, 1 and 0 times, giving (2, 1, 1, 0). The dot product is (1)(2) + (2)(1) + (0)(1) + (1)(0) = 2 + 2 + 0 + 0 = 4. Each article's norm is the square root of its own squared counts: √(1 + 4 + 0 + 1) = √6 and √(4 + 1 + 1 + 0) = √6, both about 2.4494897428. Dividing the dot product by the product of the norms gives 4 ⁄ 6, so the cosine similarity is 0.6666666667 — a moderate overlap, coming from the two words the articles share, held down by the two words only one of them uses. The cosine distance is 1 − 0.6666666667 = 0.3333333333, and the angle between the two article vectors is 48.1896851042°, comfortably under 90°, so the relationship line reads 'same general direction — the angle is under 90°'. Because both vectors contain only non-negative counts, the similarity could never have come out negative. Note what this number is not: it is not a verdict that the articles are duplicates. Whether 0.67 is high enough to merge two help articles is a judgement that has to be calibrated against pairs this desk has already labelled, in this same vocabulary.

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

Frequently asked questions.

What counts as a good cosine similarity score?
There is no universal answer, and any page that gives you one is guessing. The scale depends entirely on the embedding model and the corpus: some sentence-embedding models cluster all their vectors into a narrow cone where 0.8 is unremarkable and only 0.95 means near-duplicate, while a sparse TF-IDF representation of the same documents might place genuinely related pairs around 0.3 because they share few exact terms. The practical method is to label fifty or so pairs yourself as 'related' or 'unrelated', compute their similarities with your actual pipeline, and pick the cutoff that separates them best. What the number does tell you unconditionally is the geometry: 1 is the same direction, 0 is no shared direction, and −1 is exactly opposite.
What is the difference between cosine similarity and cosine distance?
Cosine distance is defined as 1 − cosine similarity, which is the convention SciPy uses in scipy.spatial.distance.cosine. Similarity of 1 corresponds to distance 0, similarity 0 to distance 1, and similarity −1 to distance 2. Use whichever direction your tooling expects — clustering and nearest-neighbour libraries usually want a distance to minimise, while ranking code usually wants a similarity to maximise. One caveat worth knowing: 1 − cos θ is not a true mathematical metric, because it does not satisfy the triangle inequality. If you need a genuine metric on directions, use the angular distance θ/180° instead, which this page gives you the ingredients for since it reports the angle.
Is cosine similarity the same as Pearson correlation?
No, though they are close relatives. Pearson's r subtracts each vector's own mean before doing exactly this computation, so r is the cosine similarity of the mean-centred vectors. The two agree only when both vectors already have mean zero. The difference is easy to see on this page's default lists: A = (1, 2, 0, 1) and B = (2, 1, 1, 0) give a cosine similarity of 0.6666666667, while Pearson's r on the same numbers is exactly 0, because after centring on their common mean of 1 the deviation vectors become (0, 1, −1, 0) and (1, 0, 0, −1), whose cross-products sum to zero. Use correlation when you are asking whether two variables move together, and cosine similarity when you are asking whether two vectors point the same way.
Why does the length of the vectors not matter?
Because the formula divides by both norms, which rescales each vector to unit length before comparing them. Multiply every component of one vector by 1000 and the numerator grows by a factor of 1000 while its norm in the denominator does too, so the ratio is unchanged. That is exactly the property information retrieval needs: a long document repeats its terms more often, so its raw dot product with a query is larger than a short document's, which would make length rather than relevance the dominant signal. It is also the measure's blind spot. If magnitude carries real meaning in your data — total spend, absolute counts, signal power — cosine similarity discards precisely the information you care about, and Euclidean distance is the better tool.
Can cosine similarity be negative?
Yes, whenever the vectors have an angle greater than 90°, which requires at least one of them to have negative components. Modern dense embeddings from neural models routinely contain negative values, so negative similarities appear naturally there. Sparse representations built from term counts or TF-IDF weights cannot go negative, because every component is a non-negative weight and the dot product of two non-negative vectors is a sum of non-negative terms — so with that kind of data the similarity is confined to [0, 1] and the angle can never exceed 90°. If you see a negative value with data you thought was non-negative, that is a useful signal that something upstream has centred, standardised or otherwise transformed your vectors.
What happens if one of my vectors is all zeros?
This calculator raises an input error rather than returning a number, because the zero vector has no direction and the denominator ‖A‖‖B‖ becomes zero. In an information-retrieval pipeline an all-zero row usually means a document shares no terms at all with the vocabulary you built — a stopword-only document, a document in another language, or a tokenisation failure. Returning a similarity of 0 in that situation would silently hide a data problem behind a plausible-looking answer, so the error is deliberate. Some libraries return 0 or NaN here; check what yours does before comparing results.
Do the two lists have to be the same length?
Yes. Cosine similarity compares vectors component by component, so component 1 of A is only meaningful against component 1 of B — in a text setting that means both vectors must be expressed over the same vocabulary, in the same order. If your lists have different lengths, something has gone wrong upstream: usually two documents were vectorised against different vocabularies, or one row was truncated. The fix is to re-vectorise both against a single shared vocabulary, not to pad the shorter list with zeros, since padding silently changes which term each position refers to.

In this category

Embed

Quanta Pro

Paid features are coming later.

  • All 977 calculators remain free
  • No billing is enabled
Coming soon