Semantic search at scale
A knowledge platform ingests ten million documents a day, chunks and embeds them, and answers natural-language questions over the last ninety days. Answers must cite real passages, and the search box must feel instant.
Envelope10M documents/day ingested · 90-day corpus · p99 < 200 ms on query
What the design must do
- Ingest keeps up with 10M documents a day without falling behind
- A query returns in under 200 ms at p99
- Retrieval finds passages that match by meaning and by exact term
- A new document is searchable within minutes, not overnight
- Changing the embedding model does not require an outage
The worked envelope
Assumed. 10M documents a day, averaging 8 chunks each. 1,024-dimension embeddings at float32. A 90-day retention window. 500 queries/s at peak.
| Chunks | 10M × 8 = 80M/day ≈ 926/s sustained |
| Vector size | 1,024 × 4 B = 4 KB, ≈ 320 GB/day raw |
| Corpus | 90 × 80M = 7.2B chunks ≈ 29 TB at float32 |
| After int8 | 1 KB/vector → 7.2 TB, and HNSW links on top |
| Query budget | embed 20 + ANN 30 + keyword 20 + fuse 50 + wire 30 = 150 ms |
| Re-embed cost | 7.2B ÷ ~2,000/s per GPU = 41 GPU-days |
What the numbers decide. The corpus row rules out the design everyone draws first. Twenty-nine terabytes of float32 vectors is not a graph you hold in memory on a machine, so quantisation is not a tuning step you get to defer — it is load-bearing from day one, and it costs recall, which means you owe an offline recall measurement before you ship rather than after someone complains.
The budget row decides the shape of the query path. A hundred and fifty milliseconds of a two-hundred-millisecond p99 is already spent before any reranking model gets a turn, which is why the reranker sees a few dozen candidates and not a few thousand, and why the query embedding call has to be a small model on warm capacity rather than a queued GPU job.
And the last row is the one to say out loud in a review: changing the embedding model means re-encoding the entire corpus, and at one GPU that is six weeks. It is a capacity project with a budget, not a config change (Lesson 11.03).
The decisions, and what each one costs
Ingest and query run on separate embedding capacity
- Because
- The backfill wants every GPU it can get and does not care about latency; the query path needs one small embedding in 20 ms and cannot queue behind 80 million chunks — sharing a pool means the ingest burst sets your p99
- The cost
- Two pools to size, and the query pool sits underused most of the day, which is Lesson 14.02’s idle-capacity bill arriving on schedule
- Rejected
- One autoscaled pool serving both, which is cheaper on the invoice and makes search latency a function of how much was uploaded this morning
Chunk on document structure, then embed — not on a fixed token count
- Because
- The retrieval unit and the embedding unit are the same thing, so a chunk split mid-table or mid-clause produces a vector that means nothing and can never be retrieved correctly no matter how good the index is
- The cost
- Variable-length chunks complicate batching on the GPU, and structure parsing is per-format work that never quite finishes
- Rejected
- Fixed 512-token windows with overlap, which is trivial to implement and quietly caps your retrieval quality below whatever the index could have given you
Hybrid retrieval: ANN and an inverted index queried in parallel, results fused
- Because
- Embeddings are weak at exactly what keyword search is strongest at — error codes, part numbers, surnames, negations — and the two run concurrently inside the same 50 ms because neither depends on the other
- The cost
- Two indexes to keep consistent, two failure modes, and a fusion weight that is a tuning parameter nobody can derive from first principles
- Rejected
- Vector-only retrieval, which demos beautifully and then cannot find "ERR-5041" because the embedding of a part number is noise
int8 scalar quantisation with a full-precision rerank of the top candidates
- Because
- It is the difference between 29 TB and 7.2 TB, and the recall lost by approximate distances is recovered by rescoring the shortlist exactly — the cheap index picks 200 candidates, the expensive comparison orders them
- The cost
- Recall now has to be measured rather than assumed, and the rerank step is another 50 ms you have already spent in the budget
- Rejected
- Full-precision HNSW throughout, which is the highest recall per millisecond available and needs roughly four times the memory the corpus can justify
Blue-green indexes, with the model version as part of the index identity
- Because
- Vectors from two embedding models are not comparable — mixing them silently degrades every result rather than failing — so a model change builds a second index alongside the first and flips reads once it is complete and measured
- The cost
- Peak storage is double, for the six weeks the rebuild takes, and both pipelines run in parallel throughout
- Rejected
- Re-embedding in place, which serves a corpus that is part old-model and part new-model for the entire migration, with no error and steadily wrong answers
Components in the reference design
- Client
- Browser or mobile app
- Load Balancer
- L7 routing, TLS termination, health checks
- App Service
- Stateless business logic
- Vector Index
- Approximate nearest neighbour over embeddings — HNSW / IVF
- Search Index
- Inverted index / trie, text and prefix
- Object Store
- S3-style blobs, media, backups
- Queue
- Work distribution, one consumer per message
- Worker
- Async consumer, background jobs
What not to draw
- Cache — A result cache keyed on the query string is the one component that looks obvious here and pays almost nothing. The entire premise of semantic search is that "how do I reset my password" and "forgot my login" are different strings with the same meaning — so exact-key hit rates run in the low single digits. Cache the embedding vectors of common queries if you like; caching the results is a hit rate you can measure and be disappointed by.
The reference design
Two pipelines wearing one name. The ingest path is a throughput problem measured in chunks per second, tolerant of minutes of delay, and dominated by GPU cost. The query path is a latency problem measured at p99, intolerant of a single slow hop, and dominated by index layout. They share a data store and nothing else, and most bad designs of this system are the result of letting one path's requirements set the other's architecture.
Why the queue sits between object storage and the embedding workers. Document arrival is bursty in a way embedding capacity cannot be — a customer migrating an archive uploads two million files in an afternoon. The queue turns that into a backlog that drains at GPU speed, which is the honest outcome, instead of either a dropped upload or a GPU fleet sized for the worst Tuesday of the year. It also makes the embedding worker restartable, which matters when a batch of 41 GPU-days is involved.
The retrieval quality ceiling is set at chunk time. This is the least intuitive claim in the lab and the one worth remembering. No index, no reranker and no larger model can retrieve a passage whose chunk boundary destroyed its meaning — the vector was computed once, over the wrong span of text, and everything downstream inherits that. Chunking is usually treated as preprocessing and is in fact the highest-leverage decision on the ingest path.
Filtering is where this design actually gets hard. Lesson 11.03's point, at scale: "search the last 90 days, in documents this user may read" is not a post-filter you apply to ANN results, because the top 200 by similarity may contain nothing the user is allowed to see, and you will return an empty page while the right answer sits at rank 900. Permission and recency have to be pushed into the index as pre-filters, which every engine does differently and most do badly. Design the tenancy of the index before the topology.
Freshness is a per-path decision. Minutes-fresh means the worker upserts into the live index rather than waiting for a nightly rebuild — so the index must support incremental insert without degrading, which graph indexes do well and cluster-partitioned indexes do badly as the corpus drifts from the sample the clusters were trained on. That drift is invisible until recall has been falling for a month, so periodic rebuild remains scheduled work even in a live-upsert design.
What changes at 10×. A hundred million documents a day is 72 billion chunks in the window, and the index stops fitting anywhere sensible. The corpus shards — by tenant, by time, or both — and the query path fans out and merges, at which point the 150 ms budget has a slowest-shard term in it and the p99 belongs to whichever shard is compacting. Time-based sharding is usually the one to reach for first here, because it makes the 90-day retention rule a matter of dropping a shard rather than deleting seven billion rows.