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
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.
- Paste your first vector into the Vector A box as comma-separated numbers. Spaces, tabs, newlines and a trailing comma are all fine.
- 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.
- 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.
- Read the direction relationship line for the objective geometric reading: identical, same general direction, orthogonal, opposing, or exactly opposite.
- Use the cosine distance (1 − similarity) if your pipeline expects a dissimilarity, for example when feeding a clustering algorithm that minimises distance.
- 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.
- 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.
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.
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.
Frequently asked questions.
What counts as a good cosine similarity score?
What is the difference between cosine similarity and cosine distance?
Is cosine similarity the same as Pearson correlation?
Why does the length of the vectors not matter?
Can cosine similarity be negative?
What happens if one of my vectors is all zeros?
Do the two lists have to be the same length?
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.
In this category
Embed
Quanta Pro
Paid features are coming later.
- All 977 calculators remain free
- No billing is enabled