What is cosine similarity?
Cosine similarity measures how closely two vectors point in the same direction. It is the cosine of the angle between them and ranges from −1 (exactly opposite) through 0 (perpendicular) to 1 (identical direction). Because it depends only on orientation and not magnitude, it is widely used in machine learning, text mining, and recommendation systems to compare documents, embeddings, and feature vectors.
How to use this calculator
Enter the x, y, and (optionally) z components of Vector A and Vector B. Leave the z fields blank or zero to work in two dimensions. The calculator returns the cosine similarity along with the dot product, each vector's magnitude, and the angle between the vectors in both degrees and radians.
The formula explained
The dot product is the sum of component products: \(\vec{a}\cdot\vec{b} = a_x b_x + a_y b_y + a_z b_z\). The magnitude of a vector is the square root of the sum of its squared components: \(\lVert\vec{a}\rVert = \sqrt{a_x^{2} + a_y^{2} + a_z^{2}}\). Dividing the dot product by the product of the magnitudes normalizes the result into the −1 to 1 range, giving the cosine of the angle \(\theta\). Taking the inverse cosine (arccos) recovers the angle itself.
Worked example
Take 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 magnitudes are \(\lVert A\rVert = \sqrt{1+4+9} = \sqrt{14} \approx 3.7417\) and \(\lVert B\rVert = \sqrt{16+25+36} = \sqrt{77} \approx 8.7750\). So $$\cos\theta = \frac{32}{3.7417 \times 8.7750} \approx 0.9746,$$ which corresponds to an angle of about 12.93°.
FAQ
What does a cosine similarity of 0 mean? The vectors are orthogonal (perpendicular), at a 90° angle, indicating no directional similarity.
Can the result be negative? Yes. A negative value means the vectors point in generally opposite directions; −1 means they are exactly antiparallel.
How is this different from Euclidean distance? Cosine similarity ignores magnitude and only compares direction, while Euclidean distance measures the straight-line gap between vector tips.