A vector database stores each chunk's embedding next to its text and metadata, and returns the chunks nearest to a query vector. Its core trick is an approximate nearest neighbor (ANN) index, which finds close matches without scanning every vector. In RAG, the chunks it returns become the LLM's context.
Comparing the query against every stored vector is a brute-force or flat scan. It is exact, and it is fine for a few thousand vectors. But the cost grows linearly with the corpus. Five million vectors at 1536 dimensions is about 7.7 billion multiply-adds per query.
An ANN index keeps the cost per query nearly flat as the corpus grows. It usually finds 95 percent or more of the true nearest neighbors. The database also handles filters, updates and persistence, which an in-memory array leaves to you. So you trade a little recall for a large speed win.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