Cosine Similarity Calculator: Compare Vectors Free in 3 Steps

Cosine Similarity Calculator cos θ

Measure how similar two vectors are by the angle between them — the metric behind embeddings and semantic search.

Enter two equal-length vectors. Separate components with commas or spaces.

Cosine similarity
Angle θ
Dot product A·B
|A|
|B|
Cosine distance
Show working (LaTeX)

This free cosine similarity calculator measures how similar two vectors are by the angle between them — returning the cosine similarity, the angle, the dot product and the magnitudes, step by step.

How to use the cosine similarity calculator

Enter two equal-length vectors into the cosine similarity calculator above and press Calculate. It returns the cosine similarity (a number from −1 to 1), the angle between the vectors, and the dot product and magnitudes it used. As a vector similarity calculator it works in any number of dimensions — ideal for comparing word embeddings or feature vectors.

cosine similarity calculator showing the angle between two vectors from the origin
Cosine similarity is the cosine of the angle θ between two vectors — direction matters, length does not.

What is cosine similarity?

Cosine similarity measures the cosine of the angle between two vectors, ignoring their length and focusing purely on direction. See the cosine similarity reference for the formal definition.

Definition. The cosine similarity of vectors A and B is $\cos\theta=\dfrac{A\cdot B}{\lVert A\rVert\,\lVert B\rVert}$, ranging from −1 (opposite) to 1 (identical direction).

Cosine similarity formula

$$\cos\theta=\frac{A\cdot B}{\lVert A\rVert\,\lVert B\rVert}=\frac{\sum_i A_i B_i}{\sqrt{\sum_i A_i^2}\,\sqrt{\sum_i B_i^2}}$$

How to calculate cosine similarity step by step

  1. Take the dot product of the two vectors.
  2. Find each vector’s magnitude (length).
  3. Divide the dot product by the product of the magnitudes.
ℹ️ What the value means1 = same direction (most similar), 0 = perpendicular (unrelated), −1 = opposite. For typical word embeddings the value usually sits between 0 and 1.

Worked example

For A = (1, 2, 3) and B = (4, 5, 6): the dot product is 32, $\lVert A\rVert=\sqrt{14}\approx 3.742$, $\lVert B\rVert=\sqrt{77}\approx 8.775$, so cosine similarity = $32/(3.742\times 8.775)\approx 0.975$ — an angle of about 12.9°, meaning the vectors point in nearly the same direction.

Cosine similarity to angle

Cosine similarityAngleMeaning
1.0Identical direction
0.8730°Very similar
0.560°Somewhat similar
090°Orthogonal (unrelated)
−1180°Opposite

Why cosine similarity matters in machine learning

Cosine similarity is the backbone of modern machine learning search. Embeddings turn text, images and users into vectors, and cosine similarity measures how close two of them point — powering semantic search, recommendation systems and retrieval-augmented generation (RAG). It builds directly on the dot product and unit vectors.

🤖 ML insight

Why cosine and not plain distance? Embeddings can have very different magnitudes, but it’s their direction that carries meaning. Cosine similarity ignores length, so “king” and “kings” score as nearly identical even if one vector is longer.

Cosine similarity vs Euclidean distance

Euclidean distance measures the straight-line gap between two points and is sensitive to magnitude; cosine similarity measures only the angle, so it is scale-invariant. For high-dimensional embeddings — where vectors can have wildly different lengths — cosine similarity is usually the better choice, which is why vector databases default to it.

The two are related: if you first normalise both vectors to unit length, ranking by cosine similarity and ranking by Euclidean distance give the same order. That’s why many pipelines normalise embeddings up front and then use whichever metric is faster.

Frequently asked questions

What range does cosine similarity have?
Always between −1 (opposite directions) and 1 (identical direction).
What does a cosine similarity of 0 mean?
The vectors are orthogonal (at 90°) — unrelated in direction.
What is cosine distance?
Cosine distance = 1 − cosine similarity, so identical vectors have distance 0.
Do the vectors need the same number of dimensions?
Yes — both vectors must have the same number of components.
Is the cosine similarity calculator free?
Yes, completely free and runs in your browser.

Cosine similarity calculator: summary

From comparing embeddings to powering semantic search, this cosine similarity calculator gives the similarity, angle and the working in one click. Pair it with the dot product calculator and the unit vector calculator.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top