Cosine similarity & dot product calculator
See why a larger vector can outrank a more aligned one. Compare two candidates and inspect what changes when the query, documents or both are normalized.
Compare a query with two documents
Use invented coordinates. Calculations run in this page; this tool does not save input or put it in the URL. Controls are masked from optional session recording. Other page scripts and browser extensions remain outside these guarantees.
Scores and normalization
2 dimensions · Query norm: 1
Raw dot: B ranks first · Cosine: A ranks first
| Measure | Document A | Document B |
|---|---|---|
| Document norm | 1 | 5 |
| Raw query · raw document | 1 | 4 |
| Unit query · raw document | 1 | 4 |
| Raw query · unit document | 1 | 0.8 |
| Unit query · unit document (cosine) | 1 | 0.8 |
| Squared L2 between unit vectors | 0 | 0.4 |
Unit means divided by its own Euclidean norm. Displayed numbers use nine significant digits. Rankings treat scores as tied when their difference is at most 1e-12 × max(1, |A score|, |B score|); tiny raw scores can therefore tie. The report includes unrounded floating-point values.
A cosine score is not a relevance probability. These calculations do not generate embeddings or search a vector database. Use vectors from the same compatible embedding space when investigating real systems.
Copy the calculation report
Try the ranking reversal
The default query is [1,0]. Document A is [1,0] and B is [4,3]. Raw dot products are 1 and 4, so B ranks first. Cosine scores are 1 and 0.8, so A ranks first. These are invented coordinates that illustrate geometry, not measured document relevance.
Normalization changes the score contract
For nonzero vectors, cosine is dot(q,d) divided by the product of their norms. With unit vectors on both sides, dot product equals cosine. Normalizing only the query retains document magnitude. Normalizing only documents gives cosine ranking for a fixed nonzero query, but scores retain the query’s scale.
Zero vectors and numerical limits
Raw dot product is defined for zero vectors. This calculator marks cosine, affected unit-vector scores and unit squared distance undefined instead of assigning a direction to zero. Input bounds keep arithmetic finite. Browser numbers use floating-point arithmetic, so rounding and cancellation still matter; this is not an arbitrary-precision calculator.
Similarity and distance run in opposite directions
Higher cosine or dot product ranks first. For unit vectors, squared Euclidean distance equals 2 minus twice cosine, so lower is closer. Squared distance and Euclidean distance have different numeric values even when they produce the same order.
Read the normalization guide and run the Python lab →
Evaluate labeled retrieval rankings with recall, MRR and nDCG →