AI Applied

RAG in AI: how to give your models real business context

Definition, mechanics, agentic RAG and the three traps that sink a project in production.

Louis Graffeuil
Louis Graffeuil
Founder Tandem
January 16, 2026Published
11 minread
3D illustration of a filing drawer releasing cards that converge into a cube

RAG, short for retrieval augmented generation, means making an artificial intelligence model look information up before it answers. The model no longer draws on its training memory. It draws on your documents. France's data protection authority, the CNIL, sums it up in one line. It is an information retrieval mechanism added on top of a vectorised database (generative AI Q&A, 18 July 2024).

The acronym comes from a research paper by Patrick Lewis and his co-authors (Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks). It was posted on 22 May 2020 and presented at NeurIPS the same year. Six years on, RAG has become the standard way to connect an AI to a company's own data.

The starting point is always the same. You ask a business question. The AI answers fast, phrased well, and off target. The problem is almost never the model. It is the missing context.

A model with no internal data does not know your processes. It has never seen your documents. It ignores your business rules and improvises as soon as the question gets specific. You get generic answers, sometimes right, often unusable. And sometimes answers that are wrong but convincing, which costs more than silence.

Tandem deploys this kind of system for mid-market companies. This guide covers what holds up in the field. The four ways to give an AI context, how RAG actually works, agentic RAG, and the three traps that sink a project in production. To frame the need before picking the technique, our AI audit method starts from use cases, not tools.

What exactly is RAG in AI

A RAG system always follows the same three-step logic. Much like a person who opens the right procedure before answering a customer.

  1. The question is asked by a user or by another system.
  2. The system retrieves the most relevant passages from your documents.
  3. The model writes its answer from those extracts alone, and can cite its source.
Diagram of a RAG pipeline, from question to embedding model, vector database and final answer
The middle block is what matters. Without a vector database there is no RAG, just a longer prompt. Source: Elastic.

The key point fits in one sentence. The model does not answer from memory, it answers from your data. Inside a company, that changes everything as soon as business knowledge and precise rules are involved.

Four ways to give an AI context

Before building a RAG, look at the three simpler approaches. They cover a large share of real needs for a fraction of the work. RAG only comes fourth, and that ordering is deliberate.

The four ways to give an AI context: filters, SQL query, whole document and semantic search
The decision rule sits at the bottom of each card. It beats a long comparison table.

Plain filters

This is the most underrated approach, and often the best place to start. The agent does not reason over an entire database. It applies precise filters, date, status, category, client. For the question « how many orders were confirmed yesterday for client X », it filters the relevant rows, computes and answers.

It is fast, cheap and unambiguous. The rule is simple. If a person would use filters in a spreadsheet, use filters.

n8n AI agent querying sales data through product and date filter tools
Five tools, zero vectors. A lot of requests never need to go further.

SQL queries written by the AI

As soon as you need to aggregate, rank, average or compare periods, filters hit their limit. The agent then writes the SQL query that matches the database structure. For « what are our three most profitable products this quarter », it writes the query, hits the database, gets a structured result and explains it.

This is far more reliable than chaining filters and computing by hand. The rule still holds. If a person would build a pivot table, go through SQL.

n8n AI agent connected to a PostgreSQL database, writing its own SQL queries
The executeQuery tool lets the agent write the SQL. Guardrails belong to database permissions, not to the prompt.

Passing the whole document

Another classic approach hands the entire document to the model. Contracts, procedures, transcripts, reports. No technical complexity, full context, and very good results for a global analysis or a summary.

The limit is the context window. As of 19 August 2026, GPT-5.2 lists 400,000 tokens on its model card. Claude Opus 5 and Claude Sonnet 5 reach 1 million tokens on the API (Anthropic documentation). Other Claude models stay at 200,000 tokens.

GPT-5.2 model card showing a 400,000 token context window
400,000 tokens is roughly 300,000 words. An annual report fits, a document base does not.

A wide window does not settle the matter though. Anthropic's own documentation states it plainly, accuracy and recall degrade as the token count grows, a phenomenon it calls context rot. Filling the window is not a strategy. Curating what goes into it is one. Add the cost of processing a mass of useless text on every question, and the approach shows its limits quickly.

n8n AI agent given two whole documents as read tools
Two documents hard-wired as tools. Fine for a one-off, unmanageable by the tenth procedure.

This approach stays the right one when the volume is known and the need is occasional. In every other case you need to be selective, and that is exactly where RAG earns its place.

Semantic search

Instead of filtering or sending everything, the system splits the documents, turns the text into vectors, then searches by proximity of meaning. Ask « how do we handle a customer dispute caused by a late delivery ». Even if no document contains that sentence, the system finds the right passages.

It is powerful because it works without exact word matching. It scales to thousands of documents. It is the right pick for documentation, procedures, customer reviews or meeting notes.

How a RAG works, from document to vector

Splitting into chunks

To search your documents, you have to prepare them first. That is the subtlety many teams discover too late. Documents are not stored whole. They are split into small pieces called chunks, turned into vectors by an embedding model, then stored in a vector database.

