Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

docs(search): troubleshooting names --expand now that query does not expand by default; guard the retired advice

garrytan9a4e54e89ec5
diff --git a/docs/guides/search-explain.md b/docs/guides/search-explain.md
index 810fdb6ae2..5cf51479ce 100644
--- a/docs/guides/search-explain.md
+++ b/docs/guides/search-explain.md
@@ -82,7 +82,7 @@ the next step:
| `target_dropped_return_sizing` | Autocut or adaptive return trimmed it. | `get_page`, or repeat with `autocut: false` (query). |
| `target_dropped_token_budget` | The evidence budget filled first. | Repeat with a larger `token_budget`. |
| `target_dropped_relaxed_keyword` | Only a loose keyword match found it. | `get_page`, or rephrase with the page's own terms. |
-| `target_not_retrieved` | No arm returned it for this query. | `query` (multi-query expansion) or rephrase. |
+| `target_not_retrieved` | No arm returned it for this query. | `query --expand` (`expand: true`; one call to the configured expansion model) or rephrase. |
| `target_not_indexed` | The page has no indexed chunks. | `gbrain doctor --json` names the re-index command. |
| `target_projection_stale` | The page changed and its searchable text is still being rebuilt. | Retry after `gbrain doctor` shows the backlog drained. |
| `target_safe_chunks_uncertified` | Remote reads withhold pages indexed before the current safe-chunk format. | The brain host runs `gbrain repair safe-chunks`. |
diff --git a/docs/guides/search-modes.md b/docs/guides/search-modes.md
index 6d19834dc7..c370e2aaf1 100644
--- a/docs/guides/search-modes.md
+++ b/docs/guides/search-modes.md
@@ -413,10 +413,10 @@ on user_asks_about(topic):
1. **Search returns chunks, not full pages.** After `gbrain search` or `gbrain query`, you get excerpts. Always run `gbrain get <slug>` to load the full page when the chunk confirms relevance. Don't answer questions from chunks alone when the full context matters.
2. **Search works without embeddings.** On day one before any embedding run, `gbrain search` still works (the keyword arm carries it; the vector arm joins once embeddings exist). Don't tell the user "search isn't available yet" -- search is always available.
-3. **Don't use full hybrid for known names.** `gbrain query "Alice Example"` wastes an LLM expansion call. Use `gbrain search "Alice Example"` or better yet `gbrain get alice-example` if you know the slug.
+3. **Don't use full hybrid for known names.** `gbrain query "Alice Example" --expand` wastes an LLM expansion call, and bare `query` returns the larger evidence payload. Use `gbrain search "Alice Example"` or better yet `gbrain get alice-example` if you know the slug.
4. **Token budget awareness.** A full page via `gbrain get` can be large. Read the search chunks first to confirm relevance before pulling the full page. "Did anyone mention the Series A?" -- search results (chunks) are probably enough. "Tell me everything about Alice" -- get the full page.
5. **Full hybrid needs embeddings to have been run.** If `gbrain query` returns nothing but `gbrain search` finds results, the embeddings haven't been generated yet. Run the embedding pipeline first.
-6. **A populated `gbrain search` result set is not proof you found everything.** Search runs without query expansion, so synonym- and outcome-phrased matches can be missed even when it returns plenty of hits. For "find every / all / the landscape of" questions, use `gbrain query`; for literal exhaustive enumeration ("list every page of type X"), use `list_pages` pagination. A nonzero count is not a completeness signal.
+6. **A populated `gbrain search` result set is not proof you found everything.** Neither verb expands by default, so synonym- and outcome-phrased matches can be missed even when a search returns plenty of hits. For "find every / all / the landscape of" questions, use `gbrain query`, adding `--expand` (one call to the configured expansion model, which needs an expansion provider) when the wording is likely to differ from the notes; expanded results are still a ranked top-K; for literal exhaustive enumeration ("list every page of type X"), use `list_pages` pagination. A nonzero count is not a completeness signal.
### How to Verify
diff --git a/llms-full.txt b/llms-full.txt
index 3d9cd7aa37..9e6ce19866 100644
--- a/llms-full.txt
+++ b/llms-full.txt
@@ -2858,8 +2858,8 @@ Estimated downstream input cost of the retrieved payload @ 10K queries/mo:
>
> 2) balanced — 12K budget, 25 chunks, reranked.
>
-> 3) tokenmax (recommended with a chat key) — no budget, 50 chunks, reranked,
-> per-chunk synopsis context. The widest retrieval.
+> 3) tokenmax (recommended with a chat key) — no budget, 50 chunks, reranked.
+> The widest retrieval.
>
> `gbrain query` does not expand by default in any mode; `--expand`
> (`expand: true` over MCP) forces it and `--no-expand` (`expand: false`) skips
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index b563f07815..93dd7da94c 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -642,7 +642,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText }
{ since: '0.60.249.0', text: 'On a brain without managed persistence, `extract_facts` (and the v0.32.2 fence step) now fences unfenced facts of a database-only page (no recorded file and none at its slug path) into the page\'s database body when such a write is database-only (`sync.write_through` off, or on Postgres an unbound source with `persistence.unbound_write=database_only`, which stamps the page `unbound_source`), instead of reporting a missing canonical file and halting the facts fence every run. Without that opt-in the rows stay unfenced and their page skips reconciliation, but they no longer count as pending (`legacyRowsPending`) or trigger the guard; doctor `fence_integrity` lists them under `unbound_legacy_facts` and asks the user about the opt-in, and the migration reports them as `skipped_unbound_source`.' },
{ since: '0.60.249.0', text: 'On a brain without managed persistence, `gbrain restore` / `restore_page` of a soft-deleted page whose recorded file is gone from the checkout now refuses (`source_changed`, detail `canonical_file_absent`) when the restore writes no file, instead of restoring a page the next `gbrain sync --full` deletes again. Put the file back and sync, or pass `--detach` (`detach: true`) to restore it database-only (`database_only_reason=detached`, no `source_path`); a file synced back at its path binds the page again. New doctor check `missing_recorded_files` lists live pages a full sync would delete this way.' },
{ since: '0.60.250.0', text: 'Remote agents and token-floor connections now get stored contradiction findings from `find_contradictions` instead of an availability note or a refusal: only findings whose two sides they can read now, each side re-read live with its `source_id` and `trust_tier`, never the stored report text; `min_trust` and the token floor filter instead of refusing. A local `gbrain find-contradictions --source <id>` (or `GBRAIN_SOURCE`) now gets that scoped view instead of the note; the bare command still reads the whole stored run.' },
- // LHF wave 2 item 1 (GBRA-94): tokenmax `query` no longer expands by default.
+ // LHF wave 2 item 0 (GBRA-94): tokenmax `query` no longer expands by default.
{ since: '0.60.251.0', text: '`gbrain query` no longer runs LLM query expansion by default on `tokenmax`, so no search mode expands by default. On 300 LongMemEval-S questions with the reranker, `query` without expansion kept retrieval within noise (298 vs 299 of 300) and its p50 fell from about 2 s to about 230 ms (gbrain-evals expansion-latency report, 2026-10-14). To keep expanding: `gbrain config set search.expansion true` for the brain, or pass `--expand` / `expand: true` per call.' },
];
diff --git a/test/search/query-expansion-phrasing-guard.test.ts b/test/search/query-expansion-phrasing-guard.test.ts
index 4b09144b10..ba61807a11 100644
--- a/test/search/query-expansion-phrasing-guard.test.ts
+++ b/test/search/query-expansion-phrasing-guard.test.ts
@@ -17,6 +17,9 @@ const ROOT_DOCS = ['INSTALL_FOR_AGENTS.md', 'CLAUDE.md', 'AGENTS.md', 'README.md
const CLAIM = /\b(?:expands?|expansion|expanding)\b[^.;\n]{0,40}\bin every mode\b|\bin every mode\b[^.;\n]{0,20}\bexpan(?:ds?|sion)\b|\balways (?:expands?|requests expansion)\b/i;
/** A claim that `tokenmax` turns expansion on by default. */
+/** Troubleshooting advice that sends agents to bare `query` for expansion. */
+const BARE_QUERY_EXPANSION_ADVICE = /`query` \(multi-query expansion\)|`gbrain query "[^"]*"` wastes an LLM expansion call|search runs without query expansion, so/i;
+
const TOKENMAX_CLAIM = /\bexpan\w*\b[^.\n]{0,80}\bon (?:in|for|only in) `?tokenmax`?|`?tokenmax`?[^.\n]{0,30}\bexpansion ?[=:]? ?on\b|`?tokenmax`?[^.\n]{0,80}\bexpands by default\b/i;
function files(dir: string): string[] {
@@ -47,6 +50,12 @@ describe('query expansion phrasing guard', () => {
'tokenmax (expansion=on, limit=50) has a different hash',
'3) tokenmax — no budget, 50 chunks, reranked, `gbrain query` expands by default.',
]) expect(old).toMatch(TOKENMAX_CLAIM);
+ for (const old of [
+ '| `target_not_retrieved` | No arm returned it for this query. | `query` (multi-query expansion) or rephrase. |',
+ '`gbrain query "Alice Example"` wastes an LLM expansion call.',
+ 'Search runs without query expansion, so synonym- and outcome-phrased matches can be missed',
+ ]) expect(old).toMatch(BARE_QUERY_EXPANSION_ADVICE);
+ expect('`query --expand` (`expand: true`) or rephrase').not.toMatch(BARE_QUERY_EXPANSION_ADVICE);
for (const fine of ['`gbrain query` does not expand by default in any mode', 'tokenmax (limit=50, no token budget)', 'reranker on for balanced and tokenmax']) {
expect(fine).not.toMatch(TOKENMAX_CLAIM);
}
@@ -58,7 +67,7 @@ describe('query expansion phrasing guard', () => {
for (const path of paths) {
if (relative(ROOT, path) === 'src/core/behavior-change-notice.ts') continue;
readFileSync(path, 'utf8').split('\n').forEach((line, i) => {
- if (TOKENMAX_CLAIM.test(line)) offenders.push(`${relative(ROOT, path)}:${i + 1}: ${line.trim().slice(0, 160)}`);
+ if (TOKENMAX_CLAIM.test(line) || BARE_QUERY_EXPANSION_ADVICE.test(line)) offenders.push(`${relative(ROOT, path)}:${i + 1}: ${line.trim().slice(0, 160)}`);
});
}
expect(offenders).toEqual([]);