Skip to content
Omnikalc

Cosine similarity calculator: how close are the directions of two vectors?

Enter the components of two vectors to get the cosine similarity, the angle between them, the cosine distance, the dot product and the lengths.

Updated on
Your inputs

Value out of range

Value out of range

Value out of range

Value out of range

Value out of range

Value out of range

Results

Cosine similarity

0.6779

Moderately similar direction
Angle between the vectors
47.32 °
Cosine distance (1 − similarity)
0.3221
Dot product A · B
29.00
Length of A
5.4772
Length of B
7.8102

Direction often matters more than size. The cosine similarity calculator takes the components of two vectors and gives the cosine similarity, the angle between them, the cosine distance, the dot product and the length of each vector.

How the calculation works

  • Enter the three components of vector A and of vector B. For vectors with two components, set the third to 0.
  • The cosine similarity is A · B ÷ (|A| × |B|), the dot product divided by the product of the lengths.
  • It runs from −1, vectors pointing in opposite directions, through 0, perpendicular vectors, to +1, vectors pointing the same way.
  • The angle is the inverse cosine of the similarity, and the cosine distance is 1 minus the similarity.

Example

Take A = (2, 5, 1) and B = (4, 3, 6). The dot product is 8 + 15 + 6 = 29. The lengths are √30 = 5.4772 and √61 = 7.8102. The cosine similarity is 29 ÷ 42.778 = 0.6779, which corresponds to an angle of 47.3°.

Why it matters

Cosine similarity is a core tool in information retrieval, machine learning and data science, and also a basic geometric idea in physics and engineering. A calculator helps check hand computations and build intuition, for instance by showing how rescaling a vector leaves the similarity unchanged while the dot product grows.

Good to know

The calculator handles three components. For longer vectors such as word-count tables, the idea is the same but the sums include every component. A zero vector has no direction, so the similarity is reported as 0 in that case. The angle is given in degrees between 0 and 180.

The vector calculator covers other operations on vectors, and the trigonometry calculator helps with the angle.

Frequently asked questions

What does cosine similarity measure?

It measures how closely two vectors point in the same direction, ignoring their lengths. Two vectors that are multiples of each other have a cosine similarity of 1, however different their magnitudes are.

Where is cosine similarity used?

It is widely used in text analysis and search, where documents are represented as vectors of word counts, and in recommendation systems and embeddings. Comparing direction rather than size helps when long and short documents should be treated alike.

What is the difference between cosine similarity and correlation?

Pearson correlation is the cosine similarity of the two data sets after subtracting each mean. So they agree when the means are zero, but can differ when they are not.

Can the similarity be negative?

Yes, if the vectors point in broadly opposite directions the value is negative, down to −1. With non-negative data such as word counts, it stays between 0 and 1.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.