AI State of the Art
SOTA/Retrieval Augmented Generation (RAG)/37 min
Section 135

Vector Databases: Pinecone, Weaviate, Milvus, Chroma, Qdrant

Listen as a podcast →

This page is about where the vectors produced at the indexing step of RAG: principle and architecture get stored. What goes into them, and how they get compared, belong to Text embedding models and Dense, sparse and hybrid retrieval.

Why a Vector Database?

You have a million embeddings stored. A user asks a question. The obvious method is to compare that question to every vector, one by one, and keep the best. This is called exhaustive, or exact, search: it returns the right answer by construction, because it looks at everything.

Let us put numbers on it, because it gets written off as impractical far too quickly. One comparison between two 768-dimension vectors is 768 multiplications and as many additions. Across a million documents, that is roughly 768 million multiply-adds per question. A modern CPU core executes a few billion of those per second, so we are in the region of a tenth of a second per question, on a single core, with no index at all. Which means: at a million documents and a few questions per second, exact search is fine, and it is the right default.

The problem shows up when you multiply the two factors. At a hundred million documents and a thousand questions per second, the same arithmetic gives ten thousand CPU-seconds per elapsed second. There, you need something else.

Vector databases provide that something else: indexes, data structures that let you compare the question to only a small fraction of the corpus. The price is explicit, and it has to be understood before anything else.

The most important word on this page: approximate

These indexes perform approximate search. The algorithms are called ANN (Approximate Nearest Neighbours), as opposed to exact nearest neighbours. "Approximate" does not mean "scores that are slightly off". It means:

The index may never look at the best document, and therefore never return it, with no error reported anywhere.

There is no warning, no return code, nothing. The answer comes back fast and looks normal; it is simply an answer to a slightly different question than the one you asked. A RAG system built on top will then produce a wrong answer for an invisible reason: the right passage existed, it was indexed, and nobody read it.

The quantity that measures this is recall: the proportion of the truly best results that the index actually found. A recall of 0.9 over the top 10 means that on average, 9 of the 10 documents an exact search would have returned are there, and one is missing. The precise definition, and its cousin precision, are in Measuring a ranking.

The decisive point, and the reason for this section: recall is a dial you set, not a fixed property of the product. Every one of these indexes exposes knobs that trade compute time for recall, how many cells to probe, how many neighbours to visit, how long a candidate list to maintain. Turn them up and recall rises while search slows; in the limit you revisit the whole corpus and you are back to exact search. So there is no such thing as "HNSW's recall": there is a recall for a given setting, on a given corpus.

A performance number without its conditions means nothing

When a vendor advertises "5 milliseconds per query" or "50,000 insertions per second", the measurement only means something if four things are stated alongside it:

  1. corpus size, 1 million and 1 billion vectors are different problems;
  2. vector dimension, cost is proportional to it;
  3. hardware, core count, available memory, whether a GPU is involved, and above all whether the index fits in memory or spills to disk;
  4. the recall achieved, usually omitted, and the most important of the four, because lowering recall makes any index arbitrarily fast.

Without the fourth, the first three are useless: comparing two latencies at unknown recall is comparing two race times without knowing whether the runners covered the same distance. This page therefore gives no latency or throughput figures at all, because a number torn from its conditions would mislead. The only usable measurements are published as recall/throughput curves, where you read throughput at equal recall. On reading this kind of result, see How to read a benchmark score.

Indexing Algorithms

HNSW: a neighbourhood graph on several floors

HNSW stands for Hierarchical Navigable Small World. The name is worth taking apart, because it contains the whole idea.

Small world is a term from network theory: a network in which any two people can be linked by a short chain of acquaintances, "six degrees of separation". You get one by giving each node many short-range links and a few very long ones. Navigable means that short chain can actually be found by moving locally: at each step you look at the current point's neighbours and move to whichever gets you closest to the target; when no neighbour improves things, you stop. It is a greedy descent, like a hike where at every fork you take the path that goes down most steeply.

