1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
51 small wins to finish your pathNext question →
What is a vector database, and how do approximate nearest-neighbour (ANN) indexes like HNSW work?
30-second answerSay your answer out loud first, then reveal.
Main ANN index families
| Index | Idea | Strengths | Trade-offs |
|---|---|---|---|
| Flat (brute force) | Compare against every vector | 100% recall | Slow at scale; fine under ~100K vectors |
| HNSW | Multi-layer graph: sparse top layers for long jumps, dense bottom layer for fine search | Fast, high recall, supports inserts | Memory-hungry (graph + full vectors in RAM) |
| IVF | Cluster vectors (k-means); search only the nearest nprobe clusters | Lower memory, scalable | Recall depends on nprobe; needs training |
| PQ / quantization | Compress vectors into short codes | 4–32x less memory | Some accuracy loss; often combined (IVF-PQ) |
| DiskANN-style | Graph index on SSD | Billion-scale on one machine | Higher latency than in-RAM |
HNSW tuning knobs: M (neighbours per node: higher means better recall and more memory), ef_construction (build quality), ef_search (query-time accuracy vs speed).
Vector DB features beyond ANN: metadata filtering, hybrid (keyword + vector) search, CRUD and upserts, replication and sharding, multi-tenancy, backups.
Options: dedicated (Pinecone, Weaviate, Qdrant, Milvus, Chroma) or extensions of existing stores (pgvector for Postgres, Elasticsearch/OpenSearch, MongoDB Atlas, Redis).
Good answer about choosing. "If we already run Postgres and have under ~10M vectors, pgvector is often enough and avoids a new system. At larger scale, or with heavy filtering and hybrid needs, a dedicated engine makes sense."
Follow-ups to expect
- What happens to HNSW recall when you add restrictive metadata filters? It can drop, because the graph search gets cut off from neighbours. Engines handle this with filtered-HNSW, pre-filtering, or switching to brute force for small filtered sets.
Related
Little by little, you're building something great.