Splitting a document into chunks, then turning each chunk into an embedding vector
Searching three relevant paragraphs costs far less than re-reading 200 pages on every question.

That version of RAG works, but it stays linear and passive. The system retrieves roughly relevant passages, sometimes misses the key one, and the model answers anyway. You get well-written answers that are occasionally wrong. In production, that is a real problem.

Going further means giving the system more control, more logic and genuine decision-making. That is what agentic RAG brings.

Agentic RAG, when the AI picks its own sources

Agentic RAG is no longer a simple pipeline. It is an autonomous agent driving every step. It does not just search then answer. It chooses which tool to use, checks whether the retrieved context is enough, runs another search when something is missing, and loops until it meets its goal.

I laid out this mechanism in a LinkedIn post on moving from RAG to agentic RAG in December 2025. The diagram below puts both pipelines side by side.

Side-by-side comparison of the classic RAG and agentic RAG pipelines, from query to final answer
One block makes the difference. On the left the path is fixed, on the right the agent picks between web search, database and APIs.
  • Rephrase the query when the original question is too vague for a useful search.
  • Select the sources, vectors, SQL, web, APIs or conversation memory.
  • Iterate until it has enough context, within a fixed number of loops.
  • Rerank the results to keep only the passages that genuinely matter.
  • Generate a sourced answer, or run the loop again if it does not hold up.
Agentic RAG architecture where the agent arbitrates between two search databases and a web search
A single question can need an internal rule, a figure in a database and a client history. Classic RAG would make one call.

Reranking

The principle is simple. Instead of retrieving three or four passages, the system retrieves ten, twenty, sometimes more. A second model then reorders the results by actual relevance, and only the best ones reach the model that writes the answer.

Search results reordered by a reranker, each document carrying a relevance score
Scores from 0.93 down to 0.87 are what separates a good RAG from a chatty one. Source: Cohere.
n8n scenario with a Cohere reranker plugged in after the search in a Supabase vector store
The reranker is one node, added after retrieval. Best effort-to-quality ratio in the whole chain.

My advice comes down to two points. Put your effort into data pre-processing and into the reranking step. For the large majority of use cases that is enough, and it is what I was already writing on LinkedIn. Refining the agent comes afterwards, not before.

Metadata

When a document is split, context is lost. The source, the date, the category, the client, all of it disappears with the chunking. Metadata is what keeps it. It is added at vectorisation time, and the agent can then filter on it before running any semantic search.

Add at minimum the document date, its category and its identifier. That lets you search only the version of a procedure currently in force, or group the pieces of a single document.

Adding a doc_date metadata field when vectorising a document in n8n
A date metadata field costs one line at ingestion. It stops a repealed procedure from resurfacing two years later.

The three traps of a RAG in production

A hand-built RAG works in two hours for a demo. It holds up far less well in production, and I said so bluntly on LinkedIn in January 2026. For learning, building it yourself is the right move. For production, three points are consistently underestimated.

The three traps of a RAG in production: document parsing, synchronisation and permissions
None of these three shows up in a prototype. All three get paid for in production.
  1. Document parsing. A badly split PDF returns incoherent answers. Basic extractors break the structure and flatten headings, tables and charts. On a financial or technical document, that is a deal breaker. Specialised components such as Docling handle this job properly.
  2. Synchronisation. A knowledge base is never frozen. Documents get deleted, moved, edited, and internal processes evolve. If the vector store is not aligned, the AI answers with stale content in full confidence. Duplicates are the most common trap. When a document changes, its old vectors must be deleted before new ones are created.
  3. Permissions and compliance. Without access control at vector level, any user can query any document. Data location, the processing agreement and data minimisation are not optional.

Automation is not about building everything yourself. It is about placing the cursor between control, risk and business value. Depending on the case, Tandem ships an off-the-shelf solution to move fast. Or delegates ingestion to a specialised component and keeps n8n on the business logic. Or goes self-hosted when sovereignty and long-term cost come first.

RAG or fine-tuning, which one to pick

The question comes up in every scoping session. The short answer fits in one sentence. Fine-tuning changes the model, RAG changes the context you hand it. They are not two competing options for the same problem.

CriterionRAGFine-tuning
What changesThe context sent on each callThe model itself
Data freshnessImmediate, the base updatesFrozen at training date
TraceabilityThe answer cites its sourcesNo source to show
Good forKnowledge, procedures, documentsTone, output format, jargon
Cost of a changeReindex the affected documentsRun another training
RAG and fine-tuning do not answer the same question

Start with RAG for almost every business use case. It exposes your data to a model without retraining it, keeps freshness and makes sources traceable. Fine-tuning becomes relevant when you need to durably change a model's tone, format or business vocabulary. The two combine well, but in that order.

A RAG agent at a hotel group

To move past theory, here is a real case. A hotel group runs several properties in France and receives thousands of customer reviews spread across Google, Booking and TripAdvisor. The teams face three problems. Too many reviews to read, recurring pain points that are poorly identified, and review responses handled ad hoc with no method.

