Module 4 · Data and runtime infrastructure · Chapter 13 · Free
Vector databases in production: indexing, recall and scaling
- A vector database finds the few documents closest in meaning to a question, fast, out of millions: the retrieval memory behind a RAG copilot.
- Speed comes from an approximate index. Approximation costs recall: some true neighbours are missed. Measure that trade, do not guess it.
- Memory, replicas, shards and freshness can all be worked out on paper before you deploy.
The picture: the index is a library map that points you to the right shelf quickly, and sometimes to the wrong one.
- The vector database's job in Copperline's support copilot.
- Graph versus clustered index families, at operator level.
- How to measure recall against a brute force sample.
- Memory sizing math, scaling, filter costs, freshness, and a lab.
Copperline is a made up B2B SaaS company. Priya Nair, its staff platform engineer, launched the copilot's vector store on one small node and moved on. All figures here are illustrative.
- The help centre grew from an illustrative 200,000 chunks to 2 million as Ana's team imported old ticket answers.
- One Monday the node ran out of memory, the index stopped loading, and the copilot answered from no documents for an illustrative 40 minutes.
- Worse, nobody could say whether answers had been missing good documents for weeks. There was no recall measurement.
The fix was not a bigger node. It was sizing math and a recall check.
- The job: retrieval for the copilot.
- Index families: graph versus clustered.
- Recall versus latency, measured.
- Memory sizing math, worked.
- Filtering, scaling, and freshness.
- The picture, and a sizing lab.
Next: what the vector database actually does for the copilot.
Step 1: The job, finding the right pages before the model answers
The copilot should answer from Copperline's help documents, not from model memory. The vector database finds those documents.
- At ingest: each help page is split into chunks, each chunk becomes a vector (numbers capturing meaning) via an embedding model, and the vectors are stored in an index.
- At query time: the question is embedded the same way, and the database returns the nearest chunks.
- Then: those chunks go into the prompt, and the model answers. Retrieval basics are covered in RAG end to end. This chapter runs the store underneath.
Think of a librarian who has read every page and points to the five most relevant in a blink. Where the picture breaks down:
- The librarian judges meaning. The index judges distance between number lists, which only approximates it.
- A librarian can say nothing matches. A nearest neighbour search always returns something.
Next: the two index families you will choose between.
Step 2: Index choices, graph versus clustered
Checking a question against every vector is exact but slow at millions of vectors. Indexes trade a little accuracy for a lot of speed. Two families cover most products.
- Graph indexes (HNSW is the common example): vectors linked to near neighbours in a layered graph; a search walks the graph toward the question. High recall at low latency, but links add memory and builds take longer.
- Clustered indexes (IVF style): vectors grouped into clusters; a search checks only the nearest few. Smaller memory and fast builds, but recall depends on clusters probed, and skewed clusters search unevenly.
- Flat (brute force): no index, every vector checked. Too slow at scale, but perfect as the measuring stick in Step 3.
Products here include dedicated vector databases and vector extensions for existing databases, most offering one or both families under their own setting names.
Think of graph search as following signposts between towns, and clustered search as picking the right district, then walking its streets. Where the picture breaks down: signposts are rebuilt as data changes, and district borders are learned from data, so some districts hold far more vectors.
Next: the trade every index makes, and how to put a number on it.
Step 3: Recall versus latency, measured, not vibes
An approximate index returns most of the true nearest neighbours, quickly. Recall says how many: recall at 10 of 0.9 means 9 of the true top 10 appear in the index's top 10.
- The trade: search wider (more graph steps, more clusters probed) and recall rises, latency with it. Search narrower and answers get faster and worse.
- Why it matters: a missed chunk is a fact the model never sees. Low recall looks like a model problem and gets debugged wrongly.
- The rule: pick a recall target with the workload owner, then tune to hit it at the best latency.
How to measure recall against brute force:
- Take a sample of real questions, say an illustrative 200, from production logs.
- Run each against a flat search over the same vectors. That exact top 10 is ground truth.
- Run each against the index with your candidate settings, count the overlap, and average it. That average is recall at 10 for those settings, on your data.
- Repeat after index changes, data growth, or an embedding model change.
Predict first:
Narrower settings trade recall for latency. The page can be present and well embedded, yet never visited by the search. A brute force sample would have shown the drop the day the setting changed.
Next: the picture, a question flowing through retrieval.
Step 4: The picture, from question to grounded answer
Press Next to walk a question through retrieval.
- A customer asks about refunds, with tenant and product filters attached.
- The ingest embedding model turns the question into a vector. Mismatched models mean mismatched vectors.
- The index walks toward the question vector, inside the filter, and ranks the nearest chunks.
- Top chunks and their text are read out. Recall is won or lost here.
- The chunks go into the prompt and the copilot answers from them.
Next: the worked example, sizing the index on paper.
Step 5: Worked example, memory sizing math
The formula is simple: memory equals count times dimensions times bytes per number. All figures are illustrative.
1. The raw vectors. Copperline has 2,000,000 chunks, 768 dimensions, 4 byte floats. 2,000,000 x 768 x 4 = 6,144,000,000 bytes, about 6.1 GB.
2. Index overhead. A graph index adds links per vector. At an illustrative 30 percent, add about 1.8 GB. Total: about 7.9 GB. Clustered indexes usually add less.
3. The rest of the record. IDs, filter metadata, and stored text: at an illustrative 0.5 KB per chunk, another 1 GB. Total: about 8.9 GB, before the process itself.
4. The decision. A 16 GB node fits with headroom. The cold open node, at an illustrative 8 GB, never stood a chance. Half precision (2 bytes) would cut step 1 to about 3.1 GB, at a recall cost to verify via Step 3.
5. The lesson. Count, dimensions and bytes per float set the floor. Index choice moves the overhead. Do this math before every big import.
Next: filters, scaling shapes, and keeping the index fresh.
Step 6: Metadata filtering, and what it costs
Vectors alone are not enough. The copilot must only retrieve the customer's own tenant data, the right product, and current versions. Those checks are metadata filters.
- Filter first, then search: correct and safe, but a very selective filter leaves few candidates to walk, hurting recall or forcing a near flat scan of the filtered set.
- Search first, then filter: fast, but top results may all belong to other tenants and get discarded. A bug that skips the filter risks leaking across tenants.
- Rule: most engines weave the filter into the search itself. Either way, test recall with filters on. Unfiltered numbers flatter you.
Next: scaling the store, and what breaks first.
Step 7: Scaling shapes, and what breaks first
- Replicas for read throughput: copies of the same index on more nodes. Queries spread across copies, so reads scale near linearly. Writes and builds must reach every copy. The first move when query load, not data size, is the pressure.
- Sharding for data size: split vectors across nodes, by tenant or collection. Each shard searches its slice and results merge.
- What breaks first: usually memory, as the cold open showed, then write and rebuild time, then merge cost as shards multiply.
- Watch the skew: sharding by tenant puts a giant tenant alone on a hot shard. Split big tenants by collection.
Think of replicas as photocopies of one map in many hands, and shards as splitting the map into volumes. Where the picture breaks down: photocopies go stale on every change, and each search must check several volumes.
Next: freshness, how changed documents reach the index.
Step 8: Freshness, from edited page to searchable vector
- The path: a page changes, the change is detected (event, webhook, or scan), the page is re-chunked and re-embedded, and new vectors replace the old.
- Deletes matter: a removed page must leave the index too, or the copilot quotes retired policy.
- Set a freshness budget: agree with Ana how stale is too stale, say an illustrative 15 minutes, then monitor edit to searchable lag.
- Reindexing is different: an embedding model change invalidates every vector at once. That rebuild is Chapter 14, "Embedding pipelines: ingestion, reindexing and versioning".
Next: the lab, where you size and set an index for a stated workload.
Step 9: Hands-on lab, size it and pick the settings
Why this exercise: index choices are sizing and trade decisions, made on paper against a stated workload.
The workload (illustrative): 5,000,000 chunks at 1,024 dimensions, float32, read heavy traffic, a recall at 10 target of 0.95, and a strict tenant filter on every query.
Lab: Priya is sizing Copperline's copilot vector store and, this time, measuring recall before launch instead of guessing it. This lab runs in your browser and needs JavaScript enabled.
- The worksheet killed the single node plan before any product was chosen.
- Every recall claim here is tied to a measurement, never a default.
Next: a field note and the mix-ups.
In production practice, vector stores fail quietly: recall drifts as data grows, filters change search behaviour, and stale documents keep answering. Teams that run them well treat recall sampling and freshness lag as ordinary metrics, checked on a schedule. Defaults vary by product, so measure on your own data.
Mix-ups to avoid
- "Low recall is a model problem." The model cannot use chunks it never saw. Measure retrieval first.
- "Default settings are tuned for us." Defaults are starting points. Your data, filters and recall target decide.
- "More replicas fix a too big index." Replicas copy data for read load. Sharding splits data that does not fit.
- "Unfiltered recall tests prove production recall." Tenant filters change the search. Test with filters on.
Chapter quiz
Five questions, 70% to pass.
Review this chapter in 5 minutes
Watch the whole chapter recapped: index families and recall, memory sizing math, replicas versus shards, and freshness lag.
- The vector database returns the nearest chunks to a question vector; the model answers from them.
- Graph indexes (HNSW style): high recall, low latency, more memory. Clustered (IVF style): leaner, tunable by clusters probed.
- Recall is measured: sample real questions, compare index top 10 against brute force top 10, filters on.
- Memory floor: count x dimensions x bytes per float. Example: 2,000,000 x 768 x 4, about 6.1 GB raw (illustrative).
- Replicas scale reads. Shards split data that does not fit. Memory breaks first. Freshness is a pipeline with a lag metric, deletes included.
Decision rule: size memory on paper, set a recall target, prove it against brute force with filters on, then scale reads with replicas and data with shards.
Review
Glossary
- Vector
- A list of numbers capturing a chunk's meaning.
- Graph index
- An index linking vectors to near neighbours, searched by walking links: HNSW style.
- Clustered index
- An index grouping vectors into clusters, searching the nearest few only: IVF style.
- Recall at 10
- Share of the true top 10 the index returns in its top 10: 9 of 10 found is 0.9.
- Brute force search
- Exact search over every vector: ground truth in a recall test.
- Metadata filter
- A condition applied with the search, such as only this customer's documents.
- Replica
- A full copy of the index serving reads: three copies spreading peak load.
- Shard
- One slice of the data on one node: tenants A to M on shard one.
Next: "Embedding pipelines: ingestion, reindexing and versioning".