Skip to content
D DocNectar

Free Cosine Similarity Calculator

Compute the cosine similarity between two vectors of 2 to 5 dimensions.

100% Free No Signup Works on all devices

Built and fact-checked by the DocNectar team — see our editorial standards

Thanks for rating!

Key Features

Instant Calculation

Get accurate results in real time with our optimized algorithm.

Mobile Friendly

Fully responsive design. Works on all devices & screen sizes.

Privacy Focused

Your data stays on your device. We don't store any inputs.

100% Free

No hidden costs. This tool is completely free forever.

Cosine similarity measures how similar two vectors are in direction, completely ignoring their magnitude, by computing the cosine of the angle between them: cos(θ) = (u·v)/(|u||v|). A result of 1 means the vectors point in exactly the same direction, 0 means they're perpendicular (unrelated), and -1 means they point in exactly opposite directions — with everything in between representing partial similarity. This metric is the backbone of modern text and recommendation systems: search engines and document-comparison tools represent text as high-dimensional word-frequency or embedding vectors and use cosine similarity to rank how closely two documents match, recommendation engines compare user or item vectors to suggest similar products or content, and machine learning systems comparing image or audio embeddings favor cosine similarity specifically because it cares only about the pattern/direction of the data, not its raw scale — so a short document and a long one discussing the same topic in the same proportions can still score as highly similar.

How it works

Choose the number of dimensions (2 to 5) and enter each component of both vectors u and v. The calculator computes the dot product (multiplying matching components and summing the results), the magnitude (Euclidean length) of each vector by taking the square root of the sum of its squared components, and then divides the dot product by the product of the two magnitudes: cos(θ) = (u·v)/(|u||v|). Dividing out each vector's own length is what makes the result depend only on direction — doubling every component of one vector doesn't change the cosine similarity at all, since the extra length cancels out in the division.

  1. Enter number of dimensions.
  2. Enter u — component 1.
  3. Enter u — component 2.
  4. Enter u — component 3.
  5. Enter u — component 4.
  6. Enter u — component 5.
  7. Enter v — component 1.
  8. Enter v — component 2.
  9. Enter v — component 3.
  10. Enter v — component 4.
  11. Enter v — component 5.
  12. Click Calculate to see your results.

Examples

u=(1,2), v=(2,3)

Dot product = 1(2)+2(3) = 8. |u| = √(1²+2²) = √5, |v| = √(2²+3²) = √13. Cosine similarity = 8/(√5×√13) ≈ 0.9922 — very close to 1, meaning the two vectors point in nearly the same direction.

u=(1,0), v=(0,1)

Dot product = 1(0)+0(1) = 0. Since the numerator is 0, cosine similarity = 0 regardless of the magnitudes — the vectors are perfectly perpendicular, indicating no directional relationship at all.

u=(4,4), v=(-2,-2)

Dot product = 4(-2)+4(-2) = -16. |u| = √32, |v| = √8. Cosine similarity = -16/(√32×√8) = -16/16 = -1 — the vectors point in exactly opposite directions, since v is just u scaled by -0.5.

Common mistakes to avoid

  • Leaving unused higher-dimension fields non-zero when a lower dimension is selected — set any unused components to exactly 0.
  • Confusing cosine similarity (which ranges from -1 to 1 and ignores magnitude) with Euclidean distance (which depends heavily on magnitude and has no upper bound).
  • Assuming a cosine similarity near 0 means the vectors are "dissimilar" in value — it only means they're directionally unrelated; their raw numeric values could still be numerically close by other measures.
  • Trying to compute cosine similarity with a zero vector, which leaves the formula undefined due to division by a zero magnitude.

Frequently asked questions

The two vectors point in exactly the same direction (the angle between them is 0°), regardless of how different their magnitudes are — a vector and any positive multiple of itself always score exactly 1.
It means the angle between the vectors exceeds 90° — they point, at least partially, in opposing directions. A value of exactly -1 means they point in perfectly opposite directions.
Distance (like Euclidean distance) is sensitive to magnitude — two vectors with the same direction but very different lengths can be "far apart" by distance, yet cosine similarity would correctly call them nearly identical in direction, which is often what actually matters (e.g., comparing a short tweet and a long article on the same topic).
Mathematically yes — the formula extends to any number of dimensions without any change. This tool caps at 5 dimensions for a manageable input form, but real applications like text embeddings often use hundreds or thousands of dimensions.
They're directly related but not identical: cosine similarity is the cosine of the angle, while the angle itself (in degrees) would require taking the arccosine of the similarity score. A similarity of 0.9922, for instance, corresponds to an angle of about 7.13°.
The calculation is undefined — a zero vector has zero magnitude, and dividing by zero magnitude has no defined value. At least one nonzero component is required in each vector.
No — scaling a vector by any positive number only changes its magnitude, not its direction, and since the magnitudes cancel out in the formula, cosine similarity is completely unaffected by positive scaling (though scaling by a negative number flips the sign of the similarity).

Get new calculators and guides in your inbox

No spam — just new tools like Cosine Similarity Calculator and practical guides.

Favorites