A customer types into your help center: "can I get my money back if my plan renewed by mistake?" Your policy page talks about refunds, cancellation windows and billing adjustments. Not one of the customer's key words shows up in it, so keyword search comes back with a shrug. Anyone on the support team would connect the two in a second.
Vector databases exist for that gap. They let a system search by meaning, so "money back" can find "refund". This post goes through what's inside one, the choices that matter when you build on it and the spots where it trips up. If you're coming from RAG Basics, this is the layer underneath.
Embeddings: meaning as coordinates
An embedding is a list of numbers that an embedding model produces from a piece of content: a paragraph, a product description, an image, a code snippet. Content with similar meaning should end up with similar numbers. OpenAI's text-embedding-3-small, for example, returns 1,536 numbers per input and text-embedding-3-large returns 3,072 (OpenAI embeddings guide, checked November 2026). Nobody reads those numbers directly. They're coordinates in a space with that many dimensions, and the picture above squashes the idea down to two.
"Close" needs a definition, so you pick a distance function: cosine similarity, dot product or Euclidean distance. OpenAI's guide recommends cosine similarity and notes that its embeddings are normalized to length 1, so cosine and dot product give the same ranking, and Euclidean distance does too. That's why the guide says the choice typically doesn't matter much for its embeddings. With a model that isn't normalized, the metric matters more, so use whatever its docs recommend. The wrong one can rank results slightly off while they still look plausible, and that's hard to spot.
Worth saying plainly: the database has no idea what anything means. It measures distance between lists of numbers. The sense of similarity comes from the embedding model, which learned it from training data. So when search quality is bad, swapping the database rarely fixes it. Look at the embedding model, the chunks you feed it and the filters around it.
Why it's fast: approximate search
The simplest way to find the nearest vectors is to compare the query against every stored vector. That's exact search, and for a few thousand items it's perfectly fine. At millions it gets slow, so vector databases build an approximate nearest neighbor (ANN) index that checks a small part of the data and usually finds the right neighbors.
A popular one is HNSW, from a 2016 paper by Yury Malkov and Dmitry Yashunin (Hierarchical Navigable Small World graphs). It links each vector to its near neighbors across a stack of graph layers. A search starts in the sparse top layer, jumps somewhere close to the target, then walks down into denser layers to narrow it in. The authors report search cost that grows logarithmically with the size of the data.
"Usually" is the important word. The docs for pgvector, the Postgres extension (version 0.8.7 as of November 2026), put it plainly: exact search gives perfect recall, and adding an index "trades some recall for speed" (pgvector README). They also compare the two index types pgvector ships. HNSW has the better speed-recall trade-off but builds slower and uses more memory. IVFFlat builds faster and uses less memory but gives up more recall at the same speed.
Take a sample of real queries, run each one with exact search and again through your index, and compare the top 10 results. The overlap is your recall at 10. Run it again after every index or parameter change, and you'll know what speed is costing you.
Filters are where demos and products part ways
In a real product, closest in meaning isn't enough. A document has a locale, a product version, an access level, an owner, a date and a status. You want the closest chunks this user is allowed to see, in their language, from the current policy. That's metadata filtering, and plenty of first versions get it wrong.
The pgvector docs give a concrete example of the trap. With an approximate index, the filter runs after the index scan. If a condition matches 10% of rows and HNSW uses its default candidate list of 40, only about 4 rows will match on average. You asked for 10 results, got 4 and saw no error. Version 0.8.0 added iterative index scans, which keep scanning until enough rows pass the filter, and partial indexes or partitioning help too. Other vector databases handle filters their own way, so read how yours does it before you trust a filtered query.
Access rules need extra care. If a user can't open a document, its chunks shouldn't reach the model either. Filter on permissions at query time, every time, and test with an account that has fewer rights than yours.
Pair it with keyword search
Meaning-based search is great at paraphrase and weak at exact strings. Error codes, SKUs, people's names and version numbers are where keyword search shines. Many production setups run both and merge the lists. pgvector's docs suggest pairing it with Postgres full-text search and merging the results with Reciprocal Rank Fusion or a cross-encoder reranker. RRF comes from a 2009 paper by Gordon Cormack, Charles Clarke and Stefan Büttcher (Reciprocal Rank Fusion) and fits in one line: every list a document appears in gives it 1 / (k + its rank), with k = 60 in the paper, and you add those up. The RAG Basics post has Anthropic's numbers on how much keyword search and reranking cut missed retrievals.
Freshness, deletes and cost
Docs change and policies expire. If a source changes and its embeddings don't, your index keeps answering from an older version of your company. You need an ingestion pipeline that re-embeds changed documents, a way to delete chunks when a document is removed (or when someone asks you to delete their data), and a source version stored with every chunk so any answer can be traced back to exactly what produced it.
Switching embedding models means re-embedding everything, because vectors from two different models don't share a space. Plan for that before you choose one.
Storage adds up faster than people expect. In pgvector each vector takes 4 bytes per dimension plus 8 bytes. A million chunks at 1,536 dimensions comes to about 6.2 GB before any index, and HNSW needs more memory on top. pgvector's halfvec type halves the per-dimension cost, and OpenAI's embedding API can return shorter vectors through its dimensions parameter, giving up some accuracy for size.
Do you need a separate vector database?
Often not on day one. If you already run Postgres, pgvector keeps vectors next to the rest of your data, with the same backups, permissions and joins. A dedicated vector database starts to make sense when scale, filter speed or operational needs outgrow that. Either way, the questions that decide quality stay the same: what users need to find, which boundaries the search has to respect and how you'll know retrieval is right.
Try this week
- Check which distance function your embedding model's docs recommend, and confirm your index uses the same one.
- Run a sample of real queries through exact search and through your index, then measure the overlap.
- Try one query with a narrow filter and count how many results actually come back.
- Write down what happens to a chunk when its source document is edited or deleted. If nobody knows, start there.