When would you choose cosine distance over Euclidean distance for nearest neighbor search?

Quick Overview

Asks when cosine distance is a better choice than Euclidean distance for nearest neighbor search. It tests whether you can tell when a vector's direction or its length carries the meaning, and how the choice affects text, embeddings and search indexes.

When would you choose cosine distance over Euclidean distance for nearest neighbor search?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

When would you choose cosine distance over Euclidean distance for nearest neighbor search? ```hint Scale one vector Multiply a vector by 10. Which of the two distances changes, and does that change mean anything for your data? ``` ```hint Normalize first Work out what Euclidean distance becomes once every vector has length 1. ``` ### What a Strong Answer Covers - What cosine distance measures and what it ignores - The kinds of data where a vector's direction carries the meaning, and the kinds where its magnitude matters - How cosine and Euclidean distance relate on normalized vectors, and why that matters for search indexes - Pitfalls such as zero vectors, magnitudes that carry real signal, and features on different scales ### Follow-up Questions - Your embedding model was trained with a dot-product objective. Would you normalize the vectors before search? - Distances between random points become similar in very high dimensions. Does switching to cosine fix that? - How would you run cosine search on an index that only supports Euclidean distance or inner product? - When would a centered cosine, such as Pearson correlation, be a better choice than plain cosine?

Overview: Asks when cosine distance is a better choice than Euclidean distance for nearest neighbor search. It tests whether you can tell when a vector's direction or its length carries the meaning, and how the choice affects text, embeddings and search indexes.

Nov 24, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

When would you choose cosine distance over Euclidean distance for nearest neighbor search?

What a Strong Answer Covers Guidance

  • What cosine distance measures and what it ignores
  • The kinds of data where a vector's direction carries the meaning, and the kinds where its magnitude matters
  • How cosine and Euclidean distance relate on normalized vectors, and why that matters for search indexes
  • Pitfalls such as zero vectors, magnitudes that carry real signal, and features on different scales

Follow-up Questions Guidance

  • Your embedding model was trained with a dot-product objective. Would you normalize the vectors before search?
  • Distances between random points become similar in very high dimensions. Does switching to cosine fix that?
  • How would you run cosine search on an index that only supports Euclidean distance or inner product?
  • When would a centered cosine, such as Pearson correlation, be a better choice than plain cosine?