RAG combines a retrieval system with a generative model. Before the model answers, a search step selects passages from a corpus, and those passages are inserted into the prompt as context. The model is asked to answer from them, ideally with citations. The appeal is that the knowledge can be updated without retraining, and the source can be shown.

The quality of a RAG system is mostly retrieval quality. If the right passage is not retrieved, the model cannot ground its answer in it, and a confident model may fill the gap from memory. Chunking, embedding choice, query rewriting, and the ranking function matter more than the wording of the final prompt. A large context window does not fix retrieval; it only lets you paste more of the wrong passages.

Two failure modes are common: the model cites a passage that does not support the claim, and the retrieved text contains an instruction (an indirect prompt injection). Check grounding against the source, treat retrieved text as untrusted, and keep the citation in the answer. See embedding and prompt injection.