How to design RAG for company documents
The first sections are free. The deep dives, level expectations and quiz are part of Pro.
On this page
- The problem
- Clarifying questions
- The requirements menu
- Non-functional requirements
- Estimates
- Core entities
- The API
- The high-level design
- What breaks first
- The deep dives
- Entity fields
- Ingestion and chunking
- Retrieval and permissions
- Evaluation and guardrails
- Variants
- What each level is expected to show
- The 30-second answer
- Quiz
The problem
An internal question-answering assistant takes an employee's question, finds the passages in the company's documents that answer it, and has a language model write a short answer that cites them. Two things change constantly and shape the whole design: the documents, which have to be split and embedded again as people edit them, and who may open each one, which has to be enforced inside the search rather than after it. Question traffic is small next to the index. Uber reports about 45,000 questions a month across its on-call support channels, roughly one a minute, while the index covers millions of documents, so the hard parts are ingestion, permissions, and knowing when quality has dropped.
Clarifying questions
| Ask | Why it matters | A typical answer |
|---|---|---|
Which tools hold the documents, and how do we learn about edits and permission changes? | It decides what a connector is: a webhook receiver where the tool pushes changes, a poller where it doesn't, and whether the access list arrives with the content or has to be fetched separately. | Wikis, shared drives, ticketing and document tools. Each connector sends content plus an access list through |
How are permissions expressed: per user, per group, or both? | A list of group ids on each chunk stays short and changes less often than membership does; a list of individual user ids grows with the audience of the document and has to be rewritten whenever a person joins or leaves it. | Groups from the identity provider, plus the occasional document shared with one person. Treat a personal share as a group with a single member. |
How soon after an edit, or a revoked access, must answers reflect it? | Minutes means a queue and workers that re-embed on change; a day would allow a nightly rebuild. For revoked access it decides whether you need a second check at answer time. | Minutes for an edit. A revoked access should stop showing as fast as you can manage, and the design should close whatever gap remains. |
How many questions a day, and how long may an answer take? | It tells you whether a reranker and a grounding check per question are affordable, and it shows that query load is not where the scale lives. | Tens of thousands of employees. For a reference point, the on-call support channels in our figures receive about 45,000 questions a month. A few seconds per answer is fine. |
What counts as a citation? | If the reader must be able to open the source and see the passage, each chunk needs the document id and its text stored with it, and the answer must keep the mapping from claim to passage. | The document id and the passage the answer drew on, so the reader can open the source and check. |
Do we have labeled questions to start from, and who owns answer quality? | A question set with expected documents has to come from somewhere; if none exists, the design needs a feedback path that builds one. | No labeled set exists yet. Build one from support-channel questions and from feedback on answers. |
Non-functional requirements
| Requirement | What it forces |
|---|---|
Millions of documents in the index | Tens of millions of chunks, so the vector index is sharded from day one and sized from your own arithmetic, and ingestion is a pipeline that can be paused and resumed, not a script that runs to completion. |
Zero answers that cite a document the asker cannot open | The access list rides on each chunk, the search applies the asker's groups as a filter in the query itself, permission changes flow through the same pipeline as edits, and a second check against the document record at answer time covers the window before they land. |
Chunks of 512 to 1,024 tokens | The chunker splits on headings and paragraphs within that token budget. The chunk count decides the index size, and the chunk size decides how many passages fit in a prompt. |
Retrieval quality tracked with recall at K, MRR and NDCG | A stored question set with the documents each question should find, a runner that scores the retriever on each change, and stable document ids so the expected answers survive re-indexing. |
Estimates
| Quantity | Working | Result | What it sizes |
|---|---|---|---|
Chunks in the index | Take 5 million documents as a concrete reading of "millions", and assume about 10 chunks per document, each between 512 and 1,024 tokens: 5 million × 10 = 50 million chunks | About 50 million chunks | Both indexes, and the number of embeddings a full import has to produce. |
Raw vector storage | Assume 768-dimensional vectors, the size Pinecone's filtering walkthrough uses, at 4 bytes per float as Weaviate's sizing note states: 768 × 4 = 3,072 bytes, about 3 KB a vector; 50 million × 3 KB ≈ 150 GB raw. Weaviate budgets 6 GB per million 1,024-dimensional vectors against 4 GB raw, a factor of 1.5 for the index structure: 150 GB × 1.5 ≈ 225 GB | About 150 GB of raw vectors, about 225 GB with index overhead, before the chunk text | The memory the vector index needs, and from that the shard count. |
Vector index shards | Assume one shard is allowed about 50 GB of index in memory (state the assumption out loud): 225 GB ÷ 50 GB ≈ 4.5, so 5 shards; at ten times the documents, 2,250 GB ÷ 50 GB = 45 shards | About 5 shards now, about 45 if documents grow ten times | How many shards each filtered question fans out to, and when that fan-out becomes the bottleneck. |
Question rate | 45,000 questions a month ÷ (30 days × 86,400 seconds) ≈ 0.017 a second, about 1 a minute | About 1 question a minute on average | Query load is tiny, so a reranker, a grounding check and a few lookups per question are affordable; the scale lives in the index and in ingestion. |
Time for a full import on one embedding worker | 50 million chunks at an assumed 100 embeddings a second from one worker = 500,000 seconds ≈ 6 days | About 6 days on a single worker | Why a bulk import runs many workers off the queue and has to resume from where it stopped instead of restarting. |
Steady-state re-embedding load | Assume 1% of documents change a day: 50,000 documents × 10 chunks = 500,000 embeddings a day ≈ 6 a second | About 6 embeddings a second | The everyday load on the ingest queue and the embedding service, small next to an import. |
Context tokens per question | Assume 10 passages reach the prompt: 10 × 1,024 tokens = 10,240 tokens at the upper chunk size; 10 × 512 = 5,120 at the lower | About 5,120 to 10,240 tokens of passages per question | The size of each LLM call, and why a reranker trims the merged list to a handful before the prompt is built. |
Core entities
| Entity | What it holds |
|---|---|
Document | One row per source file, carrying the version the index currently reflects and who may open it. |
Chunk | A passage cut from one version of a document, stored with its vector and the group ids allowed to read it; the unit both indexes hold. |
Answer | One row per question asked, keeping the text and the chunks it cited so feedback and audits can find them. |
Evaluation set item | A question paired with the documents a good retriever should return for it. |
Ingest job | One queued unit of work: index this version of this document, or remove it. |
The API
| Endpoint | Notes |
|---|---|
| Resolves the caller's groups, embeds the question, searches the vector and keyword indexes with the group filter, merges and reranks, rechecks each kept passage against the document record, then calls the model with those passages and an instruction to answer from them and cite them. Each answer is also stored as a row, so feedback can refer to it later. When nothing clears the relevance bar it says so instead of answering. |
| Called by connectors, not by users. Writes the document row with a new version and puts an ingest job on the queue; the response means "queued", not "indexed". Idempotent on the source id and the source's own revision marker, so a connector that retries does not create a second version. |
| Marks the row deleted and queues a removal job that deletes the document's chunks from both indexes. Until that job runs, the answer-time check sees |
| Stores the verdict against the answer. Unhelpful answers are the raw material for new evaluation set items: someone labels the documents that should have been found, and the question joins the set. |
The high-level design
Step 1 of 4
A straight line from question to cited answer
Start with the simplest thing that produces a cited answer. Connectors copy documents out of the company tools once; workers split each one into chunks between 512 and 1,024 tokens, embed them and write them to a vector index. An employee's question goes to the ask service, which embeds it, pulls the nearest chunks and sends them to a language model through a gateway, with an instruction to answer from those passages and name the ones it used. That is the usual shape of a retrieval pipeline: chunked content, vectors in an index, and a model told to answer from the supplied context and point at the source. Two gaps remain. The copy ran once, so an edit does not reach the index. And nothing looks at who is asking.
What breaks first
The deep dives
Ingestion and chunking. A team edits a policy page and someone asks about it a minute later. How does the new text reach the index, what happens to the chunks of the old text, and what does importing millions of documents look like when the embedding service has a bad day?
Retrieval and permissions. An intern asks about salaries, and the documents that answer it are open to a few people in HR. How do you find the right passages for a question like that, and how do you keep a passage the intern may not read out of the prompt?
A concept that helps here: Hybrid search and reranking
A concept that helps here: Inverted indexesEvaluation and guardrails. After a change to how documents are split, answers start citing the wrong documents. How would you find out, how soon, and what keeps a wrong or ungrounded answer from reaching the employee?
A concept that helps here: Evaluating retrieval and grounded answers
A concept that helps here: Retrieval-augmented generationConcepts this guide uses
- Retrieval-augmented generation
- Retries and dead-letter queues
- Sharding and partition keys
- Authorization models
- Hybrid search and reranking
- Inverted indexes
- Evaluating retrieval and grounded answers
Sources
- Uber Engineering: Genie, Uber's Gen AI On-Call Copilot
- Microsoft Learn: Security filter pattern in Azure AI Search
- Pinecone: The missing WHERE clause in vector search
- Pinecone: Chunking strategies for LLM applications
- Elasticsearch reference: Reciprocal rank fusion
- Weaviate documentation: Best practices (resource sizing)
- Wikipedia: Mean reciprocal rank
- Cohere documentation: Rerank models
- Ragas documentation: Faithfulness
- Wikipedia: Discounted cumulative gain
- Amazon SQS developer guide: Using dead-letter queues