Skip to content

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
Practice this question

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

AskWhy it mattersA 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 POST /v1/documents; some tools push change events, others have to be polled.

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.

The requirements menu

RequirementScopeWhy

Ingest documents from the company’s tools and keep them current

Core

The index is a copy of content that lives elsewhere, and the copy drifts the moment an edit lands. Connectors, a queue and versioned chunks all follow from this one line.

Answer a question in plain language, citing the passages used

Core

The product itself. Citations are what let an employee check the answer, and they shape the chunk record: the text and the document id travel with the vector.

Use only content the asker is allowed to open

Core

The requirement that makes this different from public search. It puts the access list on each chunk and the permission filter inside the search.

Measure answer and retrieval quality over time

Core

A change to chunking, an embedding model or ranking can make answers worse with no error anywhere. A stored set of questions, each with the documents it should find, is how you find out.

Delete a document and stop citing it within minutes

Optional

Worth taking: the API already has a delete, and it tests whether your chunk model can remove a document from both indexes. Skip it if time is short, because the versioned-replace path covers most of the same ground.

Let employees mark an answer helpful or not

Optional

Cheap to add and it feeds the evaluation set with real questions. Take it if the interviewer leans toward quality; leave it if the round is heading into permissions.

Follow-up questions that keep the thread's context

Optional

Users expect it, and it changes the ask path: the previous turns have to be rewritten into a standalone query before retrieval. Name it and park it unless asked.

Stream the answer as it is written

Optional

Nicer to use, but it complicates the output guardrail, which wants the whole answer before it decides. Mention the tension and move on.

Answer from chat history as well as documents

Out of scope

Far more items, each short, with permissions by channel membership. It is a good variant to raise at the end, not a first requirement.

Summarize a whole document on request

Out of scope

A different retrieval shape: one document, all of its chunks, no ranking. Easy to bolt on later; it does not change the core design.

Training or fine-tuning the model

Out of scope

Retrieval is how fresh and permissioned content reaches the model; a fine-tuned model bakes content in at training time, so edits need retraining and per-document permissions are hard to enforce inside the weights. Say that and set it aside.

Agents that take actions in other tools

Out of scope

Acting on tools brings its own permission and safety problems. This round is about reading, not writing.

Search of the public web

Out of scope

A different corpus with no access lists and no connectors you control. Keep the design to internal sources.

Non-functional requirements

RequirementWhat 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

QuantityWorkingResultWhat 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

EntityWhat 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

EndpointNotes

POST /v1/ask { question } → { answer, citations: [{ document_id, passage }] }

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.

POST /v1/documents { source_id, content, access_list } (from connectors)

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.

DELETE /v1/documents/{id}

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 deleted_at and drops any passage from it.

POST /v1/answers/{id}/feedback { helpful }

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

questionfiltercopypassagesConnectorsWorkersVectorsEmployeeAsk serviceLLM gateway

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.

changesquestionfeedbackreplaygroupsfilterfiltertopanswerConnectorsIngest queueWorkersVectorsKeywordsEmployeeAsk serviceQuestion setGroupsRerankerLLM gatewayGuardrails
The whole design

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?

A concept that helps here: Retrieval-augmented generationA concept that helps here: Retries and dead-letter queuesA concept that helps here: Sharding and partition keys

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: Authorization modelsA concept that helps here: Inverted indexes

Evaluation 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: Retrieval-augmented generation

Concepts this guide uses

Sources

  1. Uber Engineering: Genie, Uber's Gen AI On-Call Copilot
  2. Microsoft Learn: Security filter pattern in Azure AI Search
  3. Pinecone: The missing WHERE clause in vector search
  4. Pinecone: Chunking strategies for LLM applications
  5. Elasticsearch reference: Reciprocal rank fusion
  6. Weaviate documentation: Best practices (resource sizing)
  7. Wikipedia: Mean reciprocal rank
  8. Cohere documentation: Rerank models
  9. Ragas documentation: Faithfulness
  10. Wikipedia: Discounted cumulative gain
  11. Amazon SQS developer guide: Using dead-letter queues
Sign in to report a mistake