coding-agents: the page search tool promises a "matching passage", and with no relevance cutoff every page comes back for any query
Bug Description
Follow-up to #5503, which was closed as working as designed: snippet is the page's opening text by contract. This is not a request to reopen it. The closing comment agreed that the coding-agents wording is misleading, and that part is still open. A second problem, which #5503 did not cover, is that the page search returns every page for any query.
1. The plugin promises a passage the server does not return. On main (unchanged since 0.8.1):
- tool description: "Returns ranked pages with a relevance snippet" (
knowledge-tools.tsL210) - session guide that the hook injects into the prompt: "It ranks the pages by relevance and returns the matching passage, which a page title cannot tell you" (
knowledge-injection.tsL68)
The server documents the snippet as "The page's opening text" (http.py L3736-L3743). An agent that trusts the guide reads an unrelated page opening as "this page does not cover it" and does not open the page.
2. There is no relevance cutoff. The vector arm takes the top max(limit * 4, 40) pages by distance with no threshold, and the fused query is a FULL OUTER JOIN of the two arms. On a bank with fewer than 40 pages, any query, a nonsense one included, returns min(limit, pages) hits. score is rank-based by contract (http.py L3744-L3750), and the tool drops it on purpose (knowledge-tools.ts L222-L226). So nothing in the result tells the agent whether any page matched at all. PR #4324 noted the same: "3 for a gibberish query ... A relevance cutoff on page hits could be a follow-up."
Taken together, every search returns the same list of page openings, whatever the query.
Environment
- Hindsight API 0.10.1, self-hosted with Docker Compose, PostgreSQL 16 + pgvector, native text search
@vectorize-io/hindsight-coding-agents0.8.1 (latest on npm), default page taxonomy
Steps to Reproduce
Derived from the code; the numbers under Actual Behavior come from our deployment (0.10.1). The search path is the same in 1.0.0 and on main.
- A bank with a few knowledge pages (fewer than 40), for example the plugin's default pages after a few sessions.
- Search for something no page contains:
Every page comes back. With no full-text match, each hit carries only the vector arm's rank score,GET /v1/default/banks/<bank>/knowledge-base/search?q=zxqv%20flurble%20gronk&limit=100.5 * 61 / (60 + rank)(~0.30 to 0.50). - Call
hindsight_search_knowledge_pageswith a question whose answer sits well past character 280 of one page. The result is{page, page_id, snippet}for every page. The snippet is each page's opening and there is no score, while the session guide has just told the agent the tool "returns the matching passage".
Expected Behavior
- The tool description and the session guide describe what the server returns: the opening of each page, and the page has to be read to find the passage.
- A query that matches nothing returns nothing, or at least hits the agent can tell apart from real matches.
Actual Behavior
Measured over one week of coding sessions (4 banks with 5 to 11 pages):
- every search returned every page up to
limit, nonsense queries included - 94 of 94 snippets were the first 280 characters of the page; in the top hit, the snippet contained 0 to 3 of the query's 6 to 12 terms
- when a page did answer the query, the passage sat between characters ~1,000 and ~41,000
- none of the 8 real searches was followed by a
hindsight_read_knowledge_pagecall
Version
Plugin 0.8.1: knowledge-tools.ts and knowledge-injection.ts are unchanged on main. Server 0.10.1, 1.0.0 and main.
Suspected cause
Permalinks at main (5331da2f):
- the vector arm, no threshold:
memory_engine.pyL20108-L20115, withfetchat L19966 - the fusion: L20127-L20132
Same code in 1.0.0: L19799-L19806, L19818-L19823.
Suggested fix
- As agreed in #5503: the tool description and the session guide say the snippet is the page's opening, and that the page has to be read to find the passage.
- A signal the agent can act on, without a search redesign. Either return per hit whether the full-text arm matched (
bm.page_id IS NOT NULLis already available in the fused query) or the raw vector similarity, and let the plugin drop hits that matched neither text nor a minimum similarity; or add an optionalrequire_text_match/min_similarityparameter toGET /knowledge-base/search.
A production case of this, from a self-hosted 1.2.1 server with coding-agents 0.8.7 (pi harness).
An agent was asked why a product behaves the way it does. It called hindsight_search_pages; the result (8 hits, about 14 KB) included the page that held the answer, a dated decision and the issue that implemented it. Every snippet was the page opening ("## Purpose and scope…"), so nothing in the result showed the answer was inside. The agent opened none of the pages and gave the user a confident, wrong answer. The tool description had told it the search "returns the matching passage".
reflect already handles this: engine/reflect/tools.py returns the best hits whole up to a budget, with the comment that a model answering from a snippet without reading the page is a measured failure (test_reflect_from_page). The agent-facing tool has the same failure and no such guard.
Request, in order of preference:
hindsight_search_pagesreturns the best hit whole (same budget rule as reflect'ssearch_mental_models), the rest as openings.- Failing that, the tool description says plainly that the snippet is the page opening and that the top page must be read before answering, as suggested when #5503 was closed.