A retrieval system ranks documents by comparing a query vector against every document vector using cosine similarity, rather than the raw, unnormalized dot product between them. What property makes cosine similarity attractive for this purpose?
- It is always computationally faster than the dot product or Euclidean distance, no matter how large the vectors are
- It converts every embedding into a binary vector first, which speeds up the comparison using bitwise operations
- It only works correctly when every vector in the index has exactly the same number of dimensions as every other vector
- It measures the angle between two vectors rather than their length, so two embeddings pointing in the same direction score as highly similar even if one vector happens to have a larger magnitude than the other
Why D? And why not the others?
Correct answer: D. It measures the angle between two vectors rather than their length, so two embeddings pointing in the same direction score as highly similar even if one vector happens to have a larger magnitude than the other
Cosine similarity divides the dot product of two vectors by the product of their lengths, which cancels out each vector's magnitude and leaves only the cosine of the angle between them; this makes it well suited to comparing embeddings whose length can vary for reasons unrelated to meaning, such as differences in passage length, since two vectors pointing in nearly the same direction score as similar regardless of how long either one happens to be. The option claiming cosine similarity is always faster is wrong because computing it still requires essentially the same multiply-and-add arithmetic as a dot product, plus extra work to normalize by each vector's length; any speed difference in practice comes from indexing and hardware optimizations, not from the metric itself. The option describing a binary-vector conversion is wrong because cosine similarity operates directly on the original floating-point vectors rather than converting them into a binary representation. The option about requiring matching dimensionality is wrong because that requirement applies equally to the dot product and Euclidean distance, so it does not distinguish cosine similarity from the alternatives at all.
Source: Manning, Raghavan & Schutze, 'Introduction to Information Retrieval' (2008), Section 6.3, Vector Space Scoring, https://nlp.stanford.edu/IR-book/