Once you have turned your documents into embeddings, you need to answer one question fast: which of these vectors is closest to the query vector? A vector database is the index built for that question.
What it actually does
Comparing a query against every stored vector is exact but linear. Vector databases trade a little accuracy for a lot of speed using approximate nearest neighbour search, which prunes most of the corpus without comparing against it. They also handle the surrounding plumbing: metadata filters, updates and deletes, and persistence.
The part people skip
For a few thousand chunks you do not need one:
import { cosineSimilarity } from 'ai'
// exhaustive search over an in-memory array
function search(queryVector, docs, k = 5) {
return docs
.map((d) => ({ ...d, score: cosineSimilarity(queryVector, d.embedding) }))
.sort((a, b) => b.score - a.score)
.slice(0, k)
}That is exact, has no infrastructure, and is fast enough that you will not notice it. Thousands of vectors compared in memory is not a bottleneck. Reach for a vector database when the corpus outgrows memory, needs concurrent writes, or needs filtered search at scale, not because the tutorial used one.
What to look at when you do need one
- Metadata filtering. Restricting to one tenant, project, or date range is usually the feature you need most, and implementations differ a lot in how well they combine filtering with search.
- Update and delete semantics. Corpora change. Some indexes make deletion expensive.
- Whether it does keyword search too, which decides whether hybrid search is one system or two.
Related terms
Embeddings
An embedding turns a piece of text into a list of numbers that captures its meaning, so that similar ideas land near each other. Embeddings are what let you search by meaning instead of by exact keyword.
Read definition →PatternProvenRetrieval-augmented generation (RAG)
RAG is the workhorse pattern of context engineering: retrieve the material relevant to a request, put it in the context, and let the model generate an answer grounded in it rather than guessing from memory.
Read definition →ConceptChunking
Chunking is splitting a long document into smaller pieces before you embed and retrieve them. The size and overlap of the chunks decide what can be found as a unit, so it quietly makes or breaks a retrieval system.
Read definition →PatternValidatedHybrid search
Hybrid search runs a keyword search and a vector search over the same corpus and merges the two result lists. It exists because embeddings are good at meaning and bad at exact strings, and keyword search is the other way round.
Read definition →