Machine Learning Engineer Interview Question

How does approximate nearest neighbor search work, and what do you trade away for the speed?

What the interviewer is probing, how to structure your answer, and a spoken example you can adapt.

Quick answer

Exact search compares a query against every vector, which is linear in corpus size. ANN indexes such as HNSW or IVF build a structure (a navigable graph, or a set of clusters) that visits only a small candidate subset, giving sublinear query time. You trade exact recall: some true nearest neighbors get missed. Parameters such as efSearch or nprobe move you along the recall versus latency curve.

Why interviewers ask this

Vector retrieval sits under most current recommendation and RAG systems, so interviewers want to know you understand the index rather than treating the database as magic. The key answer is that the approximation lands in recall, and that recall is a tunable dial. Naming a concrete parameter and describing how you measure recall against an exact brute force baseline is what separates real experience here.

How to structure your answer

  • Contrast an exact linear scan with the index structure.
  • Explain in one line how HNSW or IVF narrows the candidate set.
  • Name the tradeoff as recall, and say it is tunable.
  • Describe how you measure recall against an exact baseline.

Example answer

Spoken example, first person

Exact search means comparing the query against every vector, which is fine at a hundred thousand and hopeless at a hundred million. ANN indexes cut the candidate set. HNSW builds a layered proximity graph and greedily walks it from a sparse top layer down to a dense bottom one, so you touch a few thousand nodes instead of the whole corpus. IVF clusters the space first and only searches the nearest few clusters. Either way, what you give up is recall: sometimes the true nearest neighbor sits just outside the region you explored. The important part is that it is a dial. In HNSW, efSearch controls how wide the beam is; in IVF, nprobe controls how many clusters you open. I always build a small ground truth set, a few thousand queries scored by brute force, then sweep that parameter and plot recall at ten against p99 latency. On the last system I tuned, going from 95 to 99 percent recall tripled latency and moved the downstream click rate by almost nothing, so we sat at 95. I also monitor recall, because it degrades quietly after big index rebuilds.

Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.

See how it works

Follow-up questions to expect

  • How does product quantization reduce memory, and what does it cost you?
  • What changes when the index has to support frequent deletes?
  • When would hybrid keyword plus vector search beat vector alone?

Related machine learning engineer questions

Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.

Predict my questions

Rehearse the hard questions before they are asked

Practise with a live copilot, then walk in ready. A $29 Session Pass gets you through the interview with no subscription and no lock-in.

Get GhostPilot