# RAG (retrieval-augmented generation)

> For the complete documentation index, see [llms.txt](https://attensira.com/llms.txt).
> Every page on this site is also served as Markdown: append `.md` to any URL, or send `Accept: text/markdown`.

> RAG, retrieval-augmented generation, has a model fetch documents and write from them. How the pipeline works and what it means for which pages AI answers cite.

- Canonical page: https://attensira.com/glossary/rag
- Family: glossary
- Last updated: 2026-10-04
- Author: Karl-Gustav Kallasmaa (https://attensira.com/about)
- Claims as data: https://attensira.com/claims.json?slug=rag

**In short:** RAG, retrieval-augmented generation, is how most AI answers that cite pages are built: the system retrieves relevant documents, puts the best passages in the model's context, and has the model write from them. ChatGPT search, Perplexity and AI Overviews work this way, so a page can be quoted the day it is retrieved.

**Perplexity, asked 2026-10-03:** "how does AI pick which sources to cite"

> AI sources are selected via retrieval-augmented generation: the system searches, retrieves relevant pages, and attaches citations to specific, verifiable claims. Selection emphasizes relevance, credibility, timeliness, and extractable, checkable passages.

Sources cited, in order: airops.com, truescreen.io, cite.solutions, contextbolt.com, aipogeo.com, wellows.com, surferseo.com, strategized.ai, authoritytech.io.

Attensira: not named.

_Source: attensira.com workspace, read over the Attensira MCP, as of 2026-10-04 (1 stored answer, Perplexity, 2026-10-03)._

## Key facts

- Also known as: Retrieval-augmented generation
- Pipeline: Query, retrieve, rerank, fill the context, generate
- Unit it moves: The passage, not the whole page
- First described: [Lewis et al., 2020 (Facebook AI Research, UCL, NYU)](https://arxiv.org/abs/2005.11401)
- Related term: [Reranking, the step that keeps the best few](/glossary/reranking)
- In Attensira: [Measure › Deciding sources](https://docs.attensira.com/measure/deciding-sources)

Ask ChatGPT a question with search on and watch the sources panel fill before the answer appears. That is retrieval-augmented generation: the system looks things up, and the model writes from what it found. Almost every AI answer that cites a web page is built this way, which makes RAG the mechanism behind AI visibility.

## How does a RAG pipeline work?

Five stages, and a page can be lost at each one:

1. **Query.** The question is turned into one or more search queries. Engines often split a question into several.

1. **Retrieve.** Each query runs against an index, by keywords, by meaning through [vector search](/glossary/vector-search), or both. This returns candidates, often dozens.

1. **Rerank.** A second, more careful model scores the candidates against the question and keeps the best few. See [reranking](/glossary/reranking).

1. **Fill the context.** The winning passages, not whole pages, go into the model's [context window](/glossary/context-window) alongside the question.

1. **Generate.** The model writes the answer from those passages and attaches the pages it used.

The unit that moves through the pipeline is the **passage**. A page with one paragraph that answers the question on its own competes better than a page whose answer is spread across three sections.

## What does retrieval look like in real answers?

Take one question from our own tracking: "how does AI pick which sources to cite", asked of ChatGPT and Perplexity every day. Perplexity's reply of 3 October 2026 opened: "AI sources are selected via retrieval-augmented generation". In the 30 days to 4 October 2026, read over the Attensira MCP, ChatGPT gave 57 answers carrying 1,204 citations and Perplexity 42 answers carrying 397; on ChatGPT, help.openai.com took 31.0% of the citations and openai.com 18.9%, while Perplexity's top domain, aisearch.similarweb.com, took 10.3%.

Same question, two retrieval systems, two different bodies of evidence. ChatGPT answers a question about how AI cites sources mostly from OpenAI's own help and product pages, 31.0% of its citations to help.openai.com alone. Perplexity spreads its evidence across third-party marketing and research sites, with fewer links per answer. Neither engine cited our pages for this question.

That is the practical meaning of RAG for a brand: there is no single "AI" to optimise for. Each engine's retriever decides what its model is allowed to read, and the answer can only be as good as, and only as favourable as, what was retrieved.

## Does every engine retrieve the same evidence?

No. One question we track, asked of two engines for 30 days, drew on two different bodies of evidence. ChatGPT read OpenAI's own help pages and linked about 21 sources per answer; Perplexity spread fewer links across third-party sites. Neither cited attensira.com.

**Citations behind "how does AI pick which sources to cite", 30 days to 4 Oct 2026**

| Engine | Answers | Citations | Most-cited domains |
| --- | --- | --- | --- |
| ChatGPT | 57 | 1,204 | help.openai.com 31.0%, openai.com 18.9% |
| Perplexity | 42 | 397 | aisearch.similarweb.com 10.3%, cite.solutions 8.3% |

_Source: attensira.com workspace, read over the Attensira MCP, as of 2026-10-04 (99 answers, 1,601 citations)._

## Why does RAG matter more than training for most brands?

Because it is the path you can act on. Training data is collected on the operator's schedule and used in a model you cannot inspect. Retrieval happens every time a question is asked, reads the page as it is today, and shows its work in the citations. Fix a page and the next retrieval can use the fixed version.

It also explains a common surprise: a brand can be named often and cited rarely, or the other way round. The model may know you from training and never retrieve your pages, or retrieve your page for a fact and recommend someone else.

## What does a page need to survive the pipeline?

- **Be fetchable.** The engine's search crawler must be allowed and must get the text in HTML, without running JavaScript.

- **Be retrievable for the question.** Use the words buyers use, and cover the question directly, so both keyword and meaning-based retrieval find it.

- **Have a passage that stands alone.** Put the answer in the first lines under a heading that asks the question.

- **Agree with other sources.** A claim several pages make is safer for the model to use.

## What do people get wrong about RAG?

- **Thinking ranking first in Google is enough.** Engines retrieve with their own queries and indexes.

- **Optimising whole pages.** The model reads passages.

- **Treating a citation as proof of accuracy.** Retrieval and writing fail separately.

- **Assuming a big context window removes competition.** Something still chooses what goes in.

## How does Attensira work with RAG?

It reads the output of each engine's pipeline, every day: the full answer and every citation in order. From that it ranks the pages that decide each question by citation share and position, marks whether you are on each one, and the crew proposes the next move: fix your own page so it has the passage the engine needs, or earn a place on the third-party page it already reads. See [win this answer](/features/win-this-answer) for how the deciding pages are ranked.

## FAQ

### What is RAG in simple terms?

Look it up, then answer. Instead of answering only from what it memorised in training, the system searches a collection of documents or the web, picks the passages that fit the question, gives them to the model, and the model writes an answer from them, usually with links to where each part came from.

### Where does the term RAG come from?

From a 2020 paper, Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks, by Patrick Lewis and colleagues at Facebook AI Research, University College London and New York University. It combined a language model with a searchable index of Wikipedia passages.

### How is RAG different from training a model on my content?

Training changes the model's weights once and leaves no record of which page taught it what. RAG reads your page at answer time, so the passage it used exists, can be cited, and changes when you edit the page. Training takes a new model release; retrieval can reflect a change within days.

### Does a bigger context window make RAG unnecessary?

No. A context window is finite and the web is not, so something still has to choose which passages go in. Putting more text in also makes it harder for the model to use the right part, so selection stays the step that decides what gets quoted.

### Why does a RAG answer sometimes cite a page it misread?

Because retrieval and writing are separate steps that fail separately. The right page can be retrieved and then summarised wrongly, or a passage can be quoted without the qualifier that sat two paragraphs away. That is why answers and their citations should be read together.
