Artificial intelligence • Original RRTutors lesson
Retrieval-Augmented Generation (RAG)
Combine search over trusted documents with a generative model to produce context-grounded answers.
Concept and explanation
RAG retrieves candidate passages and places selected evidence in the model context. Its quality depends on document freshness, chunking, retrieval, ranking, context assembly, and answer generation. Citation display is useful only when citations actually support the associated claims.
How to apply it
Build a document ingestion and access-control pipeline, evaluate retrieval separately from generation, and require abstention when evidence is insufficient.
Worked example
An internal policy assistant can retrieve the current policy sections, answer from those sections, and link users to the source documents.
Illustrative Python example
question = "How many days do I have to submit a claim?"
passages = retrieve(question, authorized_documents)
answer = generate(question, passages)
print(answer)
Expected result
Retrieval adds relevant context, but each function still needs access control and evaluation.
Limitations and cautions
RAG does not eliminate hallucinations, stale documents, retrieval misses, or prompt injection embedded in retrieved text.
Practice exercise
Design a RAG evaluation set with questions that have answers, missing answers, and permission-restricted sources.
Key takeaway: Grounding requires trustworthy retrieval, citations, and a safe no-answer path.