Connect via MCP →

Enter Calculation

Formula

Advertisement

Results

Cosine Similarity
0.974632
range −1 to 1
Dot product (A·B) 32
Magnitude |A| 3.741657
Magnitude |B| 8.774964
Angle between vectors 12.93°
Dimensions used 3

What Is Cosine Similarity?

Cosine similarity measures how similar two vectors are by looking at the angle between them rather than their magnitude. It returns a value between −1 and 1, where 1 means the vectors point in exactly the same direction, 0 means they are orthogonal (unrelated), and −1 means they point in opposite directions. It is widely used in text mining, recommendation systems, information retrieval, and machine learning to compare documents, embeddings, or feature vectors.

Two vectors sharing an origin with the angle theta between them
Cosine similarity measures the angle θ between two vectors, ignoring their magnitudes.

How to Use This Calculator

Enter the components of Vector A and Vector B as comma-separated numbers. Both vectors must have the same number of dimensions (if they differ, the calculator uses the shorter length). Click calculate to see the cosine similarity, the dot product, each vector's magnitude, and the angle in degrees between the two vectors.

The Formula Explained

The cosine similarity is the dot product of the two vectors divided by the product of their Euclidean norms (magnitudes):

$$\cos\theta = \frac{\vec{A} \cdot \vec{B}}{\lVert \vec{A} \rVert \, \lVert \vec{B} \rVert} = \frac{\sum_{i=1}^{n} A_i B_i}{\sqrt{\sum_{i=1}^{n} A_i^{2}} \; \sqrt{\sum_{i=1}^{n} B_i^{2}}}$$

The dot product \(\vec{A} \cdot \vec{B}\) is the sum of element-wise products. The magnitude \(\lVert \vec{A} \rVert\) is the square root of the sum of squared components. Dividing by the magnitudes normalizes the result so it depends only on direction, not length.

Advertisement
Diagram of the cosine similarity formula components: dot product over product of magnitudes
The formula divides the dot product of A and B by the product of their magnitudes.

Worked Example

Let A = [1, 2, 3] and B = [4, 5, 6]. The dot product is \(1 \cdot 4 + 2 \cdot 5 + 3 \cdot 6 = 4 + 10 + 18 = 32\). The magnitude of A is \(\sqrt{1+4+9} = \sqrt{14} \approx 3.7417\), and of B is \(\sqrt{16+25+36} = \sqrt{77} \approx 8.7750\). So

$$\cos\theta = \frac{32}{3.7417 \times 8.7750} \approx \frac{32}{32.8329} \approx 0.9746$$

giving an angle of about 12.93°.

FAQ

Can the result be negative? Yes. If the vectors point in roughly opposite directions, cosine similarity is negative, down to −1 for exactly opposite directions.

What if the vectors have different lengths? The calculator compares only the overlapping dimensions (the shorter vector's length). For meaningful results, use vectors of equal dimension.

How is this different from Euclidean distance? Cosine similarity ignores magnitude and focuses on orientation, so two vectors that point the same way are perfectly similar even if one is much longer.

Last updated: