Under what data size and latency conditions is KNN a suitable choice for a production service?

Quick Overview

Asks when k-nearest neighbors is a reasonable choice for a production service given the data size and latency budget. Tests per-query cost reasoning, exact versus approximate nearest neighbor search, memory sizing, and the conditions that make KNN a poor fit.

Under what data size and latency conditions is KNN a suitable choice for a production service?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

K-nearest neighbors keeps the training data and searches it at prediction time. Under what data size and latency conditions is KNN a suitable choice for a production service? ```hint Write the cost model Express the work and memory per query in terms of the number of stored points and their dimension, then compare that with the latency budget. ``` ```hint Exact versus approximate Consider what you give up, and what you gain, when the search does not have to return the true nearest neighbors. ``` ### What a Strong Answer Covers - Per-query compute and memory cost in terms of the number of points and the dimension - Rough size ranges where exact search meets a latency budget, and when approximate indexes are needed - Workloads and data properties that favor KNN - Conditions where KNN is a poor choice - Levers that bring a borderline case within budget ### Follow-up Questions - How would you measure the recall of an approximate index, and what recall would you accept? - How does HNSW trade memory and build time for query speed? - How would you serve KNN at 1,000 queries per second over 50 million embeddings? - Why do distances lose contrast in high dimensions, and what does that do to KD-trees?

Overview: Asks when k-nearest neighbors is a reasonable choice for a production service given the data size and latency budget. Tests per-query cost reasoning, exact versus approximate nearest neighbor search, memory sizing, and the conditions that make KNN a poor fit.

PracHub logo
General
Nov 24, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

K-nearest neighbors keeps the training data and searches it at prediction time. Under what data size and latency conditions is KNN a suitable choice for a production service?

What a Strong Answer Covers Guidance

  • Per-query compute and memory cost in terms of the number of points and the dimension
  • Rough size ranges where exact search meets a latency budget, and when approximate indexes are needed
  • Workloads and data properties that favor KNN
  • Conditions where KNN is a poor choice
  • Levers that bring a borderline case within budget

Follow-up Questions Guidance

  • How would you measure the recall of an approximate index, and what recall would you accept?
  • How does HNSW trade memory and build time for query speed?
  • How would you serve KNN at 1,000 queries per second over 50 million embeddings?
  • Why do distances lose contrast in high dimensions, and what does that do to KD-trees?