Retrieval
How AI Stores and Retrieves Meaning at Scale
14 min read · Reviewed August 06, 2026

A vector database stores and searches numerical vectors, the embeddings that represent the meaning of text, images, audio, or products, and is built to answer one deceptively simple question at scale: of the millions or billions of items I hold, which few are most similar to this one?
Traditional databases find records that match exact criteria. A vector database instead finds records whose meaning is closest to a query, by comparing high-dimensional vectors. Doing that exactly would mean comparing the query against every stored vector, which is too slow past a few hundred thousand items. So vector databases lean on approximate nearest-neighbor indexes (mainly HNSW and IVF) plus compression techniques like quantization, to return very-close matches in milliseconds while accepting a tiny, tunable loss of accuracy. Everything interesting about these systems flows from that one trade-off.
Why exact search breaks down
To see why a specialized database is needed at all, it helps to watch ordinary search fail. Once content is turned into embeddings, both recommendation and semantic search reduce to one operation: hand the system a query vector and ask which stored vectors sit closest to it, out of millions or billions. Computing that exactly is too slow at scale, which is why the whole field leans on approximate nearest-neighbor (ANN) search instead.
The naive method, often called a flat or brute-force search, compares the query against every vector in the collection, one at a time. It is perfectly accurate, and for small datasets it is the right choice. But the cost grows linearly with the number of vectors and with their dimensionality. Answering it exactly means computing the distance between the query and all N stored vectors, which works out to O(N·d) time for a collection of N vectors of dimension d, which becomes untenable for high-workload systems holding large collections. A single modern embedding at 1,536 dimensions and full precision already occupies around six kilobytes; multiply that by a billion records and the arithmetic alone explains why a different approach is required.
This is the shift that defines the whole category. A conventional database answers a crisp yes-or-no question — does a record matching these exact criteria exist? A vector database answers a fuzzier and more useful one — which records come closest in meaning to this one? The distinction matters because so much modern data (documents, images, user behavior, audio) has no meaningful "exact match" to search for in the first place.
The anatomy of a vector database
The terms "vector index," "vector store," and "vector database" are often used interchangeably, but they describe different layers of the same system, and keeping them distinct clarifies what you are actually choosing when you adopt one. A vector index is the data structure that searches vectors efficiently. A vector store persists vectors and their identifiers. A vector database typically wraps both and adds the machinery you expect from a database: metadata, filtering, updates, replication, access controls, and operational management.
| Component | Responsibility |
|---|---|
| Embedding model | Turns content and queries into vectors. Lives outside the database, but its choices constrain everything downstream. |
| Vector store | Persists the vectors alongside references to the original content and its metadata. |
| Vector index | Finds approximate or exact nearest neighbors quickly. This is where HNSW, IVF, and quantization live. |
| Query engine / retriever | Builds the query vector, applies metadata filters, and returns usable records to the application. |
The original content, whether text, image, product, or document, usually remains available beside its vector, so the application can display or act on whatever the search returns. The vector is a coordinate; the record is the thing you actually wanted.
Choosing how to measure closeness
Before an index can find "nearby" vectors, it needs a definition of near. Three distance metrics dominate, and the choice is not cosmetic — it changes which results come back.
Cosine similarity
Measures the angle between two vectors, ignoring their length. The default for text and semantic search.
Dot product
Rewards both alignment and magnitude. Useful when length itself carries a signal, like popularity.
Euclidean (L2)
Straight-line distance. Natural for count-based or spatial data; sensitive to magnitude.
Cosine similarity is the workhorse for text because it cares only about direction. Cosine treats long and short documents alike, judging only whether the right things line up in direction, while the dot product is swayed by raw magnitude. That distinction matters more than it first appears. The dot product also has a genuinely strange property: a scaled-up copy of a vector can score as closer to it than the vector is to itself. It is as if a city were not its own nearest city. A longer document can score as "more relevant" simply for being longer, which is rarely what a searcher wants.
The crucial practical rule is to match the metric to the model that produced the embeddings. As a rule of thumb, the best-performing metric is the one the embedding model was trained with. A model trained with cosine loss will behave best under cosine similarity. And there is a shortcut worth knowing: once vectors are normalized to unit length, magnitude drops out of the picture entirely, and cosine similarity and the dot product become mathematically identical. This is why many databases implement cosine as a one-time normalization followed by a faster dot product.
Magnitude is not always noise to be discarded. If the length of an embedding encodes something you care about, like the popularity of a product or the frequency of an event, then dot product or Euclidean distance will preserve that signal, while cosine similarity will wash it away.
The core trick: approximate search
Everything distinctive about vector databases rests on a single bargain. Instead of guaranteeing the exact nearest neighbors, they find almost the nearest ones, far faster. Approximate nearest-neighbor algorithms give up a sliver of accuracy (measured as recall) in exchange for order-of-magnitude speedups, sometimes around a hundredfold. The idea is to build an index that lets a search leap straight to the promising regions of the space instead of scanning all of it.
A useful mental image: finding a book in a vast library. Brute-force search means opening every book until you find the right topic. Indexed search means using the catalog: you might occasionally miss the single best match, but you land very close, in a fraction of the time. The knob that controls this is recall: the fraction of the true nearest neighbors that the approximate search actually returns. Push recall toward 100% and you approach brute-force accuracy and cost; relax it slightly and latency collapses.
These algorithms come in four broad families, and most production systems use one of the first two, sometimes combined with the third. They fall into roughly four families: graph-based methods like HNSW and Vamana, partition-based methods like IVF and locality-sensitive hashing, quantization-based methods like product quantization, and tree-based methods like ANNOY and k-d trees.
HNSW, the industry default
Hierarchical Navigable Small World graphs have become the near-universal default. Open-source vector databases including Elasticsearch, Pinecone, Weaviate, and Qdrant have all settled on HNSW as their core index. It was introduced by Yury Malkov and Dmitry Yashunin, whose 2016 paper described a new approach for approximate K-nearest neighbor search based on navigable small world graphs with controllable hierarchy.
The structure is easier to grasp as a picture than a formula. Imagine a stack of maps of the same territory. HNSW builds a graph of several stacked layers in which every vector is a node linked to its nearest neighbors. The upper layers are sparse, good for covering large distances in a few hops; the lower layers are dense, good for pinning down the exact closest points. A query threads through this graph, hopping steadily toward its nearest neighbors. A search starts at the sparse top, takes a few big leaps across the space, then drops layer by layer into progressively denser neighborhoods until it settles on the closest matches at the bottom.
The design borrows a trick from skip lists: each element is assigned a maximum layer at random, drawn from an exponentially decaying distribution, so the top layers stay sparse and the bottom layer holds everything. That scale separation is what buys the speed: beginning the search at the top and exploiting that separation of scales is what lets the algorithm scale logarithmically rather than linearly.
HNSW's reputation is earned but not free. It is fast and delivers excellent recall, but it is hungry for memory. Two parameters govern its behavior: M, the number of connections each node keeps, and ef, the size of the candidate list explored during a search. Larger values raise recall at the cost of memory and latency. The memory appetite is real: as collections grow into the billions, its memory footprint balloons, the cost of distance computations starts to dominate query time, and its performance wobbles on unevenly distributed data. That pressure is exactly what quantization, below, exists to relieve.
IVF and partition-based search
The main alternative takes a different route: instead of building a graph, it divides the space into regions and only searches the relevant ones. IVF carves the space into clusters up front, typically with k-means, and at query time it searches only the handful of clusters nearest the query rather than the whole collection. That works beautifully when the data falls into clean clusters, and less well when it does not; accuracy hinges on how faithfully the cluster centroids represent the underlying data.
The trade-off against HNSW is straightforward. IVF is lighter on memory than HNSW, but it tends to be a little slower and needs an upfront training pass to compute its clusters. That training step is a meaningful operational difference: the clustering has to be computed up front and can drift as data changes, whereas a graph index grows incrementally as vectors arrive. The rule of thumb most teams settle on: reach for HNSW when speed and high recall matter and memory is available, since it is the strongest general-purpose option for most production workloads. IVF earns its place when memory is the binding constraint or the data clusters cleanly.
Quantization: trading precision for scale
Indexes decide which vectors to compare; quantization shrinks the vectors themselves. It is the lever that makes billion-scale collections affordable, and it comes in three flavors that sit at different points on the memory–accuracy curve.
| Method | How it works | Typical compression |
|---|---|---|
| Scalar | Maps each 32-bit float dimension to an 8-bit integer. | ~4x (75% memory saved) |
| Product | Splits vectors into sub-vectors, each encoded against its own codebook of centroids. | up to ~32–64x |
| Binary | Reduces each dimension to a single bit, above or below a threshold. | up to ~32x, fastest search |
Scalar quantization is the sensible default. It rounds each dimension down to an 8-bit integer, cutting memory by about three-quarters, and holds up across most workloads with barely any recall lost. It even tends to be faster, not just smaller: comparing int8 values is computationally cheaper than comparing full floats, and the error it introduces is usually under one percent, shrinking further for high-dimensional vectors.
Product quantization pushes compression much harder. Split a 1,024-dimensional vector into 128 sub-vectors and each collapses to a single byte, so the whole thing stores in 128 bytes, roughly 32x smaller, and up to 64x in aggressive configurations. The catch is that its distance math is less hardware-friendly: its distance math does not map cleanly onto the CPU's vector instructions, so it runs slower than scalar quantization and gives up more accuracy, which is why it is usually reserved for high-dimensional vectors where the compression is worth it. It is the tool for billion-vector corpora where memory is the hard limit.
Binary quantization is the most aggressive of the three. It collapses each dimension to a single bit depending on whether it lands above or below a threshold, which enables extremely fast comparison via Hamming distance but discards the most information. In practice it is often paired with a rescoring step: retrieve a generous candidate set using the cheap binary comparison, then re-rank those few candidates with the full-precision vectors to recover most of the lost accuracy.
Start with int8 scalar quantization. It cuts memory by three-quarters, frequently speeds up search, and costs about a percent of recall. Reach for product or binary quantization only when scale forces the issue. And when you do, add a full-precision rescoring pass to claw back accuracy.
The hard problem: filtered search
Pure similarity is rarely enough on its own. Real queries carry constraints: this language, this date range, this customer's documents, this product category. Combining a metadata filter with vector similarity turns out to be one of the genuinely hard problems in the field, and the way a system handles it has real consequences for accuracy. There are two naive strategies and one harder-but-better one.
Post-filtering
Run the vector search first, then discard results that fail the filter. Simple, but if few matches survive, you can end up with fewer results than asked for.
Pre-filtering
Select the vectors that satisfy the filter first, then search only those. Guarantees enough results, but can force a slow brute-force scan.
Each degrades in a different way. Post-filtering is fast when filters are loose, but restrictive filters break it: when very few vectors satisfy the filter, post-filtering accuracy falls off sharply, because the initial similarity search may return few or no items that survive the filter. Pre-filtering guarantees you can return enough results, but without an index tailored to the filtered subset, it often falls back to a brute-force scan of those survivors, which scales poorly and throttles throughput.
Because both baselines have a weak side, modern systems increasingly fold the filter into the search itself rather than bolting it on before or after. These in-algorithm approaches change the index or the traversal so the ANN search only ever visits vectors that pass the filter — Qdrant weaves in extra graph links, Weaviate's ACORN expands two hops out, and Pinecone merges the metadata and vector indexes into one. Azure's implementation is instructive here: its preFilter mode applies the filter while walking the HNSW graph, which protects recall at the cost of exploring more of the graph, whereas postFilter walks first and filters after, and preFilter is the default precisely because it puts recall and quality ahead of raw latency. The takeaway for anyone evaluating a vector database is that "does it support filters" is the wrong question. The right one is how it filters, and what that does to recall when your filters are selective.
Where retrieval quality is really won
It is tempting to believe that retrieval quality is decided by the index or the embedding model. More often it is decided earlier, by how content was split before it was ever embedded. A RAG pipeline is a chain (chunk, embed, index, retrieve, rerank, generate), and once chunking has shattered a document into incoherent fragments, nothing downstream can put the meaning back together.
The failure is subtle because the embedding step still "works," faithfully encoding whatever fragment it is handed. A fragment reading "revenue grew 3% last quarter" is nearly worthless on its own — which company, which quarter, which report? The embedding faithfully captures the fragment while missing the very context that would make it findable. Ask "what was Acme Corp's Q2 revenue growth" and the retriever may never surface that chunk, because its vector has no signal for "Acme Corp" or "Q2."
Two findings from recent research are worth internalizing. First, chunk size has a defensible default: across seven strategies tested in a February 2026 benchmark, recursive splitting at around 512 tokens came out on top. Second, adding context back into chunks before embedding produces large, measurable gains: Anthropic's work on contextual retrieval reported that prepending a little context to each chunk before embedding cut retrieval failures by about half, and by two-thirds once reranking was added. For a publisher, the lesson is not to run a pipeline; it is that self-contained, context-complete passages are what survive this process intact.
Vector databases in RAG
Vector databases are the retrieval engine behind most retrieval-augmented generation systems, because they can surface relevant passages from enormous document collections in milliseconds. But they are a common choice, not a mandatory one. A RAG system can retrieve just as legitimately through a traditional keyword index, a SQL database, a graph database, or an external API. The vector database earns its place specifically when semantic similarity, matching by meaning rather than exact words, is the property you need.
In practice the strongest systems rarely rely on vector similarity alone. Hybrid retrieval blends semantic search with conventional keyword matching, so that exact terms (product codes, names, error strings, quoted phrases) are not lost in the fuzziness of embeddings, while conceptually related content is still found when the wording differs.
Honest limitations
A vector database is a powerful default for similarity search, not a universal answer. Its constraints are worth stating plainly, because most retrieval disappointments trace back to one of them.
- Embedding dependency: retrieval quality is capped by the embedding model and by how content was chunked. The database cannot retrieve meaning the embeddings failed to capture.
- Approximation: fast nearest-neighbor search can miss a genuinely relevant candidate. Recall is a tunable target, not a guarantee.
- Semantic drift: broadly similar content can outrank the precise answer, since similarity is not the same as correctness.
- Maintenance: changed content needs re-embedding and re-indexing; stale vectors quietly degrade results.
- Access control: retrieval must respect the permissions attached to the original data, which is exactly why filtered search matters so much.
The through-line is that similarity is a proxy, not the goal. Being easy to retrieve is necessary but never sufficient; the retrieved passage still has to be correct, current, and appropriate for the person who asked.
What this means for publishers
You do not need to run a vector database to benefit from understanding one. The concept matters because a growing share of retrieval, inside search engines, assistants, and answer engines, works at the passage level and by semantic similarity. That reframes what "optimized content" means.
Write self-contained passages
Because retrieval happens chunk by chunk, a section that only makes sense with the whole page around it is a section that retrieves poorly. Each passage should carry its own context.
Name entities explicitly
Embeddings encode what is on the page. If the company, product, date, or version is implied rather than stated, the vector has no signal for it, and the query that needs it may never match.
Use consistent terminology
Semantic search tolerates synonyms, but clear, stable naming still gives both people and machines a firmer anchor for what a passage is about.
Keep metadata accurate
Dates, categories, and other structured signals feed the filters that sit on top of similarity. Accurate metadata is what lets your content survive a selective filter.
None of this is a trick aimed at one particular architecture. It is the natural consequence of how similarity-based retrieval works: focused, context-complete, clearly-labeled content is easier to embed accurately, easier to match, and easier to filter correctly. Those are the same properties that make content genuinely useful to a human reader — which is the point.
- Vector databases answer "which items are most similar to this?", a fundamentally different question from exact-match databases.
- Exact nearest-neighbor search is too slow at scale, so these systems use approximate (ANN) indexes that trade a little recall for large speed gains.
- HNSW, a multi-layer proximity graph, is the industry default; IVF, a clustering approach, trades some speed for lower memory.
- Quantization compresses vectors 4–64x; scalar quantization is the low-risk default, with product and binary reserved for extreme scale.
- Filtered search is a genuinely hard problem: how a system combines filters with similarity affects recall more than most buyers realize.
- Retrieval quality is often decided at chunking time, before embedding; self-contained, context-complete passages retrieve best.
- For publishers, the practical implications, focused passages, explicit entities, consistent terms, accurate metadata, are the same things that help human readers.
Research
Sources
Primary platform documentation, peer-reviewed research, and vendor engineering write-ups used for this article. Sources are listed by the specific concept or system behavior they support.
- 1Malkov & Yashunin (arXiv)Efficient and robust approximate nearest neighbor search using HNSW graphs
- 2MachineLearningMasteryVector databases explained in three levels of difficulty
- 3
- 4
- 5TiDB / PingCAPANN search explained: IVF vs HNSW vs PQ
- 6
- 7
- 8
- 9
- 10Microsoft LearnVector query filters in Azure AI Search
- 11
- 12Bits & BackpropsThe Achilles heel of vector search: filters
- 13FirecrawlBest chunking strategies for RAG
- 14Denser.aiRAG chunking strategies compared