Cosine similarity calculator

Paste two vectors of the same length, such as embeddings, word counts or ratings, and get their cosine similarity, the cosine distance 1 − cos θ, the angle between them and the numbers behind it.

Numbers separated by commas, spaces or semicolons.
Same number of values as vector A.
Cosine similarity0.974632
Cosine distance (1 − similarity)
0.0253682
Angle between the vectors
12.9332°
Angle in radians
0.225726
Dot product A·B
32
Length ‖A‖
3.74166
Length ‖B‖
8.77496
Euclidean distance ‖A − B‖
5.19615
Dimensions
3

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Paste vector A and vector B, for example 1, 2, 3 and 4, 5, 6.
  2. Read the cosine similarity at the top; the distance, angle and the dot product and lengths are below.

How it works

  • Dot product: A·B = Σ aᵢbᵢ.
  • Lengths: ‖A‖ = √(Σ aᵢ²), ‖B‖ = √(Σ bᵢ²).
  • Similarity: cos θ = A·B / (‖A‖ ‖B‖); distance = 1 − cos θ.
  • The angle is computed from the unit vectors in a form that stays accurate near 0° and 180°.

Worked example

A = (1, 2, 3), B = (4, 5, 6). A·B = 4 + 10 + 18 = 32, ‖A‖ = √14 = 3.74166, ‖B‖ = √77 = 8.77496. The similarity is 32 / √1078 = 0.974632, the cosine distance is 0.0253682 and the angle is 12.9332° (0.225726 rad). The vectors point in nearly the same direction even though B is more than twice as long.

Tips and common mistakes

  • Keep the components in the same order in both vectors; similarity compares position by position.
  • Centring the data first (subtracting each vector’s mean) turns cosine similarity into the Pearson correlation.
  • For very sparse vectors, most zeros contribute nothing; only positions where both are non-zero add to the dot product.

Frequently asked questions

What is the formula for cosine similarity?

cos θ = A·B / (‖A‖ ‖B‖): the dot product divided by the product of the lengths. It ranges from −1 (opposite) through 0 (perpendicular) to 1 (same direction).

Why use cosine similarity instead of Euclidean distance?

It compares directions and ignores length, so a document and the same document repeated twice are identical (similarity 1) while their Euclidean distance is large. That is why it is common for text vectors and embeddings.

Is cosine distance a true distance?

1 − cos θ is widely used but does not satisfy the triangle inequality. The angle θ itself does, so use the angle when you need a proper metric.

Can the similarity be negative?

Yes, when the vectors point in roughly opposite directions. With only non-negative values, such as word counts, it stays between 0 and 1.

More in Math

All tools in this category: Math ·Updated November 4, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.