RAG System Design: Building an Enterprise RAG Assistant
Walk the enterprise RAG interview case: index sizing, ingestion and query paths, permission-aware retrieval, hybrid search with RRF, freshness and citations.
New12 min read

RAG system design is the AI-era interview question that looks easy and is not: "let employees ask questions over the company's documents and get cited answers". A demo with one PDF and a vector store takes an afternoon. The real system has millions of documents, permissions that keep changing, many tenants on one platform, and one rule that cannot bend: no employee may ever see text from a document they are not allowed to open.
This guide is for backend developers preparing for senior system design rounds or building an internal assistant at work. You will walk one full case: requirements, index sizing, the API, the ingestion and query paths, and the usual deep dives: permission-aware retrieval, hybrid search with reciprocal rank fusion and re-ranking, index freshness, and checkable citations.
We follow the five TRIBE steps from the TechTribers System Design book: Think requirements, Rough estimates, Interfaces, Blueprint, Evolve.
In this guide
- RAG and vector search in two minutes
- T: Think requirements
- R: Rough estimates
- I: Interfaces
- B: Blueprint, the ingestion and query paths
- E: Evolve, the deep dives
- What to say in the interview
From the book: this guide is based on Case 15 of System Design 2026: Classic + AI Era, where 18 case studies are worked step by step, with runnable Java labs. Read the free 5-page sample on the book page.
RAG and vector search in two minutes
Retrieval-augmented generation (RAG) means: find the passages that answer a question, put them in the prompt, and let the model answer from them. Documents are split into chunks of a few hundred tokens so only the relevant part goes in.
Search by meaning uses embeddings: a model maps each text to a vector of fixed length, placing texts with related meaning near each other. "Can my friend travel on my Tatkal ticket?" shares no words with a help page titled "transfer of reserved tickets", yet their vectors sit close. Chunks are embedded once at ingestion; each question is embedded at query time and matched to its nearest chunk vectors.
Comparing the question with every vector is exact but slow, so real systems build an approximate index:
- Exact scan: perfect recall, but reads every vector. Fine for small sets or after a tight filter.
- HNSW: walks layered proximity graphs from the top down. Better speed-recall trade-off, slower build, more memory. The usual default.
- IVF (IVFFlat): searches only the clusters nearest the query. Faster build, less memory; recall depends on how many lists you probe.
The key design fact for RAG: retrieved chunks go into the prompt, so the prompt is the leak. Anything retrieval returns, the model may repeat.
T: Think requirements
Functional
- Answer questions from wikis, PDFs and tickets, with citations.
- Sync sources: edits, deletes and permission changes.
- Serve many tenants from one platform.
Non-functional
- Zero leaks: never use a chunk the user may not open.
- A revoked permission applies within minutes; a document edit within an hour.
- First token in about 2 seconds, and groundedness is measured.
Out of scope: fine-tuning a model, writing back to the sources, voice and translation.
Three questions to ask first
- Who decides access: the sources' ACLs or our own rules? This decides where permissions live. (An ACL, access control list, says which users or groups may open a document.)
- How many documents, and how often do they change? This sizes the index and the re-embedding load.
- May tenants share one index? This decides how you isolate them.
R: Rough estimates
These are the book's estimates, computed by its script estimates/cs15_enterprise_rag.py from stated assumptions; they are not measurements. Assumptions: 10 million documents, 20 chunks each (about 500 tokens per chunk), 1,024-dimension float32 embeddings (4 bytes per dimension), 2% of documents changed a day, 1 million questions a day with peak factor 3, 64 GB of RAM per index node for vectors, 7 daily snapshots.
- Chunks (vectors) in the index: 200 million.
- Bytes per vector: 1,024 x 4 = 4,096 bytes, about 4.1 KB.
- Vector index size: about 820 GB.
- Index shards: 820 GB / 64 GB rounds up to 13 shards, and every query hits all 13.
- Chunks re-embedded per day: about 4 million, or about 46 embedding calls per second on average.
- Query rate: about 12 questions per second on average, about 35 at peak.
- Shard searches at peak: 35 x 13, about 450 per second.
- Snapshot storage for 7 days: about 5.7 TB.
The sentence to say: traffic is small, about 35 questions a second at peak. The 820 GB of vectors and the 4 million changed chunks a day drive the design, not the query rate. The script also notes that int8 quantisation would cut vector size about four times, which you will need at 10x.
I: Interfaces
POST /v1/ask: ask a question; the answer streams over SSE with citations. Answers: 200 stream, 429.GET /v1/chunks/{id}: open a cited passage. The ACL is checked again here. Answers: 200, 403, 404.doc.changedevent: a new version, a new ACL, or a delete. Read by ingestion.
Each chunk is one document in the search index and carries its permissions. A sketch of its shape, using the fields the book names (the text field and all values are illustrative, and the vector is cut short):
{
"tenant_id": "acme",
"doc_id": "wiki-4821",
"version": 7,
"text": "Refunds for cancelled orders are issued within ...",
"vector": [0.0132, -0.0841, 0.0277],
"allowed_groups": ["sales", "all-staff"]
}B: Blueprint, the ingestion and query paths
The design has two paths that meet at the index.
Ingestion path
Connectors read the change feeds of the wiki, drive and ticket system and put document and ACL events on a change queue. Ingestion parses each document, strips hidden text, chunks it and tags every chunk with its ACL. The embedder embeds only changed chunks into a hybrid index that holds vectors, a BM25 keyword index and the ACL fields together.
Query path
- The employee asks; single sign-on (SSO) says who they are.
- The RAG API reads the user's groups from a cache that lives about a minute.
- Hybrid search runs with the tenant and the groups as a filter.
- A cross-encoder re-ranks the allowed shortlist.
- The LLM answers from the top chunks and cites each one; the API checks every cited id.
Why each store
- Search engine (vectors + BM25): chunks, vectors and ACL fields, so one query filters and matches both words and meaning.
- PostgreSQL: documents, versions, ACLs and connector cursors; the source of truth that can rebuild the index.
- Object storage: raw files, parsed text and snapshots, to re-chunk without fetching from the sources again.
E: Evolve, the deep dives
Deep dive 1: permission-aware retrieval
Any forbidden chunk that gets into the prompt can end up in the answer. So remove such chunks inside the search itself: the API, not the model, attaches tenant_id and the user's groups as a filter. OWASP's LLM08:2025, "Vector and Embedding Weaknesses", asks for this: permission-aware vector stores and strict access partitioning.
OpenSearch documents three ways to combine a filter with vector search, a classic follow-up question:
- Post-filtering (search, then drop): simple and fast, but for a tight filter it can return far fewer than k results. Fine when most users see most chunks.
- Pre-filtering, then exact search: never misses, but slow when the allowed set is large. Good when a user sees only a small set.
- Filtering during the approximate search: still returns k results and stays fast, but needs engine support. The default for ACLs.
In OpenSearch the third option is a filter inside the knn query clause, on a knn_vector field that uses the Lucene, Faiss or JVector engine. A sketch, adapted from the efficient filtering example in the OpenSearch docs (index and field names are this design's, the vector is cut short):
POST /chunks/_search
{
"size": 100,
"query": {
"knn": {
"vector": {
"vector": [0.0132, -0.0841, 0.0277],
"k": 100,
"filter": {
"bool": {
"must": [
{ "term": { "tenant_id": "acme" } },
{ "terms": { "allowed_groups": ["sales", "all-staff"] } }
]
}
}
}
}
}
}A terms query matches a chunk if any of the listed groups is in its allowed_groups. The groups come from the API's cache, never from the prompt.
Deep dive 2: hybrid search, RRF and re-ranking
Vectors are good at meaning and bad at exact strings, and employees also search for ticket ids, PNR numbers and names, where keyword search wins. So run both: BM25 (the classic keyword ranking) and the vector index, each returning a ranked list.
The two lists have scores on different scales, so you merge them by rank with reciprocal rank fusion (RRF): each list adds 1 / (k + rank) to a document's score. A chunk ranked high in both lists wins, and the two scoring scales never need to agree. A minimal sketch in Java:
// Sketch: fuse ranked lists of chunk ids with reciprocal rank fusion.
static Map<String, Double> rrf(List<List<String>> rankedLists, int k) {
Map<String, Double> score = new HashMap<>();
for (List<String> list : rankedLists) {
for (int i = 0; i < list.size(); i++) {
int rank = i + 1;
score.merge(list.get(i), 1.0 / (k + rank), Double::sum);
}
}
return score; // sort by value, highest first
}If your engine does this for you, OpenSearch (from version 2.19) has a score-ranker processor whose rank_constant defaults to 60.
Then re-rank: a slower, more accurate cross-encoder scores a shortlist of about 100 fused candidates, and only the best few go into the prompt.
Deep dive 3: keeping the index fresh
Stale content gives two failures: quoting a policy that has since changed is merely wrong, while quoting a document whose access was revoked is a leak. The book's approach:
- Connectors read change feeds and reconcile against the source nightly.
- Only chunks whose text hash changed are re-embedded: about 46 calls a second on average.
- An ACL change updates metadata only, on a fast lane that skips embedding.
- A delete removes every chunk of the document at once.
- A new embedding model means a full re-index beside the old one, then an alias switch.
The trade-off: a periodic full crawl is simpler but hours stale; checking ACLs at the source per answer is current but slow.
Documents are also untrusted input. Indirect prompt injection (OWASP LLM01) hides instructions inside documents, for example white-on-white text in a resume. Strip hidden text at ingestion, mark retrieved text as data in the prompt, and give the assistant no tools that take actions.
Deep dive 4: citations and groundedness
Nobody can verify an answer with no source, and wrong answers sound as confident as right ones. So number each chunk in the prompt, ask for a cited number after every claim, and have the API reject any number it never sent.
Then gate releases on a golden set: real questions with the documents that should answer them. Measure retrieval (did the right chunk make the top k?) and groundedness. Ragas, for example, scores faithfulness from 0 to 1 as the share of the answer's claims that the retrieved context supports. A prompt, model or chunking change ships only if both scores hold. The book weighs three ways to check answers: code checks are free and exact but blind to meaning; an LLM judge agrees with humans over 80% of the time but has position and verbosity bias; human review is the ground truth but slow, so use it to calibrate the judge.
What breaks at 10x
- The index grows ten times past 820 GB. Quantise vectors to int8 (about four times smaller) or keep vectors on disk.
- One huge tenant slows the shared shards. Give it its own index; small tenants share one.
- Re-ranker GPUs become the cost. Re-rank 50 instead of 100, and cache answers keyed by question and group set.
Practice follow-ups: a user loses access (ACL fast lane, short groups-cache TTL, evict cached answers); answers must cite a PDF page (keep page offsets per chunk); a tenant asks to be deleted (drop its index or delete by tenant_id; let snapshots expire).
What to say in the interview
One line to say in your own words: hybrid search, BM25 plus an HNSW vector index fused with RRF, then a cross-encoder re-ranks the top hundred; you pay latency and cost per question for answers grounded in the right documents. Interviewers listen for four things:
- You filter by tenant and groups inside the search.
- You know why post-filtering loses results.
- You gate releases on groundedness and retrieval scores.
- You treat documents as untrusted input.
Red flags: letting the model decide what the user may see, caching answers without permissions in the key, and re-embedding everything nightly. Close with the trade-offs: filtering during the search needs engine support; a groundedness gate slows releases; a shared index is cheaper but isolation rests on one filter.
Go deeper
This article follows Case 15, "Enterprise RAG assistant", and building block 16, "AI building blocks", in System Design, 2026 Edition: Classic + AI Era (TechTribers Guide Series, Book 2). There you get the full estimate table with the reason for each assumption, the step-by-step permission-filter figure, the release gate for groundedness evals, practice follow-ups, and a one-page final design to redraw from memory.
See it at System Design: Classic + AI Era. The product page has a free 5-page sample.
Related reading
- Spring AI RAG tutorial with pgvector (the code side of RAG)
- LLM system design: designing a ChatGPT-style chat assistant
- A step-by-step system design interview framework
Official references used here: OpenSearch efficient k-NN filtering, OpenSearch score ranker (RRF), OWASP LLM08:2025 and Ragas faithfulness.
FAQ
What is RAG system design?
It is the design of a system that retrieves passages from your own documents and gives them to a language model to answer from. At enterprise scale it covers ingestion, chunking, a vector and keyword index, permission filtering, re-ranking, freshness and evaluation.
How do you enforce document permissions in RAG?
Store each chunk's tenant and allowed groups in the index. The API looks up the user's groups and adds them as a filter inside the search, so forbidden chunks never match and never reach the prompt. Never ask the model to hide them.
Why is post-filtering a problem in vector search?
The search returns the top k nearest chunks and only then drops the forbidden ones. With a tight filter most of them may go, leaving far fewer than k results, or none. Filtering during the search keeps k allowed results.
What is hybrid search with RRF?
Hybrid search runs keyword search (BM25) and vector search for the same question. Reciprocal rank fusion merges the ranked lists by adding 1 / (k + rank) for each list a document appears in, so the score scales never need to be compared.
How big is a vector index for 10 million documents?
In the book's estimate, 10 million documents at 20 chunks each give 200 million vectors; at 1,024 float32 dimensions that is 4,096 bytes per vector and about 820 GB in total, which needs 13 shards of 64 GB RAM.





