Retrieval-augmented generation (RAG)

A method that has an AI model look up relevant documents first and then write its answer from them, instead of relying only on what it learned in training.

Retrieval-augmented generation, usually shortened to RAG, gives a large language model an open-book exam. When a question arrives, a search step finds the most relevant passages in a chosen collection, such as a policy manual, a product catalogue or past support tickets. Those passages are placed in the prompt next to the question, and the model writes its answer from them.

The search step is usually built on embeddings. Each document is split into chunks, each chunk is turned into a list of numbers that captures its meaning, and those lists are stored, often in a vector database. The question is converted the same way, and the system pulls the chunks whose numbers sit closest to it. That is how a question about holiday entitlement finds the section headed annual leave. Meaning-based search can also be combined with ordinary keyword search.

The term comes from a 2020 paper by Patrick Lewis and colleagues, Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks, which paired a language model with an external memory searched at the moment of answering. It addressed two problems businesses run into straight away: knowledge stored inside a model is hard to update, and its answers are hard to trace back to a source.

RAG is now the usual way to point an AI assistant at a company's own information, and it is easier to keep current than fine-tuning: update the documents and the answers change, with no retraining. It reduces hallucination without ending it. If retrieval pulls the wrong passage, or the right passage is out of date, the model will answer fluently from bad material. The quality of a RAG system depends heavily on the documents behind it and how well they are organised. Good systems show which passages they used, so a reader can check.

Common questions

What is RAG in AI?

RAG stands for retrieval-augmented generation. Before an AI model answers, a search step finds relevant passages from a set of documents, such as company policies or product manuals, and adds them to the prompt. The model then writes its answer from that material, which lets it use private or recent information it never saw in training.

What is the difference between RAG and fine-tuning?

Fine-tuning changes the model itself by training it further on new examples, which suits teaching a style or a specialised task. RAG leaves the model unchanged and hands it relevant documents at the moment of each question, which suits facts that change or must be traced to a source. Updating a RAG system means updating documents, not retraining.

Does RAG stop AI hallucinations?

It reduces them but does not stop them. The model can still misread or embellish the passages it is given, and if the search step returns the wrong or outdated document, the answer will be wrong with full confidence. Showing the retrieved sources next to each answer lets people check the claims quickly.

Do I need a vector database for RAG?

No. The retrieval step can use any search system, including ordinary keyword search or an existing enterprise search tool. Vector databases are the most common choice because they find passages by meaning rather than exact wording, but for a small or well-structured document set simpler search can work well.

Finding more

Search for "retrieval-augmented generation explained", "RAG vs fine-tuning" and "RAG evaluation". Reliable sources include the original 2020 paper by Lewis and colleagues on arXiv, the technical documentation of cloud platforms and open-source projects that describe their retrieval features, and university course notes on information retrieval. Treat with care accuracy figures published by companies selling a RAG product, and any promise that RAG removes hallucinations entirely.

Working out what this means for your business?

Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.