Vector Databases interview question

Generative AIVector Databasesmedium

Which statement about the HNSW parameters M, efConstruction and efSearch is correct?

  1. AefSearch and efConstruction are both fixed when the graph is built, so changing either needs a rebuild, while M can be adjusted per query to trade recall against latency without re-indexing.
  2. BefConstruction sets how many neighbours each query returns, so it must be at least k, while efSearch and M together control how many links each node keeps and so the memory footprint.
  3. CM affects build time but not recall or memory, because links per node are pruned back to a fixed default after construction; recall is set by efConstruction and efSearch.
  4. DM and efConstruction are build-time settings that shape graph connectivity, memory and build cost, while efSearch is a query-time setting you can tune per request without a rebuild.
Show the answer and explanation

Correct answer: D, M and efConstruction are build-time settings that shape graph connectivity, memory and build cost, while efSearch is a query-time setting you can tune per request without a rebuild.

Explanation Vector Databases

HNSW (Hierarchical Navigable Small World) builds a multi-layer proximity graph. A query enters at the sparse top layer, greedily moves towards the query vector, and descends to the dense bottom layer, where it keeps a candidate list of size efSearch and returns the best k.

ParameterSet atEffectTypical values
Mbuildlinks per node (2M at layer 0): higher recall ceiling, more memory, slower build16–64
efConstructionbuildcandidate list while inserting: better graph quality, slower build100–500
efSearch (ef)querycandidate list while searching (≥ k): recall ↑, latency ↑40–500

Because efSearch is a query-time knob, you can use different values per request, e.g. a higher value for an offline batch job or a premium tier. In pgvector it is the session setting hnsw.ef_search; in FAISS it is index.hnsw.efSearch.

Why the other statements are wrong: they swap the build-time and query-time roles of efSearch and M, confuse efConstruction with k and efSearch with the number of links per node, or claim M has no effect on recall or memory. Memory grows roughly linearly with M because every node stores up to 2M neighbour IDs at the bottom layer, and recall improves because the graph has more routes to the true neighbours.

Other practical points: HNSW is memory-resident, deletes are usually soft (tombstones) and degrade the graph over time, and very restrictive metadata filters can disconnect the traversal.

Interview tip: describe tuning as "choose M and efConstruction once for the recall ceiling and memory budget, then tune efSearch to hit the latency SLA".

Practice it as a quiz

Answer this and the other free questions with instant grading, streaks and weak-topic tracking, or unlock all 4,000 questions.

More Generative AI questions

  1. An e-commerce team writes product descriptions with a prompt that includes three example descriptions, all for one brand's running shoes. New descriptions for…
  2. What is a large language model (LLM)?
  3. What is the difference between zero-shot and few-shot prompting?
  4. What is retrieval-augmented generation (RAG)?
  5. What does it mean to fine-tune a pretrained LLM?