
- d is the Euclidean distance between the query and another vector — how far apart they are in space.
- θ (theta) is the angle between vectors — the directional difference.
- Increasing arrow length increases magnitude; rotating the arrow changes angle. Both affect different metrics in different ways.
| Metric | Formula | What it emphasizes | ||||
|---|---|---|---|---|---|---|
| Cosine similarity | `cosine_similarity(a, b) = (a · b) / ( | a | b | )` | Direction/angle only — ignores magnitude after normalization | |
| Euclidean distance | `euclidean_distance(a, b) = | a - b | = sqrt((a1-b1)^2 + (a2-b2)^2)` | Absolute proximity in embedding space — shortest straight-line distance | ||
| Dot product | `dot_product(a, b) = a · b = | a | b | cos(θ)` | Combination of magnitude and alignment — rewards both length and angle |
- Intuition: after normalization, only the angle matters. Two vectors with the same direction are highly similar even if their lengths differ.
- Ranking behavior: whichever stored vector has the smallest angle with Q ranks highest, regardless of vector length.

- If Q rotates toward A, cosine similarity favors A.
- If Q rotates toward B, B may outrank A even if Q is farther from B in Euclidean terms — cosine cares about direction.
- Intuition: the closer two points are in space, the higher the similarity (lower the distance). Angle alone doesn’t matter.
- Ranking behavior: the vector with the smallest straight-line distance to Q becomes the top hit.
- Intuition: combines both magnitude and alignment. Large aligned vectors get high scores; a very long vector can outrank a shorter one even with a slightly worse angle.
- Ranking behavior: balances length and angle — useful when embedding magnitudes encode importance or confidence.

- Cosine similarity: whichever stored vector minimizes θ with Q will rank highest.
- Euclidean distance: whichever stored vector has the smallest
||a - q||ranks highest. - Dot product: a combination — a moderately close vector with a large magnitude and good alignment can outrank a closer but smaller vector.
Remember: similarity search returns a ranked list, not a single winner. The chosen metric changes result ordering and so directly impacts downstream tasks like retrieval, recommendation, or reranking.
- Cosine similarity: direction-focused, magnitude-invariant — use when vector orientation is what encodes semantics.
- Euclidean distance: proximity-focused — use when absolute position in embedding space matters.
- Dot product: magnitude + alignment — use when embedding scale carries meaning (e.g., TF-IDF‑style weighting or confidence).