mango = [0.9, 0.2, 0.8](encoding sweetness, sourness, and tropicalness). Different similarity metrics interpret these vectors in distinct ways and therefore produce different rankings. Cosine similarity Cosine similarity compares direction only. It measures the cosine of the angle θ between two vectors and is invariant to vector magnitude. Vectors that point in the same direction produce a cosine near 1, regardless of their lengths. How do the results look with cosine similarity? In this run, the ranking produced was: banana (clear winner), then orange, grapes, apple, and lemon last.

- Banana is the closest directional match to mango, so it wins under cosine similarity.
- Lemon finishes last because its embedding
lemon = [0.1, 0.95, 0.3]points in a very different direction (high sourness, low sweetness and tropicalness). The large angle between mango and lemon causes the cosine score to drop. - Some intermediate placements (e.g., grapes vs. apple) can be surprising — cosine cares only about direction and ignores scale.

find fruits similar to mango), the Euclidean ranking in this example is: banana, orange, apple, grape, and lemon.

- Banana remains closest under Euclidean distance.
- Notice the swap between apple and grape compared to the cosine ranking: cosine placed grape ahead of apple while Euclidean placed apple ahead of grape. This happens because Euclidean considers absolute coordinates; grape may point in a different direction but have coordinate values that place it slightly farther from mango than apple. Cosine missed that because it normalizes vector length first.

- Banana’s vector in this example is
banana = [0.45, 0.10, 0.47]. It points in a similar direction to mango but has a much smaller magnitude (roughly half the values). The dot product multiplies components directly and therefore penalizes small-magnitude vectors. Think of it as two people agreeing, but one is whispering — the dot product prefers the louder (higher-magnitude) match. - Papaya wins because its embedding has larger overall values (higher magnitude) that align well with mango; the magnitude compensates for small directional differences.

- Cosine focuses on direction only (ignores magnitude).
- Euclidean measures absolute spatial distance (magnitude and direction combined).
- Dot product emphasizes both alignment and magnitude (favoring larger vectors that point in the same direction).
| Metric | What it measures | When to use | Likely effect on ranking |
|---|---|---|---|
| Cosine similarity | Angle/direction between vectors | When only semantic direction matters (normalize embeddings first) | Favors vectors with similar direction regardless of length — good for semantics-only matches |
| Euclidean distance (L2) | Straight-line distance in embedding space | When absolute coordinates matter (magnitude carries semantic meaning) | Penalizes differences in absolute values — can reorder neighbors compared to cosine |
| Dot product | Alignment scaled by magnitude | When magnitude encodes importance or confidence | Rewards large aligned vectors — can push high-magnitude items to the top |
Choosing a similarity metric is a design decision, not just a configuration option. If your embeddings are not normalized, dot product results will be dominated by magnitude; Euclidean and cosine will produce different orderings. Consider whether you want direction-only matches (cosine), absolute-position matches (Euclidean), or magnitude-aware matches (dot product), and normalize embeddings if required by your use case.
- Vector databases and similarity search concepts
- Cosine similarity overview
- Euclidean distance (L2) definition