Matching a Question to a Line

keyword grounding check

Part of: FAQ Support Bot

Before you trust the model's answer, check it yourself: does this question connect to anything in the FAQ, or is the model about to answer from thin air? This lesson builds a plain-Python grounding check that runs before you call the model. It costs nothing and catches the obvious misses. Why check before calling the model You can tell the model "only use the FAQ" and it will still wander now and then. So don't rely on instructions alone. Build a pre-check : a keyword overlap test between the user's question and each FAQ line. If nothing overlaps, the FAQ doesn't cover this, and you can skip the call or flag the answer as unsupported before it ships. It's the same instinct as lesson 5 in the playbook module, verify before you trust, aimed here at grounding. A simple overlap score best match returns the line number with the most overlapping keywords, plus the score. A score of 0 means no FAQ line shares a single meaningful word with the question, a strong signal the FAQ doesn't cover it. What this buys you This doesn't replace the model reading the FAQ. It's a cheap, deterministic sanity check in pure Python with no network call, and two things fall out of it. The highest-scoring li

Challenge: Best-Match Line Finder