In short
To make an AI answer from your company's documents you use RAG (retrieval-augmented generation): a search engine finds the relevant passages in your documents and the model writes the answer using only those passages, citing where each fact comes from. It works well when documents are in order, search filters by each person's permissions and quality is measured with real questions.
The usual way to make an AI answer from your company’s documents is RAG (retrieval-augmented generation). A RAG system combines two parts: a search engine that finds, among your documents, the passages that answer the question, and a language model that writes the answer from those passages and cites where each fact comes from.
The US National Institute of Standards and Technology (NIST) defines it as a generative AI system in which the model is paired with a separate information retrieval system, which allows its knowledge to be changed without retraining the model. The idea was set out in a 2020 research paper and today it underpins many assistants that answers questions about internal documentation: manuals, procedures, contracts, regulations or incident histories.
What is RAG and how does it work, step by step?
RAG is a two-phase process: first the documents are prepared once (and kept up to date), then, for each question, the useful passages are retrieved and handed to the model. The model does not “learn” the documents: it reads them at the moment it answers.
Preparing the documents (indexing) involves these steps:
- Extract the text from each document: PDF, Word, emails, intranet pages. Scanned files need optical character recognition (OCR).
- Split the text into passages (chunks) of a few paragraphs, respecting sections and tables.
- Turn each passage into a vector (an embedding): a numerical representation of its meaning that allows searching by sense rather than only by exact words.
- Store passages, vectors and metadata (document, version, date, who may see it) in an index.
And for each question:
- The search engine retrieves the passages most similar to the question, filtered by what the person is allowed to see.
- An optional reranking step puts first the passages that actually answer the question.
- The model receives the question and those passages, with the instruction to answer only from them and cite the source.
- The answer comes back with links to the source documents so it can be checked.
Why isn’t uploading documents to a chat enough?
Uploading a few documents to a chat works for querying a specific contract or report, but not for an organisation’s documentation. There are three practical reasons: volume, answer quality with very long contexts, and access control.
- Volume. A model can only read a limited amount of text per question (its context window). Anthropic, for example, notes that if the whole knowledge base fits in about 200,000 tokens (around 500 pages) you can put all of it in the prompt and skip RAG (Anthropic, September 2024). The document archive of a mid-sized company or a town council easily exceeds that.
- Quality with long contexts. More text does not guarantee better answers. A study published in Transactions of the Association for Computational Linguistics found that models answered best when the relevant information was at the beginning or end of the input, and that performance dropped significantly when it sat in the middle (Liu et al., 2023). Models have improved since then, but the lesson holds: giving the model a few relevant passages is more reliable than giving it everything.
- Access control. A chat with uploaded documents does not know that the executive payroll is for Human Resources only. A well-built RAG system filters by each person’s permissions before the model reads anything.
In addition, a RAG system updates its documents automatically from the document management system, whereas whatever is uploaded to a chat stays at the version of the day it was uploaded.
How do you control who sees which document?
Control happens in the search layer, not in the model: each passage stores who may see it and the search is filtered with the identity of the person asking. That way the model never receives a passage that person could not open in the source system.
The pattern is well established in enterprise search. The Azure AI Search documentation, for instance, describes how to store on each document the identifiers of the groups with access and apply a filter with the caller’s groups on every query (Microsoft Learn). The same idea applies to any vector database that supports metadata filters.
The OWASP Gen AI Security Project lists this risk among the top ten for applications built on language models. It warns that inadequate or misaligned access controls can lead to unauthorised access to sensitive information, and recommends permission-aware stores with fine-grained access control, logical partitioning of data and immutable logs of every retrieval (OWASP, LLM08:2025).
In practice, four things are worth checking:
- Permissions come from the source. The index copies groups from the document management system or the corporate directory; they are not maintained by hand somewhere else.
- They are synchronised. A revoked permission or a deleted document has to disappear from the index within a known time.
- Filtering happens before search. Retrieving everything and discarding the forbidden passages afterwards lets data flow through parts of the system that should not see it.
- Everything is logged. Who asked what, which passages were retrieved and what the model answered.
For a public administration, these logs are also part of the traceability required to audit the system.
Which documents give good results and which don’t?
A RAG system answers only as well as its documents allow: if the information is correct, current and can be extracted as text, the answers are good; if there are three versions of the same procedure, the system may cite the wrong one.
| Document type | How it works in RAG | What needs preparing |
|---|---|---|
| Manuals and procedures in Word or text-based PDF | Well | Mark the current version and retire old ones |
| Contracts and tender documents | Well for locating clauses | Keep clause number and page for citations |
| Scanned PDFs | Only after OCR | Review a sample of the extracted text |
| Spreadsheets and tables | Fair | For exact figures, query the database rather than the document |
| Emails and chats | Fair | Filter by relevance and permissions; a lot of noise |
| Drawings, images and diagrams | Limited | Searchable descriptions or metadata |
Questions about figures (“how much did we invoice this customer in March?”) are not well served by RAG over documents: for those the system needs to query the ERP or the database directly. Many projects combine both: RAG for what is written in documents and system queries for structured data.
How do you improve answer quality?
Many failures in a RAG system come from search, not from the model: if the right passage is not retrieved, the model cannot answer well. That is why the most effective improvements usually lie in how documents are split and searched.
Three techniques with published results:
- Hybrid search. Combining search by meaning (vectors) with exact keyword search, which is better at finding codes, references and proper names.
- Context in each passage. Adding to each passage a sentence saying which document and section it comes from, so it keeps its meaning once separated from the rest.
- Reranking. A second model scores the retrieved passages and keeps only the best.
In tests Anthropic published in September 2024, adding context to passages reduced retrieval failures by 35%; combined with keyword search, by 49%; and with reranking, by 67% (Anthropic). These are results on their own test sets: on your documents the figures will differ, which is why they have to be measured.
To measure them, you build a set of real questions with their correct answer and the document where it is found, written together with the people who use that documentation every day. Every change is checked against it: whether it retrieves the right passage, whether the answer is faithful to the document and whether it says “I can’t find it” when the answer is not there.
Where do you start a RAG project on internal documents?
Start with a bounded set of documents and a group of users with real questions, not by indexing the whole company. A sensible order:
- Pick a use case with frequent, repetitive questions: internal support, questions about procedures, answering citizens about specific procedures.
- Inventory the documents for that use case: where they are, who maintains them, which version is valid and who may see them.
- Write the evaluation question set with the people who answer those questions today.
- Build a first version on the real documents, with permissions and citations from day one.
- Put it in the hands of real users, review the failed answers and fix documents, chunking or search.
- Decide where it runs: if the documents cannot leave the organisation, the index and the model can run on its own infrastructure.
This is how we work at Referent: an on-site diagnosis with the people who live the problem, a first version on real data built with the client’s team, and deployment in our cloud, the client’s cloud or on their own servers, with traces of everything the system does. See our method, the custom AI agents we build and how we work with public administrations.
Frequently asked questions
Do you need to retrain the AI model on the company's documents?
No. With RAG the model is not retrained: documents are stored in a separate index and, for each question, the relevant passages are passed to the model. Updating the system's knowledge means updating the index. NIST defines it in those terms: RAG lets you change what the system knows without retraining the model.
Can a RAG system make up an answer?
It can. The risk is reduced by telling the model to answer only from the retrieved passages, to cite the source of every statement and to say "I can't find it" when no relevant passage exists. Citations let the reader check the answer against the original document.
What happens to scanned PDFs in a RAG system?
A scanned PDF is an image: unless optical character recognition (OCR) is applied before indexing, the search engine finds nothing in it. It is worth reviewing a sample of the extracted text, especially tables, stamps and two-column layouts, because extraction errors turn into incomplete answers.
How often should a RAG index be updated?
As often as the documents and, above all, their permissions change. The usual approach is automatic synchronisation with the document management system: new documents, replaced versions and deletions. A permission revoked at the source that never reaches the index leaves information visible to someone who should no longer see it.
Sources
Consulted while writing this article.
- retrieval-augmented generation (RAG) - Glossary. NIST Computer Security Resource Center.
- Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks. arXiv (Lewis et al., NeurIPS 2020).
- Lost in the Middle: How Language Models Use Long Contexts. arXiv (Liu et al., TACL).
- Introducing Contextual Retrieval. Anthropic.
- LLM08:2025 Vector and Embedding Weaknesses. OWASP Gen AI Security Project.
- Security Filter Pattern - Azure AI Search. Microsoft Learn.