When should you use cosine similarity versus dot product versus Euclidean distance for vector search?
Cosine similarity measures the angle between vectors and ignores magnitude, so it's the default when embeddings encode direction (semantic meaning) but vary in length. Euclidean (L2) distance measures straight-line distance and is sensitive to magnitude. Dot product combines both direction and magnitude; it rewards larger-norm vectors. The key rule: match the metric your embedding model was trained with. Many models (e.g. OpenAI, sentence-transformers) produce normalized or near-normalized vectors, and when vectors are unit-normalized, cosine, dot product, and Euclidean rank neighbors identically, so the choice mainly affects speed and index compatibility. Dot product is common in maximum-inner-product-search (MIPS) setups where norm carries signal. Always normalize consistently at index and query time.