Eliminating Near-Miss Distractors and Stale Knowledge
Learn to use metadata-driven freshness and authority filters to remove stale runbooks and unapproved drafts from hybrid search results. You’ll apply filters before selecting top results, record drop reasons, and improve the evidence supplied to AI assistants.
We'll cover the following...
In the previous lesson, we built hybrid_search(), which combines keyword ranking, meaning-based ranking, SQL filters, and code chunks into one call. It finds relevant documents well. But its results still included note-4, the 2024 runbook that says to restart Redis first, a step the current runbook forbids during business hours.
Real document stores have a second kind of problem. Teams also write drafts: proposed runbook changes that are still waiting for review. A draft is about the same topic and uses the same words as the approved runbook, so search finds it just as easily.
In this lesson, we’ll add a draft to the store and watch three versions of the same runbook tie in the search results. We’ll see why score cutoffs can’t separate them. Then we’ll give every note a few metadata fields, write two filters that use them, and add both filters to the search.
Add a draft to the store
Let’s add note-9, a draft update to the checkout latency runbook. It’s pending review, and it tells engineers to restart the Redis cache first.
In Lesson 2.4, we kept a small registry called RUNBOOK_INFO with a topic and an effective date for each runbook. Now we’ll extend that idea to every note. Each note gets four metadata fields, which describe the note itself and not its text:
subject: The fact or procedure the note is about. Notes with the same subject are versions of the same thing.effective_date: The date the note took effect. A draft has no date yet.source_type: What kind of document it is, such as a runbook, postmortem, guideline, or draft.superseded_by: The note that replaced this one, if any.
In a real system, these fields would come from the document system itself, such as a wiki’s page status or a runbook repository’s commit dates.
In the code above:
Lines 3–6: We define the draft as
note-9and add it to the eight existing notes in ...