RAGcore
Vector indexes: HNSW, IVF, flat
Approximate nearest-neighbour structures that trade a little recall for a lot of speed.
What it is and why it exists
Flat search compares the query with every vector: exact, O(N). HNSW builds a layered proximity graph and greedily walks it — fast, high recall, memory-hungry, tuned with M (links per node) and ef (search breadth). IVF clusters vectors with k-means and searches only the nprobe nearest clusters — lighter, recall depends on nprobe.
Quick prototype
Flat search in memory or pgvector without an index.
In production, at scale
HNSW for most low-latency workloads, IVF (often with product quantisation) for very large or cost-sensitive corpora, tune ef_search/nprobe against measured recall, and plan for filtered search (metadata + vector) which most indexes handle less gracefully.
Vendors and tools
| pgvector | HNSW and IVFFlat inside Postgres |
|---|---|
| Pinecone / Weaviate / Qdrant / Milvus | Managed or self-hosted vector databases |
| FAISS | Library of flat, IVF, PQ and HNSW indexes |
| Elasticsearch / OpenSearch | kNN fields alongside BM25 |
On AWS: OpenSearch Serverless vector collections, Aurora PostgreSQL with pgvector, Amazon S3 Vectors for cheap large-scale storage, MemoryDB for low-latency vector search.
How it fails
- Default ef/nprobe giving 85% recall and nobody measured
- Restrictive filters + HNSW returning too few results
- Index rebuilds blocking writes
What the interviewer asks next
HNSW vs IVF in one sentence?
HNSW walks a graph and gives high recall at low latency for more memory; IVF searches a few clusters, is cheaper and easier to shard, and recall depends on how many clusters you probe.
How do you know your ANN index is good enough?
Compute exact top-k with flat search on a sample of queries and measure the ANN index’s recall against it while sweeping ef_search or nprobe.