Cosine Similarity Calculator
- The dot product multiplies the vectors component by component and adds: (1, 2, 3) . (4, 5, 6) = 32.
- Lengths next: |a| = 3.74 and |b| = 8.77 — the Euclidean norms that turn the dot product into a pure angle measure.
- Cosine similarity = 32 / (3.74 x 8.77) = 0.97 — 1 means same direction, 0 means perpendicular, -1 means exactly opposite, whatever the vectors' lengths.
- That cosine corresponds to an angle of 12.93 degrees between the vectors — the geometric reading of the same number.
- Because lengths cancel, cosine similarity compares direction only: it is the standard similarity for text embeddings and document vectors, where a longer document should not outscore a shorter one on the same topic.
The Cosine Similarity Calculator measures how closely two vectors point in the same direction. Cosine similarity is the dot product of two vectors divided by the product of their lengths — the cosine of the angle between them. Enter your vectors and the calculator returns that value along with the angle in degrees. For example, for (1, 2, 3) and (4, 5, 6) the dot product is 32, the lengths are 3.74 and 8.77, and the cosine similarity is 0.97 — an angle of 12.93°. The scale runs from −1 to 1: perpendicular vectors score 0.00 (angle 90.00°) and exactly opposite vectors score −1.00 (angle 180.00°). For non-negative data such as word counts, the value lies between 0 and 1.
Because the lengths cancel, cosine similarity compares direction only — which is why it is the standard similarity for text embeddings and document vectors. Two documents of very different lengths can still score as highly similar if their word patterns point the same way. This page shows the formula, step-by-step workings, worked examples and sources, so you can check every number rather than take the result on trust. Whether you are comparing embeddings, document vectors or any other pair of vectors, the calculator gives you the score, the angle and the arithmetic behind them in one place.
Worked examples
Two similar 3D vectors
Primary result: 0.97. Full step-by-step working is shown with the result. (3 dimensions · 1 · 2 · 3 · 0 · 0 · 4 · 5 · 6 · 0 · 0)
| Cosine similarity | 0.97 |
| Angle between the vectors | 12.93 degrees |
| Dot product | 32 |
| Length of a | 3.74 |
| Length of b | 8.77 |
Perpendicular vectors
Primary result: 0.00. Try it with your own numbers in the calculator above. (2 dimensions · 1 · 0 · 0 · 0 · 0 · 0 · 1 · 0 · 0 · 0)
| Cosine similarity | 0.00 |
| Angle between the vectors | 90.00 degrees |
| Dot product | 0 |
| Length of a | 1.00 |
| Length of b | 1.00 |
Opposite vectors
Primary result: -1.00. Every intermediate value is printed in the worked steps. (4 dimensions · 2 · 2 · 0 · 0 · 0 · -1 · -1 · 0 · 0 · 0)
| Cosine similarity | -1.00 |
| Angle between the vectors | 180.00 degrees |
| Dot product | -4 |
| Length of a | 2.83 |
| Length of b | 1.41 |
What cosine similarity measures
Cosine similarity is the dot product of two vectors divided by the product of their lengths. That ratio is exactly the cosine of the angle between the two vectors, which is why a cosine similarity calculator can report a single number that describes how closely two vectors point in the same direction. The arithmetic is straightforward but easy to get wrong by hand, so a calculator is most useful when you want a reliable answer on longer vectors without tracking every multiplication and square root.
A worked example shows how the pieces fit together. For the vectors (1, 2, 3) and (4, 5, 6), the dot product is 32, the lengths are 3.74 and 8.77, and the cosine similarity is 0.97 — an angle of 12.93°. Those two vectors are not identical, but they lean in nearly the same direction, and the score reflects that closeness. The angle is the geometric reading of the same fact: a small angle means the vectors are aligned, and a large angle means they diverge.
The scale runs from −1 to 1, and each landmark has a clear geometric meaning. Perpendicular vectors score 0.00 (angle 90.00°), meaning they share no directional agreement at all. Exactly opposite vectors score −1.00 (angle 180.00°), the maximum possible disagreement in direction. A score of 1.00 would mean the vectors point the same way. Because lengths cancel in the division, cosine similarity compares direction only — a long vector and a short vector pointing the same way score the same as two vectors of equal length pointing that way.
That direction-only property is why cosine similarity is the standard similarity for text embeddings and document vectors. A long document and a short one can cover the same topic and still receive a high score, because the comparison ignores how much text each contains and looks only at the pattern of the vectors. The value always lies between −1 and 1; for non-negative data such as word counts it lies between 0 and 1, since such vectors cannot point in opposite directions.
- Score 1.00: vectors point in the same direction (angle 0°).
- Score 0.97: nearly aligned, as in (1, 2, 3) versus (4, 5, 6), an angle of 12.93°.
- Score 0.00: perpendicular vectors, angle 90.00°.
- Score −1.00: exactly opposite vectors, angle 180.00°.
How to calculate it, step by step
To calculate cosine similarity by hand, you need two vectors of the same length — each a list of numbers, such as the counts of words in a document. Cosine similarity is the dot product of two vectors divided by the product of their lengths, which is the cosine of the angle between them. That sentence contains the whole method: one multiplication step, two length steps, one division, and one final conversion if you want the angle.
Start with the dot product. Multiply the vectors element by element, then add the results. Take the vectors (1, 2, 3) and (4, 5, 6): the products are 1×4 = 4, 2×5 = 10, and 3×6 = 18, which add up to 32. Next, find both lengths. Square each element of a vector, add the squares, and take the square root. For (1, 2, 3) that is √(1 + 4 + 9) = √14, about 3.74. For (4, 5, 6) it is √(16 + 25 + 36) = √77, about 8.77. Now divide the dot product by the product of the lengths: 32 ÷ (3.74 × 8.77), which gives a cosine similarity of 0.97. That is a strong score, and it corresponds to an angle of 12.93° between the two vectors.
If you want the angle in degrees, take the inverse cosine (arccos) of the similarity value. For 0.97, arccos(0.97) is 12.93°. The scale is easy to read once you know its landmarks. Perpendicular vectors score 0.00, an angle of 90.00°, meaning they share no direction at all. Exactly opposite vectors score −1.00, an angle of 180.00°. The value always lies between −1 and 1, and for non-negative data such as word counts it lies between 0 and 1. A good cosine similarity calculator automates these steps, but running the arithmetic once by hand makes the output much easier to interpret.
The reason this works so cleanly is that the lengths cancel out of the comparison. Because lengths cancel, cosine similarity compares direction only — which is why it is the standard similarity for text embeddings and document vectors. A long document and a short one that use the same words in the same proportions can score near 1.00 even though their raw counts differ greatly. Keep that in mind when reading a score: it tells you how aligned two vectors are, not how large they are.
- Step 1 — Dot product: multiply matching elements and add them. For (1, 2, 3) and (4, 5, 6): 4 + 10 + 18 = 32.
- Step 2 — Lengths: square each element, sum, and take the square root. √14 ≈ 3.74 and √77 ≈ 8.77.
- Step 3 — Divide: 32 ÷ (3.74 × 8.77) ≈ 0.97.
- Step 4 — Angle: arccos(0.97) ≈ 12.93°.
- Reference points: 0.00 = 90.00° (perpendicular); −1.00 = 180.00° (opposite).
Cosine similarity in text and AI
In text analysis and AI, documents, sentences, and words are turned into vectors — lists of numbers that stand in for meaning. A document vector might simply count how often each word appears; a modern embedding model instead assigns each word or passage a long list of coordinates learned from large amounts of text. Once meaning is expressed as direction in space, a cosine similarity calculator becomes a practical tool: it tells you how closely two of those vectors point the same way, and therefore how similar the underlying texts or items are.
The formula is the dot product of the two vectors divided by the product of their lengths — that is, the cosine of the angle between them. Take (1, 2, 3) and (4, 5, 6). Their dot product is 32, their lengths are 3.74 and 8.77, and the cosine similarity is 0.97, an angle of 12.93°. Perpendicular vectors score 0.00 (angle 90.00°), and exactly opposite vectors score −1.00 (angle 180.00°). The value always lies between −1 and 1; for non-negative data such as word counts it lies between 0 and 1.
What makes this measure so useful in text and AI is that lengths cancel out. A long article and a short note that discuss the same subject can have very different vector lengths, yet still point in nearly the same direction. Because lengths cancel, cosine similarity compares direction only — which is why it is the standard similarity for text embeddings and document vectors. A verbose page is not automatically judged more similar to a query than a concise one; what counts is the mix of terms or the direction of meaning, not the sheer volume of text.
Recommender systems use the same idea. A user can be represented as a vector of preferences or interactions, and an item as a vector of attributes or the users who engaged with it. Comparing these vectors with cosine similarity lets a system rank items by how closely they align with a user's profile, even when one user has clicked a hundred things and another only a few. Embedding search works the same way: a query is embedded, and the closest documents are those whose vectors have the highest cosine similarity to it.
That length-independence does have limits worth knowing. For non-negative data such as word counts the score stays between 0 and 1, so a value near 0 means little shared direction and a value near 1 means strong alignment. When vectors can be negative — as with many learned embeddings — scores can fall below zero, down to −1.00 for exactly opposite directions, so a negative result is meaningful rather than an error. Reading the score alongside the angle, as in the 0.97 and 12.93° example above, keeps the comparison intuitive.
Cosine vs Euclidean distance and Pearson correlation
Cosine similarity, Euclidean distance and Pearson correlation all measure how alike two vectors are, but they answer different questions. Cosine similarity is the dot product of two vectors divided by the product of their lengths — the cosine of the angle between them. Euclidean distance instead measures the straight-line gap between the two points, so it grows with the size of the numbers as well as their pattern. Pearson correlation asks whether two variables rise and fall together, which makes it the right choice when you care about the shape of a trend rather than its position in space.
The worked example shows how cosine behaves. For (1, 2, 3) and (4, 5, 6) the dot product is 32, the lengths are 3.74 and 8.77, and the cosine similarity is 0.97 — an angle of 12.93°. The vectors point in nearly the same direction even though their magnitudes differ. Perpendicular vectors score 0.00 (angle 90.00°); exactly opposite vectors score −1.00 (angle 180.00°). The value always lies between −1 and 1; for non-negative data such as word counts it lies between 0 and 1.
Because lengths cancel, cosine similarity compares direction only — which is why it is the standard similarity for text embeddings and document vectors. A short document and a long document on the same topic can score close to 1.00 even though their raw word counts differ hugely. Euclidean distance would punish that length difference, so reach for it when absolute magnitude matters, such as comparing sensor readings or coordinates where being far away is itself meaningful. A cosine similarity calculator is the practical tool when direction is the signal you want to isolate.
The centring difference separates cosine from Pearson correlation. Pearson correlation subtracts each vector's mean before comparing, so it measures similarity of deviations from the average rather than similarity of the raw vectors. Cosine does not centre: it works on the vectors as given. Two vectors that share a large constant offset can look very similar to cosine while correlating weakly, and two vectors with different baselines can correlate strongly while scoring modestly on cosine. If your data has a meaningful zero and you care about the direction from the origin, use cosine; if you care about co-movement around each series' own average, use Pearson.
In short: choose cosine for direction-based similarity of embeddings and counts, Euclidean distance when the size of the gap is the point, and Pearson correlation when you want to strip out level and compare patterns of change.
FAQs
What is cosine similarity?
Cosine similarity measures the cosine of the angle between two vectors. You get it by dividing their dot product by the product of their lengths. The result always falls between −1 and 1, so it gives a fixed scale for comparing how closely two vectors point in the same direction.
How do you calculate cosine similarity?
Multiply matching components and add them to get the dot product, then divide by the product of the vectors' lengths. For (1, 2, 3) and (4, 5, 6), the dot product is 32 and the lengths are 3.74 and 8.77, so 32 / (3.74 × 8.77) = 0.97.
What does a cosine similarity of 1 mean?
A score of 1 means the vectors point in exactly the same direction, making them maximally similar. Length does not affect the score: a short vector and a long vector pointing the same way still score 1, because cosine similarity compares direction only, not magnitude.
Can cosine similarity be negative?
Yes. Vectors pointing in opposing directions score below 0, reaching −1 when they are exactly opposite. If your data contains only non-negative values, the score stays in the range 0 to 1, since such vectors cannot point away from each other.
Why is cosine similarity used for text?
It ignores document length and compares only the direction of the term or embedding vector. That means a long document and a short document on the same topic can still score as similar, which makes it a practical way to compare texts of very different sizes.
How do I turn cosine similarity into an angle?
Take the arccosine of the similarity score to get the angle between the vectors. For example, a similarity of 0.97 corresponds to about 12.93 degrees, showing how close the two vectors are in direction.