All three rank by closeness, but they differ in how they treat a vector's magnitude, its length. Cosine similarity looks only at the angle, dot product also rewards longer vectors, and Euclidean distance measures the straight-line gap.
| Metric | Formula | Uses length? | Best score |
|---|---|---|---|
| Cosine | a·b / (|a| |b|) |
no | highest |
| Dot product | a·b |
yes | highest |
| Euclidean (L2) | |a - b| |
yes | lowest |
They produce the same ranking when every stored vector has the same norm, which in practice means embeddings normalized to length 1. Then cosine equals the dot product, and this identity ties in the third:
|a - b|^2 = 2 - 2 * (a·b) # for unit vectors
Distance falls as the dot product rises, so the order matches.
Once the stored norms match, the query's own norm never changes the order, because it scales every candidate's dot product equally. If document norms vary, dot product can push a long, loosely related vector above a short, on-topic one.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