Vezi pagina în română

IT Glossary

What is RAG (retrieval-augmented generation) and how it works

RAG means an AI model first searches your documents for the right passages and only then writes the answer, with a pointer to the source.

7
sections
5
questions answered

RAG (retrieval-augmented generation) is the technique by which an AI system first searches the company's documents — proposals, contracts, manuals, procedures — for the relevant passages and places them in front of a large language model (LLM), which writes the answer from them and can show the source. An LLM knows only what it saw in training, and your contracts, prices and procedures were not in it. RAG puts them in front of the model at every question, without retraining it.

The term comes from a 2020 paper by Patrick Lewis and colleagues at Facebook AI Research, University College London and New York University ("Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks", arXiv 2005.11401, accepted at NeurIPS 2020). The difference is that between a new employee answering customers from a vague memory and one who opens the correct file before speaking. When a document changes, it is reindexed — automatically on every save, if the system is built that way — and the next answer uses the new version instead of one that is a year old.

Why it matters for your business

Answers from your data, not from the internet

The AI cites real company proposals, procedures and contracts, so customers and staff receive official information rather than generic approximations.

Updates without retraining

The model is never retrained: the changed document is reindexed, automatically on save if the system is built that way, and the next answer uses it.

Fewer hallucinations, with the source cited

Because the answer rests on concrete passages retrieved from documents, you can display the source and verify the assistant's claims, although errors do not disappear completely.

How RAG works, step by step

First the documents are cut into chunks of a few paragraphs. An embedding model turns each chunk into a vector, a list of numbers that captures the meaning of the text, and the vectors are stored in a vector database.

At every question the system fetches the chunks closest in meaning, usually a handful up to a few dozen. For exact codes, such as a product code or an invoice number, a keyword search (BM25) is added, because vectors often miss them.

The chunks go into the prompt together with the instruction "answer only from these sources, otherwise say you do not know", and the model writes the answer pointing to the passage it used. Example: an employee asks "What return period do we have in B2B contracts?" and gets the clause plus the name of the document it came from.

RAG versus a classic chatbot

A rule-based chatbot gives answers written in advance, driven by menus and keywords. An LLM used alone answers from what it learned in training and knows nothing about your company. A chatbot with RAG searches the company's documents at every question and cites where the answer came from.

Fine-tuning is something else: it changes how the model answers, not what it knows about the company. The full comparison is on the fine-tuning page.

Want an estimate for your project?

Message us on WhatsApp. We reply the same working day, and the first 30-minute call is free.

Book a free call

When you do not need RAG

If the material is under about 200,000 tokens, roughly 500 pages, Anthropic recommends putting all of it in the prompt, with no RAG (anthropic.com, 19.09.2024).

Data that changes often, such as a price, stock level or a customer's balance, is read at question time from the ERP or inventory system through an API, not from an index. Scanned PDFs need OCR first, otherwise there is no text to search.

Where RAG goes wrong and how to measure it

A chunk can lose its context, embeddings miss exact codes, an index that was not refreshed gives an outdated but convincingly cited answer, and two sources can contradict each other. RAG reduces hallucinations, it does not eliminate them.

Anthropic measured that Contextual Retrieval cut retrieval failures (top-20 chunks) by 49 %, from 5.7 % to 2.9 %, and by 67 % (1.9 %) when reranking was added, on their own test sets (19.09.2024). Before launch, run a set of real questions with a known correct answer and repeat it after every change.

What a RAG system costs a company

Indicatively, excluding VAT: an AI chatbot on company data costs 3,000–15,000 €, and a dedicated AI feature, for example semantic search or an assistant on internal data, 10,000–50,000 €. Recurring, the model API is 20–500 € per month at SME volumes.

The price moves with the number and condition of the documents, per-user access rights and integrations with other systems. The full guide is on the page about what an AI chatbot costs.

Frequently asked questions

How does RAG differ from an ordinary chatbot?

An ordinary chatbot answers from rules written in advance or from what the model learned in training. One with RAG searches the company's documents at every question and builds the answer from the passages it finds, with the source shown. In practice it is an assistant that reads the file before speaking.

What does RAG stand for?

RAG stands for retrieval-augmented generation: retrieval is the search for passages, augmentation is adding them to the prompt, and generation is writing the answer. In Romanian the term is "generare augmentată prin regăsire"; the Romanian word "rag" is a form of the verb "a rage" (to bellow) and has nothing to do with AI.

Do I need RAG if I only have a few documents?

Often not. Under about 200,000 tokens, roughly 500 pages, Anthropic recommends putting all the material directly in the prompt (19.09.2024). RAG becomes necessary when the documents no longer fit, change often or carry different access rights for different users.

Which documents can be connected to a RAG system?

PDFs, Word files, contracts, manuals, website pages, support tickets and internal policies. Scanned PDFs go through OCR first. Prices, stock levels and balances are not copied into the index: they are read straight from the source system, through an API, at the moment of the question.

Does company data stay confidential in a RAG system?

Yes, if built correctly: the documents stay with you, only the passages for one answer are sent to the model, and access rights apply per user. OpenAI has not used API data for training since 1 March 2023, though it keeps abuse-monitoring logs for up to 30 days, and Anthropic does not train on commercial product data by default.