Math
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
Cosine similarity does not require pre-normalization. Check this box only to flag the result for downstream pipelines that expect unit vectors.
Cosine similarity
0.9949
near-identical direction (angle 5.77°)
Dot product
70
|A| magnitude
7.4162
|B| magnitude
9.4868
Dimensions
5
Angle (degrees)
5.77
Orthogonal
No
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?
It is the standard similarity metric for word embeddings (Word2Vec, GloVe, fastText), sentence embeddings (Sentence-BERT, MiniLM), and modern LLM embeddings (OpenAI, Cohere, Voyage). Document retrieval and semantic search rank candidates by cosine similarity against the query embedding. Recommendation systems score user-item affinity by the cosine between user and item vectors. Image embeddings (CLIP, DINO) use it for image search. TF-IDF document comparison was the classic pre-deep-learning use case and still works well for keyword-driven retrieval. Whenever the model output is a dense vector and you need to ask whether two things are alike, cosine similarity is almost always the first thing to try.
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 two vectors are orthogonal: the angle between them is exactly 90 degrees and their dot product is 0. In embedding space, orthogonality usually means the two items share no semantic overlap on any dimension the model learned. For sparse bag-of-words vectors, orthogonality is common and just means the two documents have no words in common. For dense neural embeddings it is much rarer because most dimensions carry some signal for every input, so true zeros almost never appear; values close to zero (say between -0.05 and 0.05) are interpreted the same way. This calculator flags scores with absolute value under 0.01 as orthogonal.