Retrieval & RAGintermediate13 min · 9 steps
Vector Databases
How a vector database finds nearest neighbours among millions of embeddings in milliseconds — and what that costs in RAM, recall and operations.
recall100%
RAM / copy (100M)614GB
requestdata
metrics are illustrativeProblemStep 1 of 9
Exact search compares the query with every vector
The honest way to find the nearest neighbours is to compute the distance from the query to every stored vector: O(n·d) per query, with perfect accuracy.
That is fine up to about 1M vectors (pgvector with no index does exactly this). Past that, every query scans the whole corpus — and RAG corpora grow into hundreds of millions of chunks.
TipFor under ~100K vectors, or when accuracy is critical and the latency budget is generous, a flat (brute-force) index is the right answer.
Lesson 4 of 37 in Retrieval & RAG