Closed book vs open book
The fake model stands in for a real one: with no source it answers from a tiny memory (and guesses when the memory is empty); with a source it answers from the source and cites it.
Retrieval-augmented generation (RAG) means your program first finds the passages that answer a question and then asks a language model to answer using those passages. It turns a closed-book exam into an open-book one.
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 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write retrieve(question, docs) that returns the id of the passage sharing the most different words with the question, or None when no passage shares any word. Test it on the three handbook passages with "Is a helmet included?" and "Do you sell gift cards?".
Write open_book_prompt(question, doc_id, text) that returns the three-line prompt from Step 3, and print it for the opening-hours passage.
Explain it without notes
Explain RAG to someone who has never programmed, in two or three sentences.
Name the three parts of a RAG system and say what each one does.
Why can a RAG system answer a question about a document that was written this morning, when the model was trained a year ago?
"We added RAG, so the bot can't make things up any more." What is wrong with this claim?
Expected output
Question: When do the shops open?
Closed book: Probably 9 am, like most shops. (a guess: the handbook was never in my training text)
Retrieved: D2 (Shops open at 7 am and c...)
Open book: Shops open at 7 am and close at 9 pm every day. [D2]
General knowledge still works: Paris.