System Design: Vector Database (Walnut Vector: ANN Indexes, 1-Bit Codes, Filtered and Hybrid Search, Multi-Tenancy, Re-Embedding)
We design a vector database. It stores lists of numbers that stand for the meaning of text, and it finds the stored lists closest to a question's list.
Our product is called Walnut Vector. Many companies share it, and most of them build AI assistants on top of it.
A vector database is the search part of RAG. RAG stands for retrieval-augmented generation: an assistant first finds the passages that match a question, then a language model writes an answer from them.
Our RAG post covers that side: cutting documents into pieces, who may read what, and writing the answer. This post covers the engine that finds the passages.
As in any system design interview, the numbers are assumptions for planning. Every number here is our own assumption, and the design is our own. All times are Pacific Time, in November 2026, unless a line says otherwise.
1. Requirements
1.1 What we are building
Walnut Vector does three jobs:
- Find by meaning, fast. A question about "hail damage to a detached garage" must find a note about "the outbuilding". The search takes tens of milliseconds, among billions of stored chunks.
- Keep each customer's data apart. One customer never sees another's rows. A deleted row stops showing at once, and an erased row is removed from every copy by a set time.
- Cost little for data nobody asks about. Most customers are small and quiet. Their data waits in cheap storage until someone asks.
Harborline is a made-up company in Seattle. It sells an AI assistant to insurers, clinics and law firms. Each Harborline customer gets its own searchable set of chunks in Walnut Vector, where a chunk is a short piece of a document.
The story, one week in November:
- Mon 9 Nov, 09:00. Grace Kim is Harborline's platform engineer. She starts moving Prairie Mutual to Harborline's new embedding model. Prairie Mutual is a made-up insurer in Omaha, with 2 billion chunks of policies and claim notes. Every chunk needs a new list of numbers, and that takes 55.6 hours.
- Tue 10 Nov, 07:01. Tina Morales runs the office at Sagebrush Dental in Boise. She asks the assistant about the clinic's fee for a missed appointment. Nobody asked about the clinic's documents since Monday afternoon, so the search reads from cheap storage. The answer is found in 312 ms.
- Tue, 13:00. Jared lives in Phoenix. He signs up 20 free accounts. He tries to read other customers' data by guessing the names of their data sets, and gets "not found" every time. At 13:20 he sends a very large number of writes and searches from all 20 accounts.
- Wed 11 Nov, 07:00. A hail storm hits Omaha. Adjusters are the staff who assess claims, and Prairie's adjusters use the assistant much more. Prairie's searches rise from 200 to 1,000 a second.
- Wed, 07:13:50. An adjuster saves a note on claim CL-77120: hail broke two windows of a detached garage.
- Wed, 07:14:05. Owen Carter is a Prairie claims adjuster in Omaha. He asks whether policy PM-44017 covers hail damage to a detached garage. He gets 10 results in 24 ms, and the note saved 15 seconds earlier is among them.
- Wed, 07:20. One of our search servers fails in the middle of the storm. Nora Webb is our on-call engineer in Seattle. Other copies of that server's data take over its searches. Nora watches, and no one has to act.
- Wed, 08:31. Frank Doyle is a former Prairie customer in Lincoln, Nebraska. He asked to be forgotten, and Prairie's privacy team sends the erase request.
- Wed, 16:33. The backfill to the new model finishes. By 17:25 the new index is built and ready.
- Thu 12 Nov, 05:00. Harborline tests the new index with its list of known good answers. A final check finds one row whose upsert to the new namespace failed on Tuesday, and Grace fixes it.
- Thu, 06:00. Grace switches Prairie to the new index in one step. At 06:15, Owen's next question runs on it.
What happens to each person:
- Owen finds the 07:13:50 note and approves the garage claim that morning.
- Tina gets her answer in 312 ms. Her next question comes 2 minutes later. It takes about 18 ms, because the clinic's data now sits on the server's SSD.
- Jared's very many requests slow only other free accounts, by up to 18%. Paying customers never notice, and an abuse check closes his 20 accounts.
- Frank's rows are hidden from searches at 08:31:00.240 on Wednesday. They are removed from every serving copy by 10:47. The last kept file, our backup copy, goes by Wed 18 Nov.
- Searches keep working all through Grace's switch. She keeps the old index for 7 days, in case she must switch back.
Most of the data must live in cheap storage, but a search must take milliseconds. And the answers must stay right while rows are written, deleted, erased and moved to a new model.
1.2 Words we use
Words used in only one place are explained there. Each word below is used all through the post.
Vectors and search.
| Word | Meaning here |
|---|---|
| Chunk | A short piece of a document, a few hundred words, such as one claim note. It is what a search returns |
| Embedding model | A model that turns text into a list of numbers. Texts with close meanings get close lists |
| Vector | That list of numbers, as we store it. Most of ours have 1,024 numbers |
| Dimension, or dims | How many numbers a vector holds. 1,024 dims means 1,024 numbers |
| Similarity score | How close two vectors are. Prairie uses cosine similarity, which compares direction only. On vectors scaled to length 1 it equals the dot product: multiply the matching numbers, then add them up |
| Row | One stored record: a row ID, a vector and its attributes |
| Attribute | A field stored with a row, such as the note's text, its date or the team that may read it |
| k | How many results a search asks for. Owen's search asks for 10 |
| Exact search | Scoring every row against the question. It finds the true closest rows, but it is slow |
| ANN | Approximate nearest neighbor search. An index skips most rows, so it is fast but may miss a few of the true closest |
| Recall@10 | Of the true 10 closest rows, the share a search returns. A search that returns 9 of them has recall 0.9 |
| Index | The structure that lets a search skip most rows |
Our index.
| Word | Meaning here |
|---|---|
| Cluster | A group of about 1,000 rows whose vectors are close to each other |
| Centroid | The center of one cluster: the average of its rows' vectors |
| Probe | One cluster that a search looks inside. Owen's search probes 32 clusters in each shard |
| 1-bit code | A tiny copy of a vector: one bit per number, kept in memory. 1,024 dims become 128 bytes |
| Rescoring | Scoring the best candidates again with the full vector, to fix their order |
| float16 | A number stored in 2 bytes. We keep the full vector this way, 2,048 bytes at 1,024 dims |
| Shard | One part of a big namespace, up to 100 million rows. Prairie's namespace has 20 shards |
Tenants and storage.
| Word | Meaning here |
|---|---|
| Org | One customer account of Walnut Vector, such as Harborline |
| Namespace | One searchable set of rows inside an org, such as Prairie's or Sagebrush's. Rows in two namespaces never mix |
| Alias | A name that points at one namespace, such as "prairie". Harborline's app searches the alias, so we can switch what it points at |
| Model tag | The name of the embedding model that made a namespace's vectors, such as harbor-embed-v1 |
| Object store | The cloud's storage service for files: cheap and durable. We plan with 100 ms a round trip, its slow end. It holds the one true copy of everything |
| SSD | A flash disk inside a server: about 4 times the price of the object store per GB, and much faster |
| Memory | A server's RAM: the fastest place, at 100 times the price of the object store per GB |
| Warm and cold | A warm namespace has its files on a search server's SSD. A cold one is only in the object store, so its first search is slow |
| WAL | The write-ahead log. Every write is saved to it first, in order, before anything else changes |
| Tenant | One of our customers' customers, such as Prairie Mutual. Each tenant gets its own namespace |
| Graph index | An index that links each row to some close rows. A search walks the links toward the question |
| Keyword list | For one word, the list of rows that contain it. Keyword search reads these lists |
| float32 | A number stored in 4 bytes, as customers send it |
IDs in this post. Every ID below is made up.
| ID | What it names | Example from the story |
|---|---|---|
| org_harbor | An org ID | Harborline |
| prairie-v1, prairie-v2 | Namespace names | Prairie's namespace on the old model, and on the new one |
| ns_4c2, ns_9d7 | Namespace IDs | prairie-v1 and prairie-v2 |
| sagebrush | A namespace name | Sagebrush Dental's 6,000 rows |
| prairie | An alias | What Harborline's app searches for Prairie |
| harbor-embed-v1, harbor-embed-v2 | Model tags | Harborline's old and new embedding models |
| PM-44017 | A policy number, in Prairie's documents | The policy Owen asks about |
| CL-77120 | A claim number, in Prairie's documents | The claim with the 07:13:50 note |
| u_2291 | A user ID, in Harborline's app | Owen |
| cust_51907 | A customer ID, in Prairie's documents | Frank |
| req_7a31 | A request ID, made once by the caller | The write of the 07:13:50 note |
| org_jx01 to org_jx20 | Org IDs, free plan | Jared's 20 accounts |
1.3 Every kind of request and change
Walnut Vector handles more than the story shows. This table lists every kind.
| Kind | What it is | How big or how often | Part that handles it | Outside company that takes part |
|---|---|---|---|---|
| Vector search | The k closest rows to a question's vector, like Owen's | 4.32 billion a day | Query router, query nodes | none; the customer embeds the question first |
| Filtered search | A search that keeps only rows that match a condition, such as team "claims" | most searches from apps with many users | Filter planner, inside each query node | none |
| Hybrid search | Vector search and keyword search together, so "PM-44017" is found by its exact letters | about 30% of searches | Query nodes, Query router | none |
| Cold search | A search on a namespace with no files on any server's disk, like Tina's | about 1% of searches | Query nodes, Object store | the cloud provider's object store |
| Upsert | Insert a row, or replace it when its ID exists | 43.2 billion rows a day | Write service | none |
| Delete | Hide rows by ID, or by a condition such as "older than 2019" | part of the writes | Write service, Indexer | none |
| Erase | A delete that must also remove every stored copy by set times, like Frank's | a few hundred a day | Erase tracker, Indexer, File collector | none |
| Bulk load | Millions of rows at once, such as a new customer's import | a few a day | GPU build pool | none |
| Model change | Every vector made again with a new embedding model, like Grace's | a few a month across all orgs | Namespace service, Write service, GPU build pool | the customer's embedding provider |
| Restore | A namespace as it was at a moment in the last 7 days | a few a week | Namespace service | none |
1.4 Functional requirements
- Store. Keep rows in namespaces. Upsert and delete rows by ID, or delete them by a condition.
- Search. Find the k rows closest to a question's vector, on warm and cold namespaces.
- Filter. Search only rows that match conditions on attributes, such as team, state or date. Return k rows when k rows match, or a flagged partial answer after 50 ms.
- Keyword search. Combine vector search with keyword search, so exact codes such as "PM-44017" are found.
- Tenants. Keep millions of namespaces apart, with quotas for each org.
- Read rules inside a tenant. Let a customer's app limit each user to the rows that user may read. The limit must hold even if the app has a bug.
- Change the model. Let a customer move a namespace to a new embedding model while searches keep working.
- Delete and erase. Hide deleted rows at once. Remove erased rows from every copy by set times.
- Restore. Bring back a namespace as it was at any moment in the last 7 days.
- Stay up. Keep serving when a server, a zone or a whole region is lost.
Out of scope: running embedding models or language models, which belong to the customer. Cutting documents into chunks and deciding who may read a document are in our RAG post. Also out of scope are billing, SQL queries and training rerankers.
1.5 Non-functional requirements
Half of all requests finish faster than the p50 time. 99 of every 100 finish faster than the p99 time. A zone is one group of data center buildings with its own power, inside a region.
- Warm search. On up to 100 million rows, a warm search takes at most 20 ms at p50 and 80 ms at p99. That includes filters and keyword search. Above 100 million rows, across shards: 40 ms and 150 ms.
- Cold search. Up to 1 million rows, a cold search takes at most 600 ms at p50 and 2 s at p99.
- Recall. Measured against exact search on sampled searches, recall@10 is at least 0.95 for each namespace. It is at least 0.90 when a filter matches under 1% of the rows.
- Writes. A write is acknowledged only after it is stored in the object store, within 500 ms at p99. A strong search, our default, sees every write acknowledged before it began.
- Region copy. Every acknowledged write reaches a second region within 15 minutes.
- Deletes and erasure. A delete is hidden from strong searches as soon as it is acknowledged. An erased row leaves every serving file and cache within 24 hours, and every stored copy within 8 days.
- Isolation. A request reads or changes only its own org's namespaces. A search with a user's read limit returns only rows inside that limit.
- Restore. Any namespace can be restored to any moment of the last 7 days, as a new namespace, searchable within 10 minutes.
- Fair share. An org over its quota gets a "retry later" answer for its own requests only. On a shared search server, one org gets at most 25% of the server's search time while others wait.
- Uptime. 99.95% of searches and writes succeed each month. A month has about 43,800 minutes. So 0.05% × 43,800 = 21.9 minutes of failures are allowed. A region loss, with 15 minutes before writes move, uses most of that.
1.6 The numbers
These are rough sums, the kind a candidate does at a whiteboard in a few minutes. Every number is our own assumption.
We use three load words:
- The daily average spreads a day's total evenly over 86,400 seconds.
- The busy hour is 2.4 times the average. We assume about 60% of a day's searches fall in the 6 busiest hours of the US working day. That is 60% ÷ 6 = 10% an hour, against 4.17% in an average hour.
- Design load is 3 times the average, always ready.
| Number | How we get it | Result | What it decides |
|---|---|---|---|
| Bytes per vector | 1,024 dims × 4 bytes = 4,096 bytes as the customer sends it. Stored in float16, 2 bytes a number: 2,048. As a 1-bit code: 1,024 bits ÷ 8 = 128 bytes | 4,096, 2,048 and 128 bytes | We store float16, half the bytes, and search the 1-bit codes first, 32 times smaller than the vector as sent |
| One stored row | float16 vector 2,048 + 1-bit code 128 + row ID, version and cluster number 32 + attributes 2,000 + keyword lists 500 | 4,708 bytes | Every storage sum below uses this row |
| All the data | 1 trillion rows × 4,708 bytes = 4.708 PB, which is 4,708,000 GB. In memory at $2 per GB-month: $9.416 million a month. In the object store at $0.02: $94,160 | 4.708 PB; 100 times cheaper in the object store | The object store holds the one true copy. Memory and SSD are only caches for what is searched |
| Namespaces | 30,000 orgs hold 100 million namespaces, one per end customer, user or agent. 99 million hold under 10,000 rows. Only 10 million get a search on a given day | 99% are small; 90% are idle each day | Small namespaces need no index. Idle ones cost only object storage |
| The hot set in memory | Rows searched in the last 10 minutes: 8% of 1 trillion = 80 billion. Their codes, IDs and cluster numbers take 160 bytes each: 80 billion × 160 = 12.8 TB. Centroids of the rows searched in the last day, 250 billion rows ÷ 1,000 × 2,048 bytes, add 512 GB | 13.31 TB in memory. A float32 graph index keeps the 4,096-byte vector plus 128 bytes of links to neighbor rows: 1 trillion × 4,224 bytes = 4.224 PB | A cluster index with 1-bit codes in memory, and full vectors on SSD |
| Searches | 4.32 billion a day ÷ 86,400 s = 50,000 a second. Busy hour × 2.4 = 120,000. Design load × 3 = 150,000. Almost every namespace fits one shard, so shard searches are about 1.1 per search: 165,000 a second | 150,000 searches a second | Search servers keep no data of their own, so we add them for load |
| Prairie's shards | 2 billion rows ÷ 100 million rows per shard. A shard of 100 million rows is 470.8 GB, which a new copy loads at 2 GB/s in about 4 minutes | 20 shards | Big namespaces are split by a hash of the row ID, and every search asks all their shards |
| Writes | AI agents save a memory after each turn of a chat, and synced documents change. So rows change faster than searches arrive. 43.2 billion rows a day ÷ 86,400 = 500,000 a second, × 3 = 1.5 million. In write requests of about 100 rows: 15,000 a second at design load | 1.5 million rows a second | Each namespace collects 100 ms of writes into one file, so the object store gets one file for each 100 ms window, not one per row |
| Object store requests | A write request of 100 rows usually fills one WAL file on its own. Each WAL file leads to about 4 file writes: itself, about one index-file write as its share, and both again in the second region. At the daily average: 5,000 write requests × 4 = 20,000 a second. At $0.005 per 1,000: 20,000 × 2,628,000 seconds in a month ÷ 1,000 × $0.005. Cold reads at design load, about 60,000 a second at $0.0004 per 1,000, add about $63,000 | $262,800 a month in writes, about $63,000 in reads | Index files are one per shard, sorted by cluster, never one per cluster |
| A cold search | A cold namespace with clusters: 4 round trips to the object store × 100 ms, plus 12 ms on our servers = 412 ms. A small one like Tina's has no clusters and needs 3: 312 ms. A graph index stored there would need about 10 round trips, one after another | 312 to 412 ms against about 1 s | A cluster index, whose reads can all go out in parallel after the first few |
What these numbers tell us: memory costs 100 times the object store, and 99% of namespaces are small and mostly idle. So a search must read tiny codes from memory and only a few full vectors from SSD. Everything else stays in cheap storage, while writes and deletes keep coming.