Cosine Similarity Calculator — Vector Angle & Distance
Enter two vectors (any number of dimensions) to compute their cosine similarity — the cosine of the angle between them — along with the dot product, magnitudes, angle in degrees, and cosine distance.
Highly similar
- 1
Dot product A·B = Σ(aᵢ × bᵢ)
32Sum of element-wise products of the two vectors. - 2
|A| = √(Σaᵢ²)
3.7417 - 3
|B| = √(Σbᵢ²)
8.775 - 4
Cosine similarity = A·B ÷ (|A| × |B|)
32 ÷ (3.7417 × 8.775) = 0.9746
How does this calculator work?
cos(θ) = A·B / (|A|·|B|). Values: +1 (same direction), 0 (perpendicular), −1 (opposite). Scale-invariant — only direction matters, not magnitude. Widely used in NLP and recommendation systems. Cosine distance = 1 − similarity. Undefined for zero-magnitude vectors.
Formula
How this is calculated
Cosine similarity measures how similar the directions of two vectors are, regardless of their magnitudes. It equals the dot product of the two vectors divided by the product of their Euclidean lengths: cos(θ) = A·B / (|A| × |B|). The result always lies in [−1, 1]: +1 means the vectors point in exactly the same direction, 0 means they are perpendicular (orthogonal), and −1 means they point in exactly opposite directions.
Unlike Euclidean distance, cosine similarity is scale-invariant — multiplying one vector by any positive constant does not change the similarity score. This property makes it especially valuable in text analysis and NLP, where term-frequency vectors for documents of different lengths need to be compared fairly, and in recommender systems where the magnitude of a user's preference vector is irrelevant to directional similarity.
The cosine distance, 1 − cos(θ), converts similarity into a dissimilarity measure useful for clustering. The angle θ = arccos(cos(θ)) gives the actual geometric angle between the two vectors in n-dimensional space, always in [0°, 180°]. Cosine similarity is undefined if either vector is the zero vector, since that vector has no direction.
Frequently asked questions
A similarity of 0 means the two vectors are orthogonal (perpendicular) — they share no directional alignment. In NLP this often means the two documents share no common words. It does not mean the vectors are opposite; −1 represents completely opposite directions.
Euclidean distance measures the straight-line gap between two points; it depends on magnitude. Cosine similarity measures only the angle between direction vectors; it is magnitude-invariant. Two vectors close in direction can be far apart in magnitude (large Euclidean distance, high cosine similarity), or vice versa.
Cosine similarity itself is not a metric. The cosine distance (1 − similarity) is used as a dissimilarity measure in clustering, but it does not strictly satisfy the triangle inequality in all cases. In practice it is widely used in k-means and hierarchical clustering of text and embedding vectors.
TG we-Calculate Editorial Team. (2026). Cosine Similarity Calculator — Vector Angle & Distance [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/cosine-similarity-calculator
TG we-Calculate Editorial Team. "Cosine Similarity Calculator — Vector Angle & Distance." TG we-Calculate. 2026. https://we-calculate.com/calculator/cosine-similarity-calculator.
TG we-Calculate Editorial Team, "Cosine Similarity Calculator — Vector Angle & Distance," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/cosine-similarity-calculator
@misc{wecalculate_cosine_similarity_calculator, title = {Cosine Similarity Calculator — Vector Angle & Distance}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/cosine-similarity-calculator}}, year = {2026}, note = {TG we-Calculate} }
Did this calculator help you?
