# RAG

> Retrieval-augmented generation (RAG) retrieves relevant text, then asks the model to answer from that text.

Retrieve relevant text, then ask the model to answer from that text.

Track: Retrieval & Grounding
Access: free
Card: https://buildsparkai.com/rag
Plain text: https://buildsparkai.com/rag.md
Last checked: 2026-10-18

## What it is

Retrieval-augmented generation is the full name. This card uses RAG for short. Search returns pieces of your documents, and those pieces go into the request with the question. Gemini's File Search guide calls this retrieval augmented generation: the tool imports, chunks, and indexes files, then the retrieved text is context for the model. LlamaIndex's RAG overview says the query filters data down to relevant context, and that context and the query go to the model with a prompt.

## Why it matters

**Cost.** The retrieved text is still input. Gemini's File Search guide says retrieved document tokens are charged as regular context tokens, and that embeddings are charged when you index a file. OpenAI's retrieval guide says vector store storage is charged from the size of the parsed chunks and their embeddings. This card does not add a price.

**Quality.** The model can use the text you retrieved and cannot use a passage you left out. OpenAI's retrieval guide says retrieval is especially useful when a model then synthesizes a response. If the chunk that holds the fact was not retrieved, that fact is not in the request.

**Risk.** A retrieved chunk can be outdated or wrong, and the model can still add a sentence the chunk does not contain. Retrieval does not check who is allowed to see the file.

## Try today

Take one question you answer from a document you already have. Paste only the paragraph that contains the answer, and tell the model to answer from that paragraph. Then send the same question with no paragraph.

## Common mistake

Calling it RAG when the prompt has the whole file, or no file, and when you do not look at the text that was retrieved.

## Self-check

You want an answer from a policy document. What is RAG?

Retrieve relevant text, then ask from that text

## Practice and deep

Coming soon. One question you already ask of a document, answered once with the paragraph and once without it.

Coming soon. How a hosted file-search tool chooses chunks, and what you still have to check in the reply.

## Sources

- [Gemini, File Search: RAG](https://ai.google.dev/gemini-api/docs/file-search)
- [OpenAI, Retrieval guide](https://developers.openai.com/api/docs/guides/retrieval)
- [LlamaIndex, Introduction to RAG](https://developers.llamaindex.ai/python/framework/understanding/rag/)

Sources opened 2026-10-17. The 2026-10-18 edit names retrieval-augmented generation. Each page is a vendor or framework doc. The card does not add a rate or a usage count.
