# Retrieval-augmented generation (RAG)

> A pattern where relevant passages are retrieved from a knowledge source and put into the prompt so the model answers from them.

Source: Promptea — https://www.promptea.me/en/glossary/retrieval-augmented-generation · Language: English · Last updated: 2026-11-09

## What it means

- Definition: instead of relying on what the model memorized in training, a system first searches your documents (or the web), selects the most relevant passages and inserts them into the prompt as context.
- Why it matters: the answer can use current or private information the model never saw, and you can show which passage supports each claim, which makes errors easier to catch.
- How to apply it: label the retrieved passages, tell the model to answer only from them, to say when they do not contain the answer, and to cite which passage it used. Keep the passages short and relevant — more text is not better.
- Common mistake: assuming retrieval removes the problem. If the search returns the wrong passages, the model answers confidently from the wrong material, so test retrieval separately from generation.

## Example

```text
Answer the question using only the numbered passages below.
Cite the passage number after each claim, like [2].
If the passages do not contain the answer, say so and stop.

<passages>
[1] [paste passage]
[2] [paste passage]
</passages>

Question: [question]
```

[Open in Promptea](https://www.promptea.me/en/analyzer?prompt=Answer+the+question+using+only+the+numbered+passages+below.%0ACite+the+passage+number+after+each+claim%2C+like+%5B2%5D.%0AIf+the+passages+do+not+contain+the+answer%2C+say+so+and+stop.%0A%0A%3Cpassages%3E%0A%5B1%5D+%5Bpaste+passage%5D%0A%5B2%5D+%5Bpaste+passage%5D%0A%3C%2Fpassages%3E%0A%0AQuestion%3A+%5Bquestion%5D&purpose=text&target=claude)

## Frequently asked questions

### Is RAG the same as fine-tuning?

No. Fine-tuning changes the model's weights; RAG leaves the model alone and changes what it reads in the prompt. RAG is the usual way to give a model fresh or private facts.

### Do search-based assistants use RAG?

They follow the same idea: search first, then answer from what was found and show sources. Models such as Perplexity's do this natively, so your prompt should seed a good search rather than paste the sources.

## Related

- [Prompts for Perplexity: grounded answers from the web](https://www.promptea.me/en/guides/perplexity-prompt-guide)
- [Context engineering: how to structure what you give an AI for better outputs](https://www.promptea.me/en/guides/context-engineering)
- [How to debug a prompt that gives bad output](https://www.promptea.me/en/guides/prompt-debugging)
- [Hallucinations](https://www.promptea.me/en/glossary/hallucinations)
- [Context window](https://www.promptea.me/en/glossary/context-window)