Hierarchical is the decisive addition. Several floors of the same graph are stacked. The top floor holds only a handful of points joined by very long links: a few hops cross the entire corpus and land you in the right region. You then drop a floor, where there are more points and shorter hops, and restart the greedy descent from where you arrived. And so on down to the bottom floor, which holds every vector. Roughly: the upper floors get you close, the bottom one gets you precise.

  • What gets visited: not the corpus, only the points met along the path. That is where the saving comes from, and empirically the number of points visited grows about like the logarithm of the number of vectors, that is, very slowly. This behaviour is observed, not guaranteed.
  • The two knobs: M sets how many neighbours each point keeps, hence graph density and memory size; ef sets how many candidates the search holds in reserve during the descent, hence effort per query. Raising ef improves recall and slows search without touching the index at all: that is the knob to know.
  • The real constraint: to be traversed quickly, the graph must sit in RAM along with the vectors. A corpus that does not fit forces either a bigger machine, or a disk-oriented index, or compression.
  • The weak spot: a greedy descent can get stuck in a local dead end and return a neighbour that is not the nearest. That is exactly the approximation described above; ef governs how often it happens.
HNSW diagram with three stacked layers. Layer 2 holds only two widely spaced nodes, layer 1 holds five nodes joined by edges, layer 0 holds every node in a dense graph. A red path starts from the entry point in layer 2, drops to layer 1, then to layer 0 and ends at the green node closest to the query. An arrow on the right indicates a decreasing characteristic radius from top to bottom.
HNSW's hierarchical descent. At the top, few nodes but very long jumps: you reach the right region fast. Each lower layer is denser and the jumps get shorter, until you land on the nearest neighbour (in green) in the bottom layer that holds every vector.Source : HNSW paper (Malkov and Yashunin, figure 1), via Zilliz

IVF: cutting the corpus into aisles

IVF stands for Inverted File. The name comes from keyword search, where an inverted file is a table listing, for each word, the documents containing it, the inverse of a table listing, for each document, its words. Here, words are replaced by regions of space.

The mechanism, in two stages. At build time, you pick a number of regions, say 4,096, and compute a representative point for each, its centroid, using k-means (place the centres at random, assign each vector to the nearest centre, recompute each centre as the mean of what was assigned to it, and repeat until it settles). Each vector then goes into its centroid's list. At search time, you first compare the question to the 4,096 centroids only, that is quick, then exhaustively scan the lists of just the few nearest centroids.

It is how a library is organised: instead of walking every shelf, you read the aisle signs, then search the right aisle from end to end.

  • The real cost: with NN vectors spread over CC regions and pp of them probed, you examine roughly N×p/CN \times p / C vectors, plus the CC comparisons against centroids. With 1 million vectors, 4,096 regions and 8 probed: about 2,000 vectors examined instead of a million. So the saving is not logarithmic as with HNSW, it is simply proportional to the fraction of the corpus you agree to read.
  • The knob: it is pp, the number of regions probed (nprobe in most libraries). p=1p = 1 is very fast and misses often; p=Cp = C is exactly exhaustive search. All recall tuning lives here.
  • The weak spot, and it is structural: region boundaries. A highly relevant document sitting just the other side of a boundary will never be examined if its region is not probed, even though it is closer to the question than half the contents of the chosen region. Probing several regions is precisely what limits that risk.
  • Memory: leaner than HNSW, since there is no link graph to store, only the centroids and each vector's assignment.
Two side-by-side panels. On the left, a plane split into polygonal cells by boundaries, each cell holding data points of the same colour. On the right, the same partition with two query points marked by red stars, and only the few cells around each star shaded in yellow and orange.
IVF carves the space into cells around centroids found by k-means (left). At search time (right), only the few cells nearest the query are visited, shaded here: the rest of the corpus is skipped entirely, which is where the speed-up comes from.Source : NVIDIA Developer blog (cuVS IVF-Flat)

PQ: replacing each slice of a vector with an id

PQ stands for Product Quantization. To quantize is to replace a continuous value by the nearest of a small set of permitted values, like rounding a price to the cent. The "product" comes from quantizing slices of the vector separately, so that the set of representable vectors is the product of the choices made on each slice.

HNSW and IVF cut down how many vectors get examined. PQ does not change that count: it cuts the size of each vector. The two compose, hence the widespread IVF-PQ index on large corpora.

How it works: slice the vector, say 96 slices of 8 numbers each for a 768-dimension vector. For each slice position, learn a small catalogue of reference slices in advance, typically 256 of them. Then replace each real slice by the id of the nearest reference in its catalogue.

