Cosine Similarity Calculator
Compare vectors by the angle between them, the way search engines and embedding models do. Exact cosines like √2/2, every pair at once, and a picture of why length doesn't count.
Vectors
Enter two to eight vectors with the same number of entries, such as embeddings or word counts, or start from an example.
Similarity
Updates as you type.
- Angle
- Dot product
- Lengths
- Euclidean distance
They point broadly the same way, so the similarity is positive.
What cosine similarity measures
Cosine similarity compares two vectors by the angle between them and ignores how long they are. It's the dot product divided by both lengths, which is the cosine of the angle :
The result is always between and . It's when the vectors point the same way, when they're perpendicular, and when they point in opposite directions. Doubling a vector doubles its dot product with everything, but it also doubles its length, so the two cancel and the cosine stays put. The dot product itself, and the angle formula behind it, are worked through in the Dot Product and Angle Calculator.
This calculator keeps the answer exact, so you see rather than only . With three or more vectors, it fills in the cosine for every pair. Stack unit-length vectors as the columns of a matrix and that whole grid is one matrix product, .
Why machine learning uses it
Many models turn things into vectors whose direction carries the meaning and whose length mostly doesn't.
- Embeddings. Language models map words, sentences, and documents to vectors. Two texts about the same thing point in similar directions, so semantic search and retrieval rank results by cosine similarity with the query.
- Word counts. A document can be a vector of how often each word appears. A long article and a short note on the same topic have very different lengths but similar proportions, so their cosine is high while their distance apart is large. The "Word counts" example shows three documents over a five-word vocabulary.
- Recommendations. Users and items become vectors of ratings or learned features, and "people like you also liked" is a nearest-neighbor search by cosine.
When every vector is scaled to length 1 first, which most embedding libraries do, cosine similarity and the dot product give the same number, and ranking by distance gives the same order too. The difference only matters when lengths vary.
Similarity, distance, and how to read the grid
The cosine distance turns similarity into a distance-like number from 0 to 2. It isn't a true distance, but it's widely used for clustering. The Euclidean distance shown beside it does depend on length: in the "Same direction" example, and have cosine 1 yet sit a whole apart.
In the grid, each row and column is one vector, the diagonal is always 1, and the grid is symmetric because the angle from to is the same as from to . Darker cells are more similar, and red ones point apart. A zero vector has no direction, so its row stays empty. The idea of measuring how much one vector lies along another continues in the Vector Projection Calculator.
Related calculators
The linear algebra underneath, and more of the machine learning section.
Dot Product and Angle Calculator
Find the dot product, magnitudes, unit vectors, and the angle between two vectors, with exact roots like √14. Drag vectors and watch the sign change at 90°.
Vector Projection Calculator
Project one vector onto another in exact fractions. Get the vector projection, scalar projection, and orthogonal remainder, and see the projection as a shadow.
Linear Independence and Span Calculator
Check whether vectors are linearly independent, with exact dependency relations like v₃ = 2v₁ − v₂. Find a basis for the span, and watch it grow from a line to a plane to space.
Matrix Multiplication Calculator
Multiply two to four matrices with exact fractions, entry-by-entry explanations, and Python list import and export.