Built and fact-checked by the DocNectar team — see our editorial standards
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.
- Enter number of dimensions.
- Enter u — component 1.
- Enter u — component 2.
- Enter u — component 3.
- Enter u — component 4.
- Enter u — component 5.
- Enter v — component 1.
- Enter v — component 2.
- Enter v — component 3.
- Enter v — component 4.
- Enter v — component 5.
- 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.