Cosine Similarity Calculator
Inputs
| Component a₁ | 0.5 |
|---|---|
| Component a₂ | 0.1 |
| Component a₃ | -0.3 |
| Component b₁ | 0.4 |
| Component b₂ | 0.2 |
| Component b₃ | -0.1 |
Cosine Similarity Calculator
Compute the cosine similarity and angle between two vectors from their components — the standard way to measure how alike two text embeddings are.
Inputs
Vector A
Vector B
Results
Enter a value to see results.
Details
Cosine similarity
Cosine similarity measures how closely two vectors point in the same direction. It is the cosine of the angle between them, so it depends only on their orientation and not on their lengths. The score runs from minus one, for vectors pointing in exactly opposite directions, through zero, for vectors at a right angle, to plus one, for vectors aligned in the same direction. It is the default way to compare text embeddings, where the direction of a vector encodes meaning and its length is mostly incidental. This calculator works in three dimensions so the arithmetic is easy to follow, but the formula and its interpretation are identical in the hundreds or thousands of dimensions a real embedding occupies.
How it is computed
Two ingredients combine to give the score. The dot product measures how much the vectors agree component by component, and the magnitudes measure their lengths. For vectors and the dot product is
a⋅b=a1b1+a2b2+a3b3and the magnitude of a vector is the square root of the sum of its squared components,
∥a∥=a12+a22+a32Dividing the dot product by the two magnitudes cancels the effect of length and leaves only the angle:
cosθ=∥a∥∥b∥a⋅bThe angle itself follows by inverting the cosine, , which is sometimes easier to reason about than the raw score — a similarity of 0.92 is harder to picture than an angle of roughly twenty-three degrees.
Worked example
Compare with . The dot product is
a⋅b=(0.5)(0.4)+(0.1)(0.2)+(−0.3)(−0.1)=0.20+0.02+0.03=0.25The magnitudes are
∥a∥∥b∥=0.25+0.01+0.09=0.35=0.5916=0.16+0.04+0.01=0.21=0.4583so the cosine similarity is
cosθ=0.5916×0.45830.25=0.27110.25=0.9221which corresponds to an angle of . The two vectors are close but not identical — they lean strongly the same way, with a little over twenty degrees of separation. A score this high would, in an embedding search, mark the two items as a strong match.
Notes and variations
When vectors are normalized to unit length in advance, both magnitudes equal one and cosine similarity reduces to the dot product alone — which is why vector databases store normalized embeddings and rank results by a single multiply-and-add. Cosine similarity is also closely related to Euclidean distance on the unit sphere: for unit vectors, a higher cosine similarity always means a smaller straight-line distance, so the two rankings agree. Scores are only comparable within one embedding model; a value of 0.8 from one model does not mean the same thing as 0.8 from another.
Application
Cosine similarity is the scoring step behind embedding search, which underpins retrieval-augmented generation. The passages it compares are produced by a chunking stage — see RAG Chunking Calculator — and embedded into vectors whose cost is estimated by Embedding Cost Calculator. The number of such vectors a system must compare drives the index size computed by Vector Database Size Calculator.
Frequently Asked Questions (FAQ)
How does cosine similarity differ from Euclidean distance?
Euclidean distance measures the straight-line gap between the tips of two vectors and is sensitive to their lengths. Cosine similarity measures only the angle between them and ignores length entirely.
Two embeddings that point the same way but differ in magnitude have a large Euclidean distance yet a cosine similarity near 1. For text embeddings, direction carries the meaning and magnitude is mostly incidental, so the angle is usually the more informative comparison.
What range does cosine similarity take?
It ranges from −1 to +1. A value of +1 means the vectors point in exactly the same direction, 0 means they are orthogonal and share no common direction, and −1 means they point in opposite directions. Embedding models are often trained so that unrelated text lands near 0 and related text scores well above it, though the exact scale depends on the model, and many models rarely produce strongly negative values.
Why do embedding searches use cosine similarity?
An embedding encodes meaning as a direction in a high-dimensional space, and two passages mean similar things when their vectors point similar ways, regardless of how long the passages are. Cosine similarity captures exactly that direction-only comparison.
It is also cheap to compute at scale: once vectors are normalized to unit length, cosine similarity reduces to a single dot product, which vector databases can evaluate across millions of entries quickly.
Disclaimer
A cosine similarity score is only meaningful relative to other scores from the same embedding model. There is no universal threshold that marks two items as “similar”; calibrate against examples from your own data before drawing conclusions.