Skip to main content

Context

What is RAG (retrieval-augmented generation)?

RAG retrieves relevant passages from your own documents and puts them in front of the model. How chunking and retrieval quality decide whether it works.

All explainers · Last reviewed:

How it works

Documents are split into chunks and each chunk is converted into a vector — a numeric representation of its meaning. The question is converted the same way, and the chunks whose vectors are closest are retrieved.

Those chunks are inserted into the prompt, usually with an instruction to answer from them. The model does the language work; the retrieval does the knowing.

Retrieval quality is the whole system

If the right passage is not retrieved, no model can rescue the answer — it will answer from general knowledge and sound just as confident. Most disappointing RAG systems are retrieval problems wearing a generation costume.

Chunking is where this is decided. Chunks that are too small lose the context that made them meaningful; too large and each one dilutes the match. Splitting on document structure — sections, headings — usually beats splitting on a fixed length.

What it does and does not fix

RAG fixes "the model has never seen my documents". It reduces hallucination on questions the documents answer, because the answer is in front of the model.

It does not fix reasoning, and it does not stop the model answering from memory when retrieval returns nothing useful. Grounding is a strong tendency, not a guarantee, and the failure mode is a confident answer with no source.

Questions people ask

Is RAG the same as fine-tuning?
No, and they solve different problems. Fine-tuning changes how a model behaves; RAG changes what it knows for one request. For "answer questions about my documents", RAG is almost always the right tool and far cheaper to keep current.
Do large context windows make RAG obsolete?
No. You can paste more in, but you pay for every token on every message and models attend unevenly across very long inputs. Retrieval is also the only approach that scales past what any window holds.
Does RAG send my documents to the model provider?
The retrieved passages, yes — that is how the model sees them. If that is unacceptable, the model has to run somewhere you control, which is what local execution is for.

Try it rather than read about it

ClawAI retrieves from files you attach, and pairs it with local execution so the retrieved passages can stay on your own hardware.