Your vector search might be ranking the wrong result, and vector length is why.
Introduction
The Ranking Bug
Your search engine may be ranking the wrong result, and the bug is one word: dot product.
- Dot product can mislead
The Query Vector
Take a query vector pointing right. Call it q, with coordinates two and zero.
- q = (2, 0)
Document A
Document A points the exact same way. Coordinates one and zero. A perfect match.
- Same direction
- Short vector
Document B
Document B points forty-five degrees away, at three and three. Clearly less similar.
- 45 degrees off
- Much longer
Dot Product Scores
Now score them. Dot product gives A two, but B six. The long vector wins.
- A = 2
- B = 6
- Long vector wins
Cosine Ignores Length
Cosine ignores length. A scores one point zero. B scores about zero point seven one. Now A wins.
- A = 1.00
- B ≈ 0.71
Norm Is Not Meaning
Length is just magnitude, and magnitude can come from word frequency or noise, not meaning.
- Direction carries meaning
- Norm can be noise
The Rule: Normalize
The rule: if your embeddings were trained with cosine, normalize them to length one. Then dot product equals cosine.
- Cosine-trained? Normalize
- Unit length, then dot
Next: Similarity Metrics
Next lesson, we dig into similarity metrics. Follow so you don't miss it.
- Follow for more