# What is RAG (retrieval-augmented generation)?

> What RAG is in AI, the paper it comes from, how Google and ChatGPT use it to answer with sources, and what part of your product page ends up in the answer.

URL: https://clione.ai/glossary/rag/
Lang: en

RAG stands for _retrieval-augmented generation_. It isn't a model or a product but a way of building a system: **first it searches, then it writes**. If you search for "rag" on its own you'll find cloths, ragtime music and little else; here we mean artificial intelligence. A store should care because every time an assistant answers with sources and cites your [product page](/glossary/product-page/), your page was the retrieved document, and what the system took from it decides what it says about you.

## How it works

The name comes from a research paper by Patrick Lewis and eleven other authors, published on arXiv on May 22, 2020 and accepted at NeurIPS 2020. It started from a problem: pretrained language models store knowledge in their parameters but struggle to access it precisely, and **explaining where an answer comes from or updating what they know** were still open problems.[^rag-paper] Its proposal was to combine two memories: the model's own and an external one, a vector index of Wikipedia queried with a neural retriever. On generation tasks, those models produced language that was **more specific, diverse and factual** than an equivalent model without retrieval.[^rag-paper]

A typical RAG system today does four things, and Anthropic describes them step by step:[^anthropic-contextual]

1. **It splits the documents** into chunks of text, usually no more than a few hundred [tokens](/glossary/token/).
2. **It turns each chunk into a vector** with an [embeddings](/glossary/embeddings/) model and stores it in a vector database, so it can search by similarity of meaning.
3. **It retrieves** the chunks most relevant to the question, often combining that [vector search](/glossary/vector-search/) with an exact-word search (BM25).
4. **It adds those chunks to the request** and the language model writes the answer with them in front of it.

The weak point is the first step. A loose chunk can lose what made it useful: Anthropic gives the example of a sentence from a financial report, "the company's revenue grew 3% over the previous quarter", which without the rest of the document doesn't say which company or which quarter it is about. By adding a line of context to each chunk before [indexing](/glossary/indexing/) it, Anthropic measured **49% fewer retrieval failures**, and 67% fewer if it also reranked the results.[^anthropic-contextual]

### RAG in AI search engines

In [AI search](/glossary/ai-search/), the index is the web. Google defines RAG, which it also calls [grounding](/glossary/grounding/), as a technique for improving the quality, accuracy and freshness of answers: **its usual ranking systems retrieve pages from its index**, the system reviews the specific information on those pages and generates the answer with links to the ones that support it.[^google-ai-guide] That is why, for Google, getting into what is retrieved still runs through crawling and [indexing](/glossary/indexing/).

ChatGPT does something similar with outside search providers: it rewrites the question into one or more queries, reviews the first results and can run more specific ones before answering.[^openai-help-search] That step of multiplying queries has a name of its own, [query fan-out](/glossary/query-fan-out/). And Bing shows site owners a trace of the retrieval: its AI Performance report shows the grounding queries, the key phrases the AI used to retrieve the content it ended up citing.[^bing-ai-performance]

## In a store

A **fictional example**: the product page of a travel tripod. Microsoft explains that assistants split content into pieces and assemble the answer from pieces of several sources,[^microsoft-ai-search] so it pays to read the page the way a retriever would, paragraph by paragraph:

| Chunk of the page                               | Read alone, does it make sense?     | How to fix it                                                                                      |
| ----------------------------------------------- | ----------------------------------- | -------------------------------------------------------------------------------------------------- |
| "Weighs 3.1 lb and holds up to 17.6 lb."        | No: it doesn't say what weighs that | "The X travel tripod weighs 3.1 lb and holds up to 17.6 lb."                                       |
| "Compatible with all the previous ones."        | No: previous what?                  | Name the ball heads or cameras it works with                                                       |
| "Folded it measures 16 in, fits in a carry-on." | Half: the product is missing        | Name the product in the sentence                                                                   |
| Spec table inside an image                      | Never reaches the text              | Move it to HTML; Microsoft warns that text in images is understood less well[^microsoft-ai-search] |

It is the same problem as the financial report: **a sentence that only makes sense with the whole page around it** gets retrieved worse and cited worse. Clione uses this scheme in its own enrichment: when the store turns it on, it attaches to each product's prompt four chunks from the documents the store has uploaded, about 1,200 tokens.


That RAG puts an end to made-up answers. Retrieval helps: the original paper measured answers more faithful to the facts,[^rag-paper] and Google uses it to improve accuracy.[^google-ai-guide] But the model still does the writing, and OpenAI warns that [ChatGPT search](/glossary/chatgpt-search/) results and citations **can be incomplete, outdated or wrong**, and advises opening the cited source to check that it supports the answer.[^openai-help-search] A citation doesn't guarantee the sentence next to it is on your page.


## How to check it

1. **Read your product page paragraph by paragraph, as loose chunks.** If a paragraph doesn't name the product or depends on the previous one to make sense, rewrite it so it stands alone.[^anthropic-contextual]
2. **Pull the facts out of images, PDFs and closed tabs** and put them in the page's HTML text.[^microsoft-ai-search]
3. **Confirm in [Search Console](/glossary/google-search-console/) that the page is indexed.** In Google, what isn't in the index isn't retrieved.[^google-ai-guide]
4. **Ask a question with search on and open every cited source.** Check that the sentence credited to it is really on the page.[^openai-help-search]
5. **If your site is in [Bing Webmaster Tools](/glossary/bing-webmaster-tools/), look at the grounding queries** in AI Performance: which phrases led to retrieving the pages that cited you.[^bing-ai-performance]

## Related concept: grounding

Google treats RAG and grounding as the same process: its guide defines RAG and adds that it is also known as grounding.[^google-ai-guide] The useful difference is one of focus. RAG names the mechanism, retrieve and then generate; grounding names the result you are after, an answer anchored in specific sources. That is why Bing talks about grounding queries for the searches the AI runs before citing.[^bing-ai-performance] For a store, the practical point is the same under both names: **your page only counts if it is retrieved, and it is only cited well if each chunk makes sense alone**.

To keep going, the [LLM (large language model)](/glossary/llm/) entry explains what the model does with what is retrieved, and the [AI search reading path](/learn/ai-search/) puts the other terms in order.
