Retrieval-augmented generation (RAG)
Also: RAG (retrieval-augmented generation), RAG, retrieval augmented generation, generování rozšířené o vyhledávání
Retrieval-augmented generation (RAG) is a technique in which a language model first retrieves relevant passages from an external source, such as company documents, and places them in its context before answering. The answer is then grounded in the retrieved text rather than only in knowledge learned during training. The method was described under this name in 2020 by a team led by Patrick Lewis.
What it means for a company
RAG is the most common way to let AI answer questions over internal data: policies, contracts, product documentation or support tickets. The model is not retrained, so updating the documents is enough for answers to reflect the current state. Answers can cite their source, which makes them easier to check and lowers the risk of hallucinations. Quality depends on the data: outdated, duplicated or badly split documents produce poor answers. Access control is equally important, so the assistant never shows an employee a document they are not allowed to open.
In practice
RAG vs fine-tuning: RAG supplies knowledge to the model at query time, while fine-tuning changes the model's behaviour through further training. If a service assistant needs to know the current price list and manuals, RAG is the right choice, because a new price list simply goes into the source. If the model must always answer in a fixed format and house style, fine-tuning fits better. They can be combined. OpenAI recommends starting with prompt engineering and choosing the next step based on whether the model lacks knowledge or consistency.
Frequently asked questions
Does RAG need a vector database?
Usually, but not necessarily. A typical implementation turns documents into embeddings and stores them in a vector database to search by meaning. Retrieval can also use classic full-text search or a hybrid of both, which helps with exact terms such as contract numbers or product codes.
Does RAG eliminate hallucinations?
Not completely. RAG reduces the risk of the model inventing facts, because it answers from retrieved text and can cite it. If retrieval returns the wrong passage or the document is missing from the source, the model can still answer incorrectly. Showing sources and testing answers regularly is worth the effort.
Does company data go to the model provider with RAG?
The retrieved passages are sent to the model as part of the request, so whoever runs the model processes them. The service's contractual terms, data location and retention settings therefore matter. Sensitive sources can be connected to a model hosted in the EU or in your own infrastructure.