Agent Wranglers

AIF-23Recommended

Say so when nothing relevant was found

When search finds nothing above a set relevance threshold, reply that the documents do not cover the question. Do not let the model answer from its general knowledge.

How to do it

Pick a threshold from the retrieval evals, such as the lowest score that still found a right document in 95 of 100 cases. Below it, skip the model and send a fixed reply with a link to search or support. Log these questions, because they show which documents are missing. The interface side is to tell an empty start from an empty search.

Examples

TypeScript example

if (!hits.length || hits[0].score < MIN_RELEVANCE) {
  log.info({ event: 'retrieval.no_match', feature: 'help-search' });
  return { text: NO_MATCH_REPLY, sources: [] };
}

Python example

if not hits or hits[0].score < MIN_RELEVANCE:
    log.info("retrieval.no_match", feature="help-search")
    return {"text": NO_MATCH_REPLY, "sources": []}

How to check

Ask a question the documents do not cover, such as one about a product you do not sell. The reply says the documents do not cover it, and the log shows a no-match event.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/ai-features/retrieval/no-match-answer">Agent Wranglers AI features playbook</a>. In code you write, add a comment next to it with the same link.