Imagine a support search system ranking articles for “cancel my order.” It converts the query and each article into vectors. A similarity score helps it decide which articles to show first. Change the scoring rule and the same candidates can appear in a different order.
Cosine similarity compares the direction of two nonzero vectors. It divides their dot product by the product of their lengths. Vectors pointing the same way score 1, perpendicular vectors score 0, and vectors pointing in opposite directions score −1. Multiplying either vector by a positive constant leaves the score unchanged. Scikit-learn’s cosine similarity reference.
Calculate one score by hand
Use two-dimensional vectors to make the calculation easy to inspect. Let the query be Q = (3, 4), with three candidate articles A = (6, 8), B = (4, 3), and C = (0, 5). These are illustrative coordinates, not outputs from an embedding model.

For Q and B, multiply corresponding coordinates and add them: (3 × 4) + (4 × 3) = 24. Both vectors have length √(3² + 4²) = 5. Dividing 24 by 5 × 5 gives a cosine similarity of 0.96.
A has twice the length of Q and points in exactly the same direction. Its dot product with Q is 50 and the product of their lengths is also 50, so its cosine score is 1. Candidate C gives 20 ÷ 25 = 0.80. The cosine ranking is A, then B, then C.
Why Euclidean distance can pick a different result
Euclidean distance measures the gap between the endpoints. B is one unit to the right and one unit below Q, so its distance is √2, about 1.41. A is five units away even though its direction matches Q exactly.
| Candidate | Cosine similarity ↑ | Euclidean distance ↓ | Dot product ↑ |
|---|---|---|---|
| A (6, 8) | 1.00 | 5.00 | 50 |
| B (4, 3) | 0.96 | 1.41 | 24 |
| C (0, 5) | 0.80 | 3.16 | 20 |

With these raw vectors, cosine picks A and Euclidean distance picks B. The raw dot product also picks A here, but its score grows with vector length when the cosine is positive. That can change the ordering in other examples.
What changes when you normalize the vectors?
L2 normalization divides a vector by its length to make it one unit long. Once every vector has unit length, dot product equals cosine similarity. Squared Euclidean distance becomes 2 − 2 × cosine similarity, so sorting by increasing distance produces the same exact ranking as sorting by decreasing cosine, apart from ties and numeric precision. Google’s comparison of embedding similarity metrics.
If you switch a real system from cosine to dot product, check both the stored vectors and the query vectors before comparing absolute scores. Search engines can also expose a distance or a transformed score. Confirm which direction is better in your index before setting a cutoff.
Check whether the ranking helps searchers
Use the same embedding model and compatible input configuration for queries and indexed articles. Start with the model’s recommended metric, then compare it on a labeled set of real search queries. Include different ways to ask the same question, short queries, and exact product or policy names. How a vector database retrieves similar documents.
Inspect the top few results for each query and look at the missed matches. A high cosine score tells you the vectors point in similar directions. A retrieved article may still describe an outdated policy or fail to answer the question. For a system that generates answers from retrieved passages, evaluate both retrieval and answer quality. How retrieval-augmented generation uses source passages.
Common questions
Is a cosine score of 0.80 always a good match?
Choose a cutoff on your own labeled examples. Scores vary with the embedding model, domain, and collection. If the system returns the top results without a cutoff, review weak queries where every candidate could be irrelevant.
What happens if a vector is all zeros?
The mathematical formula is undefined because it divides by length. Some libraries return a conventional value such as zero. Decide how your pipeline should handle empty inputs, and check the behavior of the library or index you use.
Is cosine distance the same score as cosine similarity?
A common definition of cosine distance is 1 minus cosine similarity. In that convention, smaller distance means a closer match. Check the exact score definition before comparing values across systems.

















