What is a vector database?
A database built to store embeddings and quickly find the ones closest to a query, which is how AI apps search by meaning.
intermediate · Also called Vector Store
An ordinary database answers exact questions. Which orders came from Leeds? Which customer has this email address? A vector database answers a fuzzier one: which stored items are most like this?
It does that with embeddingsEmbeddingA list of numbers that stands for the meaning of a piece of text, an image or other data. Things with similar meaning get similar numbers, so a computer can find them., lists of numbers that stand for meaning. Every document, product or image you store is turned into one of these lists. When a question comes in, it is turned into a list the same way, and the database returns the stored lists nearest to it. Near in numbers means near in meaning.
Where you meet one
Most AI apps that answer from your own documents use one. In RAGRAGA way to answer from your own documents. A search finds the passages that match the question, and they are added to the prompt before the model writes., documents are cut into chunks, each chunk is embedded and stored, and at question time the vector database hands back the closest chunks for the model to read. The same trick drives "similar products", duplicate detection and search that understands what you meant rather than what you typed.
The hard part is speed
Finding the nearest neighbour is easy with a small collection: compare the question with every one. With millions of lists, each 1,536 numbers long (the size of OpenAI's smaller embedding model), checking them all is too slow.
So vector databases build an index that finds nearly the closest items, very fast. This is approximate nearest neighbour search. The documentation for pgvector, an open-source add-on for Postgres, states the trade-off plainly: an index trades some recall for speed. Now and then the true best match is skipped.
One index type, HNSW, builds a layered graph that search can hop through. pgvector notes it gives a better balance of speed and recall than the older IVFFlat index, at the price of slower builds and more memory.
Do you need a separate product?
Not always. Dedicated vector databases exist, but pgvector lets Postgres store vectors right next to your other data. For a modest collection, keeping everything in the database you already run is often simpler.
What it cannot do alone
A vector search finds what is about the same thing, and can miss an exact term such as a product code or an error number. Good search systems run an ordinary keyword search alongside it and merge the results, which is what Anthropic does in its own retrieval setup.
So when an AI app "can't find" something you know is in your files, try the exact phrase. You may be watching the gap between meaning and spelling.
Sources
Where each fact comes from
This page was last checked against these sources on 14 October 2026.
- 1pgvector
pgvector, on GitHub · 14 October 2026
pgvector is open-source vector similarity search for Postgres, and stores vectors with the rest of your data. It supports exact and approximate nearest neighbour search, and queries are exact by default. Adding an index gives approximate nearest neighbour search, which trades some recall for speed. HNSW builds a multilayer graph and has better speed-recall performance than IVFFlat, with slower builds and more memory. Distance functions include L2, inner product and cosine distance.
- 2Introducing Contextual Retrieval
Anthropic · 19 September 2024
In RAG, documents are split into chunks, an embedding model turns each chunk into a vector, and a vector database finds the chunks closest in meaning to the query. Embedding search can miss exact matches such as an error code, which keyword search (BM25) finds, and the 2 are combined.
- 3Vector embeddings
OpenAI API documentation · 14 October 2026
An embedding is a list of numbers, and the distance between 2 of them measures relatedness. By default text-embedding-3-small produces 1,536 numbers. Cosine similarity is recommended.