The goal is an agent that analyses those reviews for management, spots friction points property by property and helps teams reply. Reviews are collected and stored in a SQL database. The internal response guidelines live in a vector database.

The full build, from the Google Drive trigger to the reranker. The review response guide runs about a dozen pages, already too much for a prompt.

Vectorising reviews and procedures

A first workflow categorises each review automatically, then vectorises it and stores it in Supabase with its metadata, the property, the rating and the category. A second workflow watches a Google Drive folder. As soon as a document is added or edited, it triggers an update of the vector store.

n8n workflow categorising then vectorising customer reviews before storing them in Supabase
Categorise first, vectorise second. A categorised review can be filtered before semantic search, which cuts the noise.

That second workflow carries the detail I see forgotten most often. When an existing document is edited, its old vectors are deleted before the new ones are created. Without that step, the previous version of the procedure stays in the base and keeps showing up in answers.

The agent that queries the base

The agent searches relevant reviews semantically, groups weak signals and produces actionable summaries. It retrieves several passages with their metadata, then a Cohere reranker keeps only the top three. The model is called through OpenRouter, which leaves the provider choice open without touching the scenario.

n8n AI agent with a GET-REVIEWS tool to query the customer review base
One tool exposed to the agent, a short conversation memory. Complexity lives in ingestion, not in the agent.

Teams then ask questions in plain language. Summarise the negative reviews for the Annecy hotel. What are this month's main pain points in Toulouse. How should we reply to a four-star review mentioning breakfast. This kind of agent replicates across many other functions, starting with customer support and documentation roles.

The same mechanism feeds other building blocks. An AI voice agent that has to answer a procedural question relies on exactly this foundation. And if you want to reproduce the build yourself, our tutorial on creating an AI agent with n8n walks through the nodes one by one.

Should you put a RAG in place in your company

Yes, as soon as your answers depend on internal documents that keep moving. No, if a filter or a SQL query answers the question. That is the only rule that matters, and it can be tested in half a day.

RAG is not a hard technology. What is hard is keeping it alive in production. Parsing, synchronisation and permissions cost far more than the pipeline itself. A project that neglects those three ships an AI that answers wrong with confidence, which is worse than no AI at all.

This is also why keeping the system healthy matters as much as building it. Our AI autopilots cover that side, from tracking answer quality to keeping the knowledge base current.

Our recommendation has not changed in two years. Start small, on a bounded corpus and a precise use case. Get pre-processing and reranking right before refining the agent. Measure answer quality before opening the tool to the whole company. And plan the human side, because a good RAG nobody adopts is worth nothing, which our article on AI literacy covers in detail.

Bpifrance lists RAG among the strategic methods for French small and mid-sized companies in its December 2025 dossier. We share that view, with one nuance. The value does not come from the technique, it comes from the corpus you are willing to clean up.

Frequently asked questions

What is RAG in AI, in one sentence?

A RAG, or retrieval augmented generation, is a system that fetches the relevant passages from your documents before an AI model writes its answer. The model no longer answers from training memory but from your data, and it can cite its source. The CNIL describes it as an information retrieval mechanism on a vectorised database.

What is the difference between RAG and agentic RAG?

Classic RAG follows a fixed path, it searches once then answers. Agentic RAG hands that path to an autonomous agent. The agent rephrases the question, picks between sources such as a vector store, SQL or a web search, checks whether the context is sufficient and searches again if not. The gain shows on questions that span several sources.

Should you choose RAG or fine-tuning?

RAG for almost every business case. It gives the model your data without retraining it, stays current as soon as the base changes and keeps sources traceable. Fine-tuning is for durably changing a model's tone, output format or business vocabulary. The two combine, but RAG comes first.

Does a large context window replace RAG?

No. Claude Opus 5 and Claude Sonnet 5 accept 1 million tokens on the API and GPT-5.2 lists 400,000, which covers a large report but not a document base. Anthropic's documentation also notes that accuracy and recall degrade as the window fills up. Curating what enters the context stays more effective than sending everything.

Who is responsible for personal data inside a RAG?

The company deploying the system. In its July 2024 Q&A, the CNIL states that a deployer connecting an AI to its own knowledge base becomes a controller for that processing as soon as it holds personal data. Vectorising HR files or a client history therefore commits the company, and requires access control at vector level.

Read next

All articles
AI AppliedTwo blocks, one pale and one dark, joined by a coral bridge, with a laptop resting on top

Forward Deployed Engineer: the job of deploying AI

By Louis Graffeuil
AI AppliedIllustration of Claude Code training, a laptop wearing a graduation cap

Claude Code training: the path for people who do not code

By Louis Graffeuil
AI AppliedIllustration of Claude Skills, a cabinet with three drawers pulled out to different depths, one coral drawer holding a folder

Claude Skills and Projects, why the prompt is no longer the right unit of work

By Louis Graffeuil