Cosine Similarity Calculator
Compute cosine similarity between two vectors. Supports raw numeric arrays, comma-separated strings, and tag-frequency bags for NLP and ML use cases. Returns the score from -1 to 1, the angle in degrees, magnitudes, and a similarity classification.
Cosine Similarity Examples
| Vector A | Vector B | Cosine Similarity | Angle |
|---|---|---|---|
| (1, 0) | (1, 0) | 1 | 0° |
| (1, 0) | (0, 1) | 0 | 90° |
| (1, 1) | (1, 0) | 0.7071 | 45° |
| (1, 1) | (1, -1) | 0 | 90° |
| (1, 2) | (2, 1) | 0.8 | 36.87° |
| (1, 0) | (-1, 0) | -1 | 180° |
Frequently Asked Questions about the Cosine Similarity Calculator
What is the cosine similarity formula?
Cosine similarity is the dot product of two vectors divided by the product of their magnitudes: cos(theta) = (A . B) / (|A| * |B|). The dot product A . B sums the elementwise products a_i * b_i across every dimension. Each magnitude is the square root of the sum of squared components, sqrt(sum of a_i^2). The result is the cosine of the angle between the two vectors, which lands between -1 and 1. Identical direction returns 1, perpendicular (orthogonal) returns 0, exactly opposite directions return -1.
How does cosine similarity differ from Euclidean distance?
Cosine similarity only looks at direction, ignoring magnitude. Euclidean distance measures the straight-line gap between two points and is dominated by magnitude. Two documents of very different lengths can have a high cosine similarity if they use the same words in the same proportions, but their Euclidean distance will be large because one vector has bigger numbers throughout. That is exactly why text retrieval, recommendation systems, and embedding search default to cosine: a long article and a short summary on the same topic should score as similar, not as far apart.
Where is cosine similarity used in NLP and machine learning?
Cosine similarity is common for TF-IDF vectors and for embedding models whose geometry or normalization supports it. Search and recommendation systems may rank vectors by cosine similarity, dot product, Euclidean distance, or a model-specific metric. Use the metric recommended for the embedding model rather than assuming cosine is always appropriate.
Why does direction matter more than magnitude in cosine similarity?
Because the metric divides out magnitude by construction. The denominator |A| * |B| cancels any scalar multiple of either vector, so doubling every component of A leaves the similarity exactly the same. In an NLP setting that means a 200-word article and a 2000-word article on the same topic can have nearly identical cosine similarity even though their raw word counts differ by 10x. In an embedding setting it means temperature or norm differences in the model output do not change the ranking. If you do care about magnitude (length, importance, confidence), use Euclidean or Manhattan distance instead, or weight the cosine score by a separate magnitude signal after retrieval.
What does it mean when cosine similarity is 0 (orthogonal vectors)?
A cosine similarity of 0 means the vectors are mathematically orthogonal and their dot product is 0. For nonnegative bag-of-words vectors, that can mean no shared terms. Dense embedding dimensions are not usually individually interpretable, so a value near 0 does not prove there is no semantic overlap. Interpret it against the model and comparison distribution.
Related Calculators
More calculators in "Math"
Polynomial Long Division CalculatorPolynomial CalculatorCombinations and Permutations CalculatorMatrix Determinant CalculatorMatrix Multiplication CalculatorDouble Discount Calculator (Stacked %)
See all 202 calculators in "Math"