Building with AILesson 39 of 80

Module 4 · Retrieval and the knowledge problem

Rewriting the question before you search it

In this lesson

  • 9 min read
  • 8 reading sections
  • Knowledge check
  • Lesson 8 of 11 in this chapter

This chapter’s goalBuild a retrieval pipeline from raw documents to a ranked set of chunks (embed, index, fuse with keyword search, rerank, filter by permission) measure its recall on a gold set of your own questions, and say from cost and quality numbers whether a given corpus should be retrieved or simply placed in the context window.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 9Free · no account needed
Lesson steps

The query the user typed is not the query to search

A user asks “what does the Pro plan cost?”, gets an answer, and then types “and for enterprise?”. Embed that second message on its own and it lands nowhere useful. The word that matters, cost, is in the previous turn. The retrieval system, which sees only the string it was given, returns chunks about enterprise onboarding, enterprise security, anything with the word in it, and the model answers from the wrong passages.

This is the most common failure in chat-over-documents, and it has nothing to do with embeddings. The fix is to rewrite the message into a standalone query before searching. A small, fast model, given the last few turns and asked to produce one self-contained search query, returns “enterprise plan pricing” in a hundred milliseconds for a fraction of a cent. That one step fixes more follow-up questions than any change to the index.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the Python, from Zero, for AI exam.

Stuck on something?Ask Sayali, your AI tutor

How to cite: Addaly (2026) ‘Rewriting the question before you search it’, in Building with AI. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/building-with-ai/rewriting-the-question (Accessed: 27 November 2026).