passdrill
AI & LLM Engineering · RAG & Embeddings · Card 005/012 easy

A vector index built with the HNSW algorithm returns the top-k most similar vectors to a query in a few milliseconds even when the index holds tens of millions of vectors, but occasionally misses a vector that an exhaustive, compare-against-everything search would have found. What best explains this trade-off?

  1. HNSW is an approximate nearest-neighbor algorithm: it searches a multi-layer navigable graph structure to reach a good answer quickly, accepting a small chance of missing the true nearest neighbor in exchange for search times far faster than comparing the query against every stored vector
  2. HNSW deletes any vector it judges to be a near-duplicate of another vector already in the index, so the missed vector was likely removed while the index was being built
  3. HNSW indexes only a random sample of the uploaded vectors and ignores the rest, so vectors outside that sample can never be returned by any query
  4. HNSW rounds every vector's coordinates to a lower numeric precision before storing them, and the missed vector's true nearest neighbor was lost during that rounding step
Next card → Shuffle