# What is a RAG system and how do you build one with AI in your company?

A RAG system searches the organization's documents for passages each time someone asks a question and hands those passages to a language model, which answers based on them and cites the source. Learn the parts of the system, when you need one, the ways to build it and a step-by-step process that tests both search and answers.

Canonical URL: https://thecompanybrain.com.br/en/articles/rag-system-company
Authors: Luiz Gardelin
Updated: 2026-11-23T12:10:00.596Z

![Three-dimensional illustration of two soft tubes, one orange and one blue, running side by side and intertwining in a loop, on a light beige background.](https://thecompanybrain.com.br/api/media/file/recurso-sistema-rag-empresa.webp)

The Company Brain, site thumbnail

A RAG system is a system that, for each question, searches the organization's document base for passages and hands those passages to a language model, which writes the answer from them and states where the information came from. RAG stands for [retrieval-augmented generation](/en/glossary/retrieval-augmented-generation): the system retrieves the material, augments the question with it and only then generates the text. If someone in your company asked for "a RAG with our documents", this article helps you understand the parts of that system, decide whether you really need it, choose how to build it and test the first one before releasing it to the team.

## Key points

- A RAG system searches company documents for passages on every question and hands them to a model that answers from them and cites the source, unlike attaching files to a chat, where the person picks the material, or fine-tuning, which changes the model without consulting documents.
- A company needs a RAG system when the lookup is recurring and the documents are many, change often, have different permissions per person or require answers with a source; with a few stable documents everyone can see, an assistant with attached files is usually enough.
- Among Databricks customers using generative AI, 70% supplemented their models with retrieval and vector databases, but a review of 63 studies on RAG in companies found only 15.9% measuring business impact and 38.1% addressing access control.
- The system can be built with the file search feature of a platform you already pay for, with a managed cloud service or through in-house development, and the choice depends on document volume, permissions and where the lookup will be used.
- The first system starts with real questions tied to a reference passage, goes through extraction, chunking, hybrid search and an access filter before the model, and is released only after search and answers are tested separately and someone owns reindexing and retesting.

## How does a RAG system work, part by part?

A RAG system works in two phases: preparing the documents, done before any question, and the query, which happens each time someone asks. In preparation, the system extracts text from the files, splits it into smaller passages and builds a [search index](/en/glossary/search-index). In the query, it looks in the index for the passages closest to the question, checks whether the person may see each one, builds an input for the model with the question and the passages and returns the answer with its sources.

IBM describes [four main components](https://www.ibm.com/br-pt/think/topics/retrieval-augmented-generation): the [knowledge base](/en/glossary/knowledge-base), the retriever, the integration layer that coordinates the flow and the generator, which is the language model. For whoever commissions the system, each part corresponds to a decision.

| Part | What it does | Decision you make | Most common failure |
| --- | --- | --- | --- |
| Extraction | Pulls text from PDFs, spreadsheets and pages | Which formats go in and how to handle scanned PDFs and tables | A table becomes scrambled text and the value is lost |
| Chunking | Splits each document into passages | Passage size and whether it carries title and section | A passage too large becomes generic; too small loses meaning |
| Index | Stores passages in a searchable form, usually as a [vector representation](/en/glossary/vector-representation) | Where the index lives and how often it is rebuilt | A revoked document stays in the index |
| Search | Finds the passages closest to the question | [Semantic search](/en/glossary/semantic-search), keyword search or both | A product code or regulation number is not found |
| Access filter | Removes passages the person may not see | Which system the [access permissions](/en/glossary/access-permission) come from | The model summarizes a restricted document for someone who should not see it |
| Input assembly | Combines instructions, question and passages | How many passages go in and what to do when none fits | The right passage is left out for lack of room in the [context window](/en/glossary/context-window) |
| Generation | The model writes the answer and cites the source | Answer format and the sentence to use when there is no basis | The answer states something that is not in the passage |

Vector search compares meanings: the question and the passages become lists of numbers, called [embeddings](/en/glossary/embedding), and the system looks for the passages with the closest numbers. Keyword search, called [lexical search](/en/glossary/lexical-search), looks for exact terms. Combining both, [hybrid search](/en/glossary/hybrid-search), helps when documents contain codes, acronyms and proper names.

On passage size, IBM notes that [passages that are too large become too general and passages that are too small lose coherence](https://www.ibm.com/br-pt/think/topics/retrieval-augmented-generation). There is no single right number. Size is adjusted during testing, by checking whether the retrieved passage contains the whole answer.

## What is the difference between RAG, attaching documents to a chat and fine-tuning?

The difference between RAG, attaching documents to a chat and fine-tuning lies in who chooses the material and when the knowledge reaches the model. When you attach a file to an assistant, you choose the material and it enters that chat in full. In RAG, an automatic mechanism chooses passages for each question from a base maintained by the organization. In [fine-tuning](/en/glossary/fine-tuning), the model is trained again with examples and starts behaving differently, without consulting any document when it answers.

The Brazilian federal government's Governo Digital guide for public servants makes this distinction explicitly: when the person gathers documents and inserts them into the [prompt](/en/glossary/ai-prompt), without automated search, [this is context augmentation, not RAG](https://www.gov.br/governodigital/pt-br/infraestrutura-nacional-de-dados/inteligencia-artificial/publicacoes/guia-de-rag).

| Criterion | Attaching documents to a chat | RAG system | Fine-tuning |
| --- | --- | --- | --- |
| Who chooses the material | The person asking | The search mechanism | Whoever prepares the training examples |
| When knowledge comes in | In the chat | On every question | Before use, in training |
| Documents that change | The person must attach the new version | Updating the index is enough | Requires new training |
| Different permissions per person | Depend on who attaches | Applied in search | Do not apply to what the model learned |
| Cites the source | Only if the person asks | Can cite passage and document | No |
| Suited to | One-off task with few files | Recurring lookup across many documents | Consistent output format or style |

## When does your company need a RAG system?

Your company needs a RAG system when looking things up in documents is recurring and attaching files to a chat no longer works. The usual signs are these:

- The documents do not fit in a chat, or the person does not know which one holds the answer.
- Sources change often, and the answer must use the current version.
- Different people may see different documents.
- The answer must point to the document and passage so it can be checked.
- The same lookup serves many people or another tool, such as an agent or a form.

If the team consults a few stable documents that everyone can see, attaching the files to a corporate assistant or creating a project with those files on a platform you already pay for is usually enough. The article on [how to create an AI virtual assistant for your company](/en/articles/create-ai-virtual-assistant-for-your-company) covers that choice from the side of the application the team uses.

## What does the data show about RAG use in companies?

The available data shows that supplementing models with document search is common among companies already using [generative AI](/en/glossary/generative-ai), and that few projects measure results. Among Databricks customers using generative [AI](/en/glossary/artificial-intelligence), [70% used tools, retrieval systems and vector databases](https://www.databricks.com/blog/state-ai-enterprise-adoption-growth-trends) to supplement their models, in data from February 2023 to March 2024. In the same base, use of vector databases, which support RAG applications, [grew 377% in one year](https://www.databricks.com/blog/state-ai-enterprise-adoption-growth-trends). The figures describe that platform's customer base, which includes more than 10,000 organizations worldwide, not companies in general.

In a survey of about 500 decision-makers at US companies, published in December 2025, Menlo Ventures found that [prompt design is the dominant customization technique, followed by retrieval-augmented generation](https://menlovc.com/perspective/2025-the-state-of-generative-ai-in-the-enterprise/), while fine-tuning remains limited to a few teams. The report gives the ranking of techniques, without percentages.

A review of 63 studies on RAG in [knowledge management](/en/glossary/knowledge-management) and document automation, published in the journal Applied Sciences, shows where practice is still weak. [Only 15.9% of the studies measured business impact](https://www.mdpi.com/2076-3417/16/1/368), [38.1% addressed encryption or access control](https://www.mdpi.com/2076-3417/16/1/368) for retrieved data and [18% examined how to update the system](https://www.mdpi.com/2076-3417/16/1/368) when rules and products change. [Only 5% included tables, images or languages other than English](https://www.mdpi.com/2076-3417/16/1/368), which matters for anyone working with PDFs in Portuguese. The review describes published studies, not companies, but the weak points match the steps that demand the most care in a real project: access, updates, document formats and measurement.

We found no survey with Brazilian data on RAG use in companies.

## What are the ways to build a RAG system in a company?

There are three ways to build a RAG system in a company: use the file search feature of an AI platform you already pay for, build the system on a managed cloud service or develop it with your own libraries. Menlo Ventures estimates that [76% of AI use cases at the companies surveyed were bought ready-made in 2025](https://menlovc.com/perspective/2025-the-state-of-generative-ai-in-the-enterprise/), compared with 53% in 2024, which shows where the market is heading but does not replace analyzing your own case.

| Criterion | Ready-made platform feature | Managed cloud service | In-house development |
| --- | --- | --- | --- |
| Who configures it | Someone from the area with help from the platform administrator | Technical team familiar with the cloud | Development team |
| Control over chunking and search | Low | Medium | Full |
| Permissions | The platform's; they do not always read those of other systems | Configurable, require integration | Implemented by the team |
| Sources | Uploaded files or connectors offered | Cloud repositories and databases | Any source with technical access |
| Maintenance | The area that owns the documents | Technical team and the area | Technical team and the area |
| Suited when | Few documents, simple permissions, used by the team | Many documents, permissions from a central repository | Specific sources and rules, use inside other systems |

For a comparison with more criteria, the article on [buying or building an AI solution](/en/articles/buy-or-build-ai-solution) covers contracts, vendor dependence and cost. Whatever the path, the decision about where data is stored should go through the area responsible for security. IBM points out that if a [vector database](/en/glossary/vector-database) is breached, [the original data can be recovered, especially without encryption](https://www.ibm.com/br-pt/think/topics/retrieval-augmented-generation).

## How do you build a RAG system in your company, step by step?

To build a RAG system in your company, start with a recurring lookup by one team and put together a set of test questions before choosing any technology. At the end, you will have a system that answers that lookup with a cited source, a test spreadsheet and a person responsible for maintenance. You will need someone from the team that does the lookup, whoever owns the documents, whoever manages permissions and whoever will build or configure the system.

To follow the steps, we use a hypothetical example: the technical support team at an equipment distributor answers resellers by consulting about 400 product manuals and technical bulletins in PDF. Some bulletins are restricted to certified technicians.

1. **Define the lookup and the test questions.** With the support team, gather 40 real questions received in recent months. For each one, record the correct answer and the document and page that support it. Include questions with no answer in the documents and questions about restricted bulletins. Check: each question has a reference passage or the label "no answer in the base".
2. **Separate the sources and their owners.** List manuals and bulletins with version, date and owner. Remove old versions and duplicates, as the [Governo Digital guide](https://www.gov.br/governodigital/pt-br/infraestrutura-nacional-de-dados/inteligencia-artificial/publicacoes/guia-de-rag) recommends for revoked documents. Check: no product has two current manuals.
3. **Handle extraction.** Open a sample of 10 PDFs extracted as text and compare them with the originals, especially specification tables. Scanned PDFs need text recognition first. If a table comes out scrambled, fix the extraction before moving on, because the error repeats in every passage.
4. **Chunk and tag the passages.** Split documents by manual section, storing in each passage the product name, section title, version and access level. Check: a passage read on its own lets you tell which product and section it came from.
5. **Build the index and search.** Since support looks up model codes, use [hybrid search](/en/glossary/hybrid-search). In the Applied Sciences review, [80.5% of the studies used vector search, and 55% combined it with keyword search](https://www.mdpi.com/2076-3417/16/1/368) to handle domain terms.
6. **Apply permissions in search.** The access filter must act before a passage reaches the model. The Governo Digital guide recommends configuring the system to [retrieve only documents that the person is authorized to see](https://www.gov.br/governodigital/pt-br/infraestrutura-nacional-de-dados/inteligencia-artificial/publicacoes/guia-de-rag). Check with a user without certification: questions about restricted bulletins should come back without an answer.
7. **Write the answer instructions.** Ask the model to answer only from the passages, cite product, document and page and say "I could not find this information in the manuals" when no passage fits. Define where unanswered questions are routed.
8. **Test search and answers separately.** Run the 40 questions and record, in separate columns, whether the reference passage appeared among those retrieved and whether the answer is correct and cites the right source. A failure in the first column is fixed in extraction, chunking or search type; a failure only in the second, in the answer instructions.
9. **Release to a small group and define maintenance.** Start with three technicians for two weeks and record unanswered questions. Define who reindexes when a new bulletin comes out and who reruns the test after each change.

The completion test is simple: another person on the support team asks five new questions, opens the source cited in each answer and finds the information there. If an answer has no source or the source does not contain the information, go back to step 8 and find out whether the failure is in search or in the wording.

### How do you test whether a RAG system finds the right passage and answers well?

To test a RAG system, evaluate search and answers separately, because each fails for a different reason and needs a different fix.

- **Search.** For each question, check whether the reference passage is among the first retrieved. The share of questions in which it appears measures [recall](/en/glossary/recall-in-information-retrieval). The share of retrieved passages that are useful measures [precision](/en/glossary/precision-in-information-retrieval). If the right passage does not appear, adjust extraction, chunking or search type.
- **Answer.** With the right passage retrieved, check whether the answer uses only what it says, cites the source and handles unanswerable questions correctly. If the answer invents things or mixes products, adjust the instructions or the number of passages sent.
- **Access.** Repeat the restricted questions with profiles that lack permission.
- **Results at work.** Decide beforehand what you will measure in the team, such as time to answer a reseller or the number of lookups escalated to specialists. In the Applied Sciences review, [only 15.9% of the studies measured business impact](https://www.mdpi.com/2076-3417/16/1/368).

IBM sums up the limit the test has to assume: RAG [can reduce the risk of hallucinations but cannot make a model error-proof](https://www.ibm.com/br-pt/think/topics/retrieval-augmented-generation). So the decision to release depends on a criterion agreed with the team, such as getting the source right on every restricted-bulletin question and answering "I could not find this" on every question with no basis. The article on [acceptance criteria for AI projects](/en/articles/ai-project-acceptance-criteria-company) helps you write that criterion.

## How does The Company Brain help build a RAG system?

The Company Brain helps build a RAG system by starting from the routine, not the technology. We talk to the people who do the lookup and map which documents the team opens, who owns them and who may see each one. In the [organizational AI assessment](/en/services/organizational-ai-assessment), that conversation shows which lookups justify a RAG system and which can be solved with an assistant you already pay for. In [AI solutions](/en/services/ai-solutions), we build the system with the team, including the test questions and the maintenance routine.

When several teams and tools need to query the same base with the same access rules, the RAG system becomes one part of the [Company Brain](/en/company-brain), the infrastructure that organizes the organization's knowledge for people and AI agents. The article on [AI knowledge management](/en/articles/ai-knowledge-management-company) covers the work on sources that supports that base.

If someone in your company asked for a RAG with the team's documents and you need to decide whether that is the right path, bring the lookup that keeps repeating, the documents involved and who may see each one. We can talk about which way to build it and how to test it before release. [Schedule a conversation](https://thecompanybrain.com.br/en/contact)

## Sources

- [State of AI: Enterprise Adoption & Growth Trends](https://www.databricks.com/blog/state-ai-enterprise-adoption-growth-trends): Aggregated, anonymized data from more than 10,000 platform customers worldwide, February 2023 to March 2024. Supports the 70% of companies supplementing models with retrieval and vector databases and the 377% growth of vector databases. Does not represent companies outside the customer base.
- [2025: The State of Generative AI in the Enterprise](https://menlovc.com/perspective/2025-the-state-of-generative-ai-in-the-enterprise/): Survey of about 500 US enterprise decision-makers combined with a market model. Supports the ranking of customization techniques (prompting, then RAG; fine-tuning as niche) and the share of use cases bought (76% in 2025, 53% in 2024).
- [Retrieval-Augmented Generation (RAG) and Large Language Models (LLMs) for Enterprise Knowledge Management and Document Automation: A Systematic Literature Review](https://www.mdpi.com/2076-3417/16/1/368): Review of 63 academic studies. Supports 15.9% measuring business impact, 38.1% addressing encryption or access control, 18% addressing updates, 5% covering other languages and formats, and 80.5% using vector search with 55% combining keyword search. Describes published studies, not companies.
- [What is retrieval-augmented generation (RAG)? (Portuguese edition)](https://www.ibm.com/br-pt/think/topics/retrieval-augmented-generation): Vendor page, updated on 2 October 2026. Used for the system components, the effect of chunk size, the exposure risk in vector databases and the limit that RAG reduces but does not eliminate errors.
- [Guia de Introdução ao RAG para Servidores Públicos (Introductory RAG guide for public servants)](https://www.gov.br/governodigital/pt-br/infraestrutura-nacional-de-dados/inteligencia-artificial/publicacoes/guia-de-rag): Informational guide for the public sector, in Portuguese. Used for the distinction between context augmentation and RAG, the removal of revoked documents and retrieval limited to documents each person may see.

## Related reading

- [Custom AI solutions | The Company Brain](/en/services/ai-solutions)
- [Company Brain: your company's knowledge, connected](/en/company-brain)
- [Organizational AI assessment | The Company Brain](/en/services/organizational-ai-assessment)
- [How to create an AI virtual assistant for your company?](/en/articles/create-ai-virtual-assistant-for-your-company)
- [How do you structure an AI knowledge management project in a company?](/en/articles/ai-knowledge-management-company)
- [Retrieval-augmented generation](/en/glossary/retrieval-augmented-generation)
