A complete RAG pipeline with a fake model
Ask your own questions by changing the list at the bottom. Notice the "not found" answer when nothing relevant is retrieved.
RAG answers questions from your own documents: split them into chunks, embed them, retrieve the chunks closest to the question, put them in the prompt as numbered sources, and have the model answer and cite them. It is a few dozen lines of Python, and most failures come from bad chunks and missing context.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write chunk_words(text, size, overlap) returning overlapping chunks of words.
Write build_prompt(question, sources) that numbers sources from 1.
Write valid_citations(answer, source_count) that checks that every [n] in the answer points at a real source and that at least one citation exists.
Explain it without notes
Walk through the indexing and answering phases of RAG.
How do chunk size and overlap affect retrieval quality?
How do you reduce wrong or ungrounded answers in a RAG system?
Users say your RAG assistant gives wrong answers. How do you find out whether the retriever or the generator is at fault, and what do you try first?
Expected output
Q: what does a virtual environment do
retrieved: [('python.md', 0.53)]
A: A virtual environment keeps the packages of one project separate from another. [1]
Q: what is the capital of France
retrieved: []
A: I could not find that in the documents.