The saving can be worked out by hand. A 768-dimension FP32 vector takes 768 × 4 = 3,072 bytes. After PQ with 96 slices and 256 references per catalogue, all that remains is 96 ids, each fitting in one byte since 256 values encode in 8 bits: 96 bytes. That is 3,072 / 96 = 32 times less. So the factor is not a property of PQ, it is the outcome of two choices (slice count and catalogue size) and it is yours to set.

The cost is immediate: two different slices end up with the same id, so distances computed on compressed vectors are wrong, by a small but real margin. Hence the usual remedy: shortlist on the compressed index, then recompute exact scores for the few dozen survivors from the original vectors, kept aside.

Product quantization diagram. On the left, a vector split into four subvectors. In the middle, for each subvector, a small space holding three reproduction values marked by coloured crosses, with the subvector attached to the nearest cross. On the right, the quantized subvectors take the colour of their reproduction value, then are replaced by a plain colour identifier.
How product quantization works. You slice the vector, replace each slice by the closest reproduction value from a small learned catalogue, and store only that value's id. Hence the massive compression, and the precision loss, since two neighbouring slices end up with the same id.Source : Pinecone, Faiss series

What follows describes what each product is (deployment model, indexes, licence) and not its performance, for the reason given above. Relative speed rankings change from release to release and would not survive the writing of this page.

Chroma

Type: in-process (Python library, no separate server). Index: HNSW. Strengths: very quick to get running, ideal for learning and prototyping. Since it runs inside your own process, there is no server to administer and no network hop. Limitations: not designed for production, it does not spread across machines, and it shares your application's memory.

import chromadb
client = chromadb.Client()
collection = client.create_collection("docs")
collection.add(documents=["text 1"], ids=["1"])
results = collection.query(query_texts=["my question"], n_results=3)

Chroma is the SQLite of vector databases: perfect to get started, to be replaced when things get serious.

Qdrant

Type: dedicated server, written in Rust. Index: HNSW, with specific handling of metadata filtering. Strengths: metadata filters (date, category, access rights) built into the vector search rather than applied afterwards, which is an important technical point, see the filtering box below. Detailed documentation. Limitations: one more server to deploy, monitor and back up. License: Apache 2.0.

A common choice for self-hosted production, particularly when every query has to be restricted to a subset of documents.

Weaviate

Type: dedicated server, written in Go. Index: HNSW, plus a BM25 keyword index in the same database. Strengths: hybrid search (vectors and keywords combined) comes from the database itself, sparing you from running two systems and merging their results by hand. What BM25, dense retrieval and their fusion actually are is covered in Dense, sparse and hybrid retrieval. Modules can call the embedding model themselves at insert time. Limitations: two indexes instead of one, so more memory for the same corpus.

The right choice if you want hybrid search without assembling it yourself.

Pinecone

Type: hosted service run by the vendor; you install nothing. Strengths: no operations on your side, no machine to size, no upgrades, no backups. Capacity tracking is the provider's job. Limitations: your data and index live with a third party, the software is not open, and there is no equivalent self-hosted edition to fall back on. The bill follows stored volume and traffic, and the indexes used are not documented publicly, so you cannot tune the recall/latency trade-off yourself at the same level of detail.

Suited to teams with no systems operator who accept the dependency.

Milvus / Zilliz

Type: distributed system, self-hostable or offered as a managed service (Zilliz). Index: HNSW, IVF-PQ, DiskANN, the last being an index designed to keep vectors on disk instead of occupying RAM, which changes the size ceiling reachable on a given machine. Strengths: built to spread one index across several machines, and lets you pick the index type to match the trade-off you want. Limitations: several components to deploy and operate when self-hosted; this is an infrastructure decision, not a library.

The natural candidate once a single server no longer suffices.

pgvector

Type: PostgreSQL extension. Index: IVF, HNSW. Strengths: the vectors live in the database you already operate, with your transactions, permissions, backups and joins. That is the underrated advantage: a vector search and a WHERE on business columns in one SQL statement, with no two systems to keep in sync. Limitations: its vector indexes are newer and less tunable than in dedicated databases, and they share the database's resources with the rest of your load.

The pragmatic choice if you already run PostgreSQL, and often the right one, as long as vector search is not the heart of the product.

The Decision in Three Questions
  1. Does the index fit in memory on one machine? The arithmetic is in the next section. If yes, almost anything works, including exact search. If no, the question becomes "disk-based index or spread across machines", and the field narrows to Milvus, a managed service, or compression.
  2. Who operates the system? Nobody → a managed service. An infrastructure team → a self-hosted database, with the recall dial in your hands.
  3. Do you already run a relational database? If so, start by putting the vectors in it, and only move once a measurement forces you to.
The filtering trap, which explains much of the gap between products

Almost every real use needs to restrict the search: documents from this year, from this customer, visible to this user. And filtering interacts badly with approximate search.

Two naive strategies, both bad. Filter afterwards: ask the index for the top 10, then discard those failing the filter, if all of them are discarded you return an empty list even though good documents existed. Filter beforehand: build the list of allowed documents and compare all of them, correct, but that is exhaustive search again.

Serious databases do something else: they fold the filter into the index traversal, following only links that lead to allowed documents, and switch to exhaustive comparison on their own when the filter is highly selective. That work, rather than raw speed, is what distinguishes the products, and it is the first thing to measure if your application filters heavily, because a selective filter can sink recall without changing the advertised latencies at all.

Sizing: the one calculation worth knowing

The memory of an HNSW index splits into two items, and they must be counted separately because they are not the same order of magnitude.

The vectors themselves. One FP32 number takes 4 bytes, so:

vectors=N×d×4 bytes\text{vectors} = N \times d \times 4 \text{ bytes}

where NN is the number of vectors and dd their dimension. For a million 768-dimension vectors: 1,000,000 × 768 × 4 = 3.07 GB.

The link graph. Each vector keeps roughly MM neighbours per floor. Since links are reciprocal, in practice you count on the order of 2M2M ids per vector, each id taking 4 bytes:

graph≈N×2M×4 bytes\text{graph} \approx N \times 2M \times 4 \text{ bytes}

With the most common default, M=16M = 16: 1,000,000 × 32 × 4 = 128 MB.

Total: about 3.2 GB, roughly 5% more than the vectors alone. So the sizing rule to remember is simple: memory is the size of the vectors, plus a margin on the order of tens of percent, for the graph, the metadata and the database's internal work. It is not a factor of three or four. If you see such a factor quoted, ask which item it comes from.

A useful corollary: it is the vector dimension that drives the memory bill, not the index structure. Hence the value of the two levers covered elsewhere, truncating the vectors (Matryoshka embeddings) and cutting the precision of each number (product quantization, above). Going from 768 dimensions in FP32 to 256 dimensions in INT8 divides this item by 3 × 4 = 12.

Common Pitfalls

A badly tuned index misses documents silently

HNSW's parameters (M and ef_construction at build time, ef at search time) set the trade-off between speed and recall. A too-frugal index will return fast, incomplete answers (and this is the whole problem) your application will not notice: queries succeed, results look plausible, latency is excellent.

The only way to catch it is to measure, and the method needs no tooling. Take a few hundred questions, compute the true best results for each by exhaustive search (slow, but perfectly feasible offline on a sample), then compare against what your index returns. The proportion recovered is your recall. Redo the measurement after every change of parameter, embedding model or filtering policy.

Most projects over-invest in the choice of vector database when the real leverage is elsewhere. Below a million documents, the arithmetic at the top of this page makes the point: even exhaustive search holds up, and any properly tuned solution will do. Invest instead in the embedding model and in how documents are split (Chunking strategies), and above all, establish whether your problem is in retrieval or in writing, which evaluating a RAG settles. A faster vector database does not repair bad chunking.

Check your understanding0 / 5

1. What does approximate mean in a vector database's ANN algorithms?

2. You have a million documents and a few questions per second. Do you need an approximate index?

3. A vendor advertises 5 milliseconds per query. What missing piece of information makes that figure unusable?

4. Your application restricts every search to the documents the user is allowed to see. What is the risk of the filter-after strategy (search first, discard afterwards)?

5. How do you detect that an overly frugal HNSW index is missing documents, given that the application sees no error?