Cosine Similarity Calculator

This cosine similarity calculator compares the direction of two vectors. Enter both to get the cosine similarity, the angle between them, the cosine distance and the dot-product working.

Numbers separated by commas, spaces or new lines.

Same number of values as A.

Checks on your data

  • All values are non-negative, so the similarity can only fall between 0 and 1 (typical for word counts and TF-IDF vectors).
  • Cosine similarity measures direction only. Vectors of very different length, such as [1, 2] and [100, 200], score a perfect 1. Use Euclidean distance (shown in the results) if size matters.

Results

Cosine similarity
0.9722843
very similar
Angle between vectors
13.521°
Cosine distance (1 − similarity)
0.02771575
Dot product A·B
2557
‖A‖ (length of A)
45.6837
‖B‖ (length of B)
57.5674
Euclidean distance
16.9411
depends on magnitude, unlike cosine
Dimensions
4
Cosine as a function of angle; your pair is marked
-10105010015013.5°Angle θ (degrees)
Component values of A and B (dimension-wise)
02040A·d1: 3A·d13A·d2: 45A·d245A·d3: 7A·d37A·d4: 2A·d42B·d1: 2B·d12B·d2: 54B·d254B·d3: 13B·d313B·d4: 15B·d415
Component products
DimABA × B
d1326
d245542430
d371391
d421530
Show step-by-step solution
  1. Dot product A·B = 3×2 + 45×54 + 7×13 + 2×15 = 2557.
  2. Lengths: ‖A‖ = 45.6837, ‖B‖ = 57.5674.
  3. cos θ = 2557 ÷ (45.6837 × 57.5674) = 0.9722843.
  4. θ = arccos(0.9722843) = 13.521°.
FormulaA·B / (‖A‖‖B‖)
Range−1 to 1
IgnoresVector length
Used inSearch, NLP, recommenders

What Is Cosine Similarity?

Cosine similarity measures how closely two vectors point in the same direction, ignoring their lengths. It equals the dot product of the vectors divided by the product of their magnitudes, and ranges from −1 (opposite) through 0 (perpendicular) to 1 (same direction).

The calculator also returns the angle between the vectors in degrees, the cosine distance (1 − similarity), the dot product, both magnitudes and the Euclidean distance for contrast. Because cosine similarity ignores magnitude, two vectors that differ only in scale score 1.

Below you will find the formula, a variables table, a worked example and answers to common questions such as cosine similarity versus Euclidean distance.

How to Use the Cosine Similarity Calculator

  1. Enter the numbers for vector A and vector B with the same number of values.
  2. Read the cosine similarity and the plain-English description.
  3. Use the component table to see which dimensions contribute most to the dot product.
  4. To compare documents, build term-frequency vectors over the same vocabulary first.

Cosine Similarity Formula

Cosine similarity

cos⁡θ=A⋅B∥A∥ ∥B∥=∑AiBi∑Ai2∑Bi2\cos\theta=\frac{\mathbf{A}\cdot\mathbf{B}}{\|\mathbf{A}\|\,\|\mathbf{B}\|}=\frac{\sum A_iB_i}{\sqrt{\sum A_i^2}\sqrt{\sum B_i^2}}

Cosine distance

dcos=1−cos⁡θd_{cos}=1-\cos\theta

Angle

θ=arccos⁡(cos⁡θ)\theta=\arccos(\cos\theta)

Cosine Similarity Variables Explained

SymbolMeaningNotes
A, BThe two vectorsSame number of dimensions
A·BDot productΣ AᵢBᵢ
‖A‖, ‖B‖Vector magnitudes√(Σ Aᵢ²)
cos θCosine similarityA·B ÷ (‖A‖‖B‖)

Cosine Similarity Worked Example

Using the example values (press “Load example” above to try them):

  1. Dot product A·B = 3×2 + 45×54 + 7×13 + 2×15 = 2557.
  2. Lengths: ‖A‖ = 45.6837, ‖B‖ = 57.5674.
  3. cos θ = 2557 ÷ (45.6837 × 57.5674) = 0.9722843.
  4. θ = arccos(0.9722843) = 13.521°.

Result: Cosine similarity = 0.9722843; Angle between vectors = 13.521°.

How to read the similarity score

What counts as “similar” depends on the data. With sparse text vectors, 0.3 can already be a strong match, while dense embeddings from language models often score 0.7 or more for unrelated texts. Always calibrate against known similar and dissimilar pairs.

Reading cosine similarity
CosineAngleMeaning
10°Same direction
0.8 to 1under 37°Very similar
0.5 to 0.837° to 60°Moderately similar
about 090°Orthogonal, unrelated
below 0over 90°Opposing directions
−1180°Exactly opposite

Cosine vs Euclidean distance vs Pearson correlation

Pearson correlation is cosine similarity after subtracting each vector’s mean, so it ignores shifts as well as scale. If the vectors have different baselines, centre them first.

Choosing a similarity measure
MeasureSensitive to lengthSensitive to shiftTypical use
Cosine similarityNoYesText and embedding similarity
Euclidean distanceYesYesClustering in physical space
Pearson correlationNoNoLinear relationship between variables

Using cosine similarity for text

Represent each document as a vector of word counts or TF-IDF weights over a shared vocabulary, then compare vectors. Because document length scales the counts but not the direction, a long and a short document on the same topic score high. TF-IDF weighting further reduces the influence of very common words.

Where Cosine Similarity Is Used

Comparing text vectors

Scoring how similar two documents are when each is represented as a vector of term counts.

Comparing embeddings

Measuring closeness of two feature or embedding vectors by direction.

Finding the angle

Getting the angle between two vectors from their coordinates.

Linear algebra practice

Checking dot-product and magnitude calculations.

Common Cosine Similarity Mistakes to Avoid

  • Both vectors must be in the same order and have the same dimensions.
  • A zero vector has no direction, so similarity is undefined.
  • Cosine similarity ignores magnitude; if length matters, also compare norms or use Euclidean distance.
  • Mean-centre the vectors if you care about correlation rather than raw direction.

Cosine Similarity Terms and Definitions

Dot product
Sum of the products of matching components.
Norm
The length of a vector, the square root of the sum of squares.
Orthogonal
At a right angle; cosine similarity of zero.

Cosine Similarity FAQs

What is cosine similarity?

It is the cosine of the angle between two vectors. It measures how similar their directions are, independent of their lengths.

What range does cosine similarity take?

From −1 to 1. With non-negative data such as word counts it ranges from 0 to 1.

What is cosine distance?

One minus the cosine similarity. It is 0 for identical directions and 2 for opposite ones. It is not a true metric because it does not satisfy the triangle inequality.

Why use cosine similarity for text?

It ignores document length, so a long and a short document about the same topic can still be judged similar.

How is it different from correlation?

Pearson correlation is the cosine similarity of mean-centred vectors, so it also ignores shifts in the baseline.

Can I compare vectors of different lengths?

Not directly. Both vectors must live in the same space, with the same number of dimensions in the same order.

Related calculators

Last updated 2026-11-09. See our disclaimer.