ORIGINAL TECHNICAL PRACTICE
Choose and evaluate an embedding similarity
Why can dot product and cosine similarity produce different nearest neighbors, and how would you choose between them?
Written for independent practice. The model answer presents one approach; clarify constraints and explain alternatives.
A REASONED APPROACH
Model answer.
Cosine similarity compares direction after accounting for vector magnitude; dot product also reflects magnitude. When vectors are unit-normalized, their dot product equals cosine similarity, but a model’s recommended setup still matters.
Work through it
- Confirm how the embedding model was trained and whether its documentation expects normalization, a particular query prefix or a specific similarity function.
- Evaluate the complete retrieval pipeline on labelled relevance examples. Include short and long texts, domain terms and cases where lexical matching is important.
- Keep embedding model and dimension changes versioned. Re-embed the corpus when necessary rather than mixing vectors from incompatible representations.
Tradeoffs to discuss
- Approximate nearest-neighbor indexes trade retrieval fidelity for speed and memory. Hybrid lexical/vector retrieval can help exact identifiers, but requires its own ranking evaluation.
Common pitfalls
- Comparing scores across different models as though they share a calibrated scale is unreliable. Zero vectors need explicit handling when computing cosine similarity.