Skip to content
Book a conversation

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.

Luiz GardelinUpdated 14 min readRead in Markdown
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.
On this pageIntroduction

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: 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.

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. 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: the 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.

PartWhat it doesDecision you makeMost common failure
ExtractionPulls text from PDFs, spreadsheets and pagesWhich formats go in and how to handle scanned PDFs and tablesA table becomes scrambled text and the value is lost
ChunkingSplits each document into passagesPassage size and whether it carries title and sectionA passage too large becomes generic; too small loses meaning
IndexStores passages in a searchable form, usually as a vector representationWhere the index lives and how often it is rebuiltA revoked document stays in the index
SearchFinds the passages closest to the questionSemantic search, keyword search or bothA product code or regulation number is not found
Access filterRemoves passages the person may not seeWhich system the access permissions come fromThe model summarizes a restricted document for someone who should not see it
Input assemblyCombines instructions, question and passagesHow many passages go in and what to do when none fitsThe right passage is left out for lack of room in the context window
GenerationThe model writes the answer and cites the sourceAnswer format and the sentence to use when there is no basisThe answer states something that is not in the passage

Vector search compares meanings: the question and the passages become lists of numbers, called embeddings, and the system looks for the passages with the closest numbers. Keyword search, called lexical search, looks for exact terms. Combining both, 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. 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, 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, without automated search, this is context augmentation, not RAG.

CriterionAttaching documents to a chatRAG systemFine-tuning
Who chooses the materialThe person askingThe search mechanismWhoever prepares the training examples
When knowledge comes inIn the chatOn every questionBefore use, in training
Documents that changeThe person must attach the new versionUpdating the index is enoughRequires new training
Different permissions per personDepend on who attachesApplied in searchDo not apply to what the model learned
Cites the sourceOnly if the person asksCan cite passage and documentNo
Suited toOne-off task with few filesRecurring lookup across many documentsConsistent 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 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, and that few projects measure results. Among Databricks customers using generative AI, 70% used tools, retrieval systems and vector databases 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. 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, 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 and document automation, published in the journal Applied Sciences, shows where practice is still weak. Only 15.9% of the studies measured business impact, 38.1% addressed encryption or access control for retrieved data and 18% examined how to update the system when rules and products change. Only 5% included tables, images or languages other than English, 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, compared with 53% in 2024, which shows where the market is heading but does not replace analyzing your own case.

CriterionReady-made platform featureManaged cloud serviceIn-house development
Who configures itSomeone from the area with help from the platform administratorTechnical team familiar with the cloudDevelopment team
Control over chunking and searchLowMediumFull
PermissionsThe platform's; they do not always read those of other systemsConfigurable, require integrationImplemented by the team
SourcesUploaded files or connectors offeredCloud repositories and databasesAny source with technical access
MaintenanceThe area that owns the documentsTechnical team and the areaTechnical team and the area
Suited whenFew documents, simple permissions, used by the teamMany documents, permissions from a central repositorySpecific sources and rules, use inside other systems

For a comparison with more criteria, the article on buying or building an 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 is breached, the original data can be recovered, especially without encryption.

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 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. In the Applied Sciences review, 80.5% of the studies used vector search, and 55% combined it with keyword search 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. 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. The share of retrieved passages that are useful measures precision. 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.

IBM sums up the limit the test has to assume: RAG can reduce the risk of hallucinations but cannot make a model error-proof. 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 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, that conversation shows which lookups justify a RAG system and which can be solved with an assistant you already pay for. In 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, the infrastructure that organizes the organization's knowledge for people and AI agents. The article on AI knowledge management 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

Common questions

What is a RAG system?

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 cites the source. RAG stands for retrieval-augmented generation. The system has a preparation phase, in which documents are extracted, split into passages and indexed, and a query phase, in which passages are searched, filtered by permission and sent to the model.

How many companies use RAG to supplement AI models?

Among Databricks customers using generative AI, 70% used tools, retrieval systems and vector databases to supplement their models, in data from February 2023 to March 2024. In the same base, use of vector databases grew 377% in one year. These figures describe that platform's customer base, and there is no survey with Brazilian data on RAG use.

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 attaching documents, the person picks the files for that chat. In RAG, a search mechanism picks passages for each question from a base maintained by the organization. In fine-tuning, the model is trained again with examples and does not consult documents when answering.

What are the main risks of a RAG system in a company?

The main risks of a RAG system in a company are showing someone passages from documents they are not allowed to see, answering from revoked versions still in the index, losing information from badly extracted tables and stating something that is not in the retrieved passage. The access filter must act before passages reach the model, and the index must be rebuilt when documents change.

How do you build a RAG system in a company?

To build a RAG system in a company, start with a recurring lookup by one team and gather real questions with the correct answer and the reference passage. Then separate the current sources and their owners, check how PDFs are extracted, split documents into passages tagged with product, section and access level, set up search, apply permissions and write the answer instructions. Test search and answers separately and release to a small group with someone responsible for maintenance.

When is it worth building a RAG system instead of using a ready-made platform?

It is worth building a RAG system on a managed service or through in-house development when there are many documents, permissions that come from other systems, sources that change often or use inside other tools. With a few stable documents everyone can see, the file search feature of a platform you already pay for is usually enough. According to Menlo Ventures, 76% of AI use cases at the companies it surveyed were bought ready-made in 2025.

Sources

  1. State of AI: Enterprise Adoption & Growth Trends Databricks

    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.

  2. 2025: The State of Generative AI in the Enterprise Menlo Ventures

    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).

  3. Retrieval-Augmented Generation (RAG) and Large Language Models (LLMs) for Enterprise Knowledge Management and Document Automation: A Systematic Literature Review Applied Sciences (MDPI), Karakurt and Akbulut

    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.

  4. What is retrieval-augmented generation (RAG)? (Portuguese edition) IBM Think

    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.

  5. Guia de Introdução ao RAG para Servidores Públicos (Introductory RAG guide for public servants) Governo Digital, Brazilian Federal Government

    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.

Written by

Luiz Gardelin

Founder and lead consultant at The Company Brain

Luiz Gardelin is the founder and lead consultant at The Company Brain, an AI organizational transformation consultancy based in Brazil. He also founded Webinhood and Tropk.ai.

See all content by this author

A conversation about your organization.

Before recommending any tool, we talk with your teams and map how the work really happens.

Arrange a conversation

Related terms

Continue reading

All resources