When not to retrieve
Rules for "do not retrieve" are narrow on purpose. Anything unrecognised retrieves.
In a chat, the latest message is often not a question on its own: "what about the second one?". Turn the history plus the follow-up into a standalone question before retrieval, and skip retrieval when the message does not need the documents.
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 needs_rewrite(history, message) that returns True when the history is non-empty and the message has four words or fewer, or contains one of it, that, one. Print yes or no for three cases.
Write last_turns(history, n, limit) returning the last n messages, each cut to limit characters. Print the result for six short messages with n = 4 and limit = 10, joined with " | ".
Explain it without notes
Why can't a retriever answer "how much is it?"?
What goes into a standalone-question prompt, and what do you leave out?
Why not make a model call on every turn?
Why must the rule for skipping retrieval be narrow?
Expected output
hello no retrieval (small talk)
Thanks a lot! no retrieval (small talk)
Can you make that shorter? no retrieval (about the last answer)
hi, how do I reset my password? retrieve
What does the monthly pass cost? retrieve