Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
search: multi-hop planner on by default in balanced and tokenmax (held-out verdict)
garrytanc5e56a8705e4
diff --git a/docs/architecture/key-files/core-search-2.md b/docs/architecture/key-files/core-search-2.mdindex f71b19e0dc..5acd8cc06a 100644--- a/docs/architecture/key-files/core-search-2.md+++ b/docs/architecture/key-files/core-search-2.md@@ -35,6 +35,6 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL- `src/core/search/hub-dampening.ts` — `hubWeight(degree, H)` = 1 / (1 + ((max(n,1) − 1) / H)²), `'off'` → 1; `dampenBoost`, `normalizeHubDampening`. Pure; callers pass the caller-visible degree.-- `src/core/search/relational-recall.ts` — the relational recall arm: `parseRelationalQuery` → seed resolution per in-scope source (federated set, scalar source, or every non-archived source for an unscoped caller; a literal `__all__` resolves no seeds, fail-closed) → `relationalFanout` → hydrate, fail-open. Seeds resolve through `resolveEntitySlugWithSource` and a `fallback_slugify` result is dropped (confidence gate D3). The entity resolver never returns meetings, so for an incoming `attended` relation (`Who attended <meeting>?`) a live `meeting` or `event` page whose title is exactly the seed phrase (case-insensitive, unique in the source) is the seed; other relations never seed from titles. Pinned by `test/relational-recall.test.ts`, `test/relational-recall-scope-sources.test.ts` and `test/pack-relation-direction-engine.test.ts`. With `planner` on (`search.relational_planner`), a 2-3 relationship question (`parseRelationalPlan`) runs `runRelationalChain` first: answers then evidence pages, each with a `relational` field; nothing found → the one-hop path; refused → no arm (`meta.plan`). With `orientOneHop` (`search.relational_orient_onehop`, unset follows the planner) typed one-hop walks add neighbors reached through links written on the other page. `answerRows` limits the pin and evidence slot to answers. Pinned by `test/relational-recall.test.ts`.+- `src/core/search/relational-recall.ts` — the relational recall arm: `parseRelationalQuery` → seed resolution per in-scope source (federated set, scalar source, or every non-archived source for an unscoped caller; a literal `__all__` resolves no seeds, fail-closed) → `relationalFanout` → hydrate, fail-open. Seeds resolve through `resolveEntitySlugWithSource` and a `fallback_slugify` result is dropped (confidence gate D3). The entity resolver never returns meetings, so for an incoming `attended` relation (`Who attended <meeting>?`) a live `meeting` or `event` page whose title is exactly the seed phrase (case-insensitive, unique in the source) is the seed; other relations never seed from titles. Pinned by `test/relational-recall.test.ts`, `test/relational-recall-scope-sources.test.ts` and `test/pack-relation-direction-engine.test.ts`. With `planner` on (`search.relational_planner`, on in balanced/tokenmax), a 2-3 relationship question (`parseRelationalPlan`) runs `runRelationalChain` first: answers then evidence pages, each with a `relational` field; nothing found → the one-hop path; refused → no arm (`meta.plan`). With `orientOneHop` (`search.relational_orient_onehop`, off in every bundle) typed one-hop walks add neighbors reached through links written on the other page. `answerRows` limits the pin and evidence slot to answers. Pinned by `test/relational-recall.test.ts`.- `src/core/search/relational-rerank-pin.ts` — relational-arm rows bypass reranker DEMOTION (ranker wave, receipt R1 in `scripts/r1-namedthing-rerank-ab.ts`: on NamedThingBench's 39 graph-relationship questions the shipped `balanced` default lost hit@1 21/39 → 3/39 and hit@3 27/39 → 5/39 with the reranker on — 19 and 22 paired losses — because the cross-encoder scores chunk TEXT and an edge-derived answer's text need not mention the query's entity; with the pin at its default 3, measured with `--autocut on`, the shape that shipped before rule R2 turned autocut off, the same paired run shows 0 hit@1 / 0 hit@3 losses, 21/39 and 27/39, and the 11 non-relational core queries show 0 losses — one hard-negative gain, hit@1 10/11 → 11/11). `pinRelationalRows(reranked, relationalList, {max, fusedOrder?, onPin?})` is a pure PERMUTATION of the post-rerank pool: relational rows (page key `(source_id, slug)` in the arm's list; ONE row per page — its first, highest-ranked occurrence) claim `min(fused_rank, reranked_rank)` (fused rank = position among relational rows in `fusedOrder`, the pre-rerank `deduped` pool; arm order for rows absent from it), claims sort ascending with ties resolved to the FUSED order then the reranked position, the first `max` claimants form the top block in that order, every other row follows in reranked order (an unpinned row lands at its reranked position or up to `pinned.length` lower, never higher). Pinned rows are shallow copies stamped `relational_pinned: true`; no row is added or removed (re-injecting rows dropped upstream stays `ensureRelationalEvidenceSlot`'s job). Every no-op path (`max <= 0`, empty pool, empty arm, no relational page in the pool) returns the input array itself. `normalizeRelationalRerankPin` is the ONE range contract for the knob (non-negative integer `<= 10` or a string parsing to one → that integer; the literals `off` / `false` (any case) or boolean `false` → 0; anything else → `undefined` = fall through), shared by `mode.ts:loadOverridesFromConfig` and both per-call seams in `hybrid.ts`; `DEFAULT_RELATIONAL_RERANK_PIN` (3) and `RELATIONAL_RERANK_PIN_MAX` (10) are exported. `RelationalRerankPinDecision` (`{max, relational_in_pool, pinned:[{slug, source_id, from_rank, to_rank, fused_rank}], moved}`) is surfaced as `HybridSearchMeta.relational_rerank_pin` for `--explain`. Wired in `hybridSearch` immediately after `applyReranker` and before the alias hop, gated on the reranker having actually reordered (`reranked !== deduped` — `applyReranker` returns its input on every fail-open / skip / pass-through path, and the fused order already carries the arm) and on non-image modality; autocut's `scoreOf` ignores pinned rows and its preserve predicate keeps them, so text-row autocut is byte-identical to the pre-pin behavior. Known cost: a false-positive arm (relational shape parsed AND a real seed resolved, but wrong/stale edges) now puts up to `max` edge pages at ranks 1..max instead of one at `limit`; mitigations are the arm's `fallback_slugify` confidence gate, the tier-2 resolution-margin TODO, config `search.relational_rerank_pin off`, and per-call `SearchOpts.relationalRerankPin`. Pinned by `test/search/relational-rerank-pin.test.ts` (pure contract + tie policy) and `test/search/relational-rerank-pin-hybrid.serial.test.ts` (hermetic PGLite on the relational corpus through the REAL gateway rerank path behind `__setRerankTransportForTests` with an inverted-relevance stub: pin 0 reproduces the regression, pin 3 restores hit@1/hit@3 on all 8 who-invested questions, non-relational queries and reranker-off runs are byte-identical).diff --git a/docs/eval/decisions/p7-heldout-2026-10-05/README.md b/docs/eval/decisions/p7-heldout-2026-10-05/README.mdnew file mode 100644index 0000000000..1901f5347f--- /dev/null+++ b/docs/eval/decisions/p7-heldout-2026-10-05/README.md@@ -0,0 +1,39 @@+# P7 multi-relation query planner: held-out verdict++The custodian (P0) ran the sealed multi-hop set (`multi-hop-paraphrase`, N9 v1)+once on the frozen planner build, under the preregistration in gbrain-evals+(`docs/benchmarks/2026-10-04-p7-multi-hop-planner-preregistration.md`, scored by+`docs/benchmarks/2026-10-04-p7-multi-hop-planner/heldout-verdict.ts`). The+sealed receipts stay with the custodian. Verdict: **pass**, so+`search.relational_planner` defaults on in `balanced` and `tokenmax`.++## Benefit gates++| Gate | Result |+|---|---|+| 1. Sign test, paid paraphrase, cell (a) | 24 questions better, 0 worse, p = 1.2 × 10⁻⁷ |+| 2. Strict all-hit@10 on the five typed families | cell (a) 0 → 27.0%, cell (b, reranker on) 1.1 → 28.1%: +27 points in both |+| 3. Safety | chain answer precision 0.83 (≥ 0.7); edge-evidence correctness 0.85 (≥ 0.8); non-gold pages above the first gold page 3.31 → 0.09; no typed family dropped |+| 4. No hurt | no cell hurts, including the keyless cell |+| 5. One-hop regression (relational-ab) | 0 questions worse |+| 6. False fire | 0 of 500 LongMemEval-S, 0 of 77 BrainBench non-relational, 0 of 50 cat-13 queries |++Custodian notes: N9 v1 has no unanswerable questions, so the abstention part of+gate 3 could not be evaluated; v1 was opened twice, within its three-opening+limit.++## Defaults++- `search.relational_planner`: on in `balanced` and `tokenmax`, off in+ `conservative` (that tier has relational retrieval off).+- `search.relational_orient_onehop`: off in every bundle and available opt-in.+ The orientation ablation was 1 question better and 0 worse on relational-ab+ (p = 1.0), short of the improvement its default rule requires.++## Known gap++The planner planned 70% of the plainly worded (template) questions and 21% of+the reworded (paraphrase) ones. The surface-form vocabulary is the limit, the+same brittleness the one-hop relational parser showed in its own held-out run.+Widening coverage of reworded questions without giving up precision is the+follow-up.diff --git a/docs/guides/multi-hop.md b/docs/guides/multi-hop.mdindex 9a3615c4b5..f4c54e9cc3 100644--- a/docs/guides/multi-hop.md+++ b/docs/guides/multi-hop.md@@ -12,9 +12,9 @@ companies backed by Fund A?"*## Two ways in-**Ask in plain English (search, query, recall, think).** With-`search.relational_planner` on, a question that chains 2-3 relationships is-planned into typed hops and the answers join the normal search results. Each+**Ask in plain English (search, query, recall, think).** In the `balanced`+and `tokenmax` modes (`search.relational_planner`, on by default there), a+question that chains 2-3 relationships is planned into typed hops and the answers join the normal search results. Eachchain row carries a `relational` field:```json@@ -67,7 +67,6 @@ gbrain init --pglite --no-embeddingprintf -- '---\ntype: person\ntitle: Bob Example\n---\nBob Example is a robotics engineer.\n' | gbrain put people/bob-exampleprintf -- '---\ntype: company\ntitle: Acme Example\n---\nAcme Example makes robots. It was founded by [Bob Example](people/bob-example).\n' | gbrain put companies/acme-exampleprintf -- '---\ntype: person\ntitle: Alice Example\n---\nAlice Example is a seed investor. She backed [Acme Example](companies/acme-example) in 2024.\n' | gbrain put people/alice-example-gbrain config set search.relational_planner truegbrain graph-query people/alice-example --hop invested_in:object --hop founded:subjectgbrain search "Who founded the companies that Alice Example invested in?" --json```@@ -100,6 +99,11 @@ the hops run outward from it. Questions it does not plan, and says so in a- two named entities, quoted names, or relationships whose page types do notchain.+The vocabulary is fixed, so many rewordings are not planned: on the held-out+multi-hop set the planner planned 70% of plainly worded questions and 21% of+reworded ones. A chain question that comes back without `meta.relational_plan`+was not planned; call `traverse_graph` with explicit `hops` instead.+Single-relationship questions ("who invested in Acme?") keep the one-hoprelational arm. Split an unplanned question into one-relationship questions,or pass explicit `hops`.@@ -140,8 +144,8 @@ company → company or deal), and a chain reads a link by that signature:`uncertain` when both fit (company ↔ company investment links, walked aswritten at half weight) and not at all when neither fits. Frontmatter,manual and attendance-section links keep their stored direction.-`search.relational_orient_onehop` applies the same reading to-single-relationship questions; unset, it follows `search.relational_planner`.+`search.relational_orient_onehop` (off by default) applies the same reading to+single-relationship questions.Every page and edge in a chain passes the caller's read scope before anythingis ranked: private, deleted, quarantined and out-of-scope pages never appear@@ -153,8 +157,8 @@ sanitized excerpt of at most 160 characters.| Key | Effect ||---|---|-| `search.relational_planner` | Plan 2-3 relationship questions into typed chains (search, query, recall, think) |-| `search.relational_orient_onehop` | Single-relationship walks read links written on either page (unset = follows the planner) |+| `search.relational_planner` | Plan 2-3 relationship questions into typed chains (search, query, recall, think). On in `balanced` and `tokenmax`, off in `conservative`; `gbrain config set search.relational_planner false` turns it off |+| `search.relational_orient_onehop` | Single-relationship walks read links written on either page. Off by default; unset follows the planner || `search.relational_chain_slots` | When a chain fires, up to this many chain rows (answers, then the pages on their paths) lead page 1; 0..10, default 10, 0 keeps a single evidence slot |Each chain hop expands at most 50 pages, 100 links per page and 10 paths perdiff --git a/src/core/search/mode.ts b/src/core/search/mode.tsindex 899cfa8ed5..3f326e6187 100644--- a/src/core/search/mode.ts+++ b/src/core/search/mode.ts@@ -368,7 +368,7 @@ export interface ModeBundle {relational_planner: boolean;/*** Typed one-hop walks read edges stored from either page's side by the- * relation's type signature. `null` follows `relational_planner`. Override:+ * relation's type signature (opt-in; `null` follows `relational_planner`). Override:* per-call SearchOpts.relationalOrientOneHop → `search.relational_orient_onehop`.*/relational_orient_onehop: boolean | null;@@ -479,9 +479,9 @@ export const MODE_BUNDLES: Readonly<Record<SearchMode, Readonly<ModeBundle>>> =relational_retrieval_depth: 2,// Ranker wave (R1) — relational rows re-pinned above reranked text rows (0 = off).relational_rerank_pin: DEFAULT_RELATIONAL_RERANK_PIN,- // Multi-hop planner: default set by its held-out eval (off until then).+ // Multi-hop planner: relational retrieval is off in this tier, so the planner is too.relational_planner: false,- relational_orient_onehop: null,+ relational_orient_onehop: false,relational_chain_slots: 10,autocut_jump: 0.2,autocut_min_top: 0.35,@@ -545,9 +545,9 @@ export const MODE_BUNDLES: Readonly<Record<SearchMode, Readonly<ModeBundle>>> =relational_retrieval_depth: 2,// Ranker wave (R1) — relational rows re-pinned above reranked text rows (0 = off).relational_rerank_pin: DEFAULT_RELATIONAL_RERANK_PIN,- // Multi-hop planner: default set by its held-out eval (off until then).- relational_planner: false,- relational_orient_onehop: null,+ // Multi-hop planner ON, one-hop orientation opt-in: docs/eval/decisions/p7-heldout-2026-10-05.+ relational_planner: true,+ relational_orient_onehop: false,relational_chain_slots: 10,autocut_jump: 0.2,autocut_min_top: 0.35,@@ -611,9 +611,9 @@ export const MODE_BUNDLES: Readonly<Record<SearchMode, Readonly<ModeBundle>>> =relational_retrieval_depth: 2,// Ranker wave (R1) — relational rows re-pinned above reranked text rows (0 = off).relational_rerank_pin: DEFAULT_RELATIONAL_RERANK_PIN,- // Multi-hop planner: default set by its held-out eval (off until then).- relational_planner: false,- relational_orient_onehop: null,+ // Multi-hop planner ON, one-hop orientation opt-in: docs/eval/decisions/p7-heldout-2026-10-05.+ relational_planner: true,+ relational_orient_onehop: false,relational_chain_slots: 10,autocut_jump: 0.2,autocut_min_top: 0.35,diff --git a/src/core/search/modes-report.ts b/src/core/search/modes-report.tsindex d9a90e57cd..bb7ebbfa2e 100644--- a/src/core/search/modes-report.ts+++ b/src/core/search/modes-report.ts@@ -61,7 +61,7 @@ export const KNOB_DESCRIPTIONS: Record<keyof ModeBundle, string> = {relational_retrieval_depth: 'Max hops for relational traversal (1..3, 2 default)',relational_rerank_pin: 'Relational-arm rows re-pinned above reranked text rows in fused order (0 = off; 0..10, 3 default)',relational_planner: 'Multi-hop planner: questions chaining 2-3 typed relations walk typed hop chains with evidence (also keyless recall)',- relational_orient_onehop: 'Typed one-hop walks read edges written on either page by the relation type signature (null = follow relational_planner)',+ relational_orient_onehop: 'Typed one-hop walks read edges written on either page by the relation type signature (opt-in; null = follow relational_planner)',relational_chain_slots: 'When a multi-hop chain fired, up to this many chain rows (answers, then evidence pages) lead page 1 (0..10; 0 = single evidence slot)',// Ranker wave (Phase E2) arm-confidence fusionkeyword_arm_confidence_floor: 'Keyword-arm confidence floor: below this margin ratio the keyword + title lists fuse at half weight (null = off; (0, 1])',diff --git a/test/search-mode.test.ts b/test/search-mode.test.tsindex a92019c0e5..63fed5035f 100644--- a/test/search-mode.test.ts+++ b/test/search-mode.test.ts@@ -89,7 +89,7 @@ describe('SEARCH_MODES + MODE_BUNDLES canonical shape', () => {// ranker wave (R1) — relational rerank pin, 3 in every bundle (0 = off).relational_rerank_pin: 3,relational_planner: false,- relational_orient_onehop: null,+ relational_orient_onehop: false,relational_chain_slots: 10,// ranker wave (Phase E2) — keyword-arm confidence floor OFF in every bundle until the Cat 13 receipt.keyword_arm_confidence_floor: null,@@ -134,8 +134,8 @@ describe('SEARCH_MODES + MODE_BUNDLES canonical shape', () => {relational_retrieval_depth: 2,// ranker wave (R1) — relational rerank pin, 3 in every bundle (0 = off).relational_rerank_pin: 3,- relational_planner: false,- relational_orient_onehop: null,+ relational_planner: true,+ relational_orient_onehop: false,relational_chain_slots: 10,// ranker wave (Phase E2) — keyword-arm confidence floor OFF in every bundle until the Cat 13 receipt.keyword_arm_confidence_floor: null,@@ -178,8 +178,8 @@ describe('SEARCH_MODES + MODE_BUNDLES canonical shape', () => {relational_retrieval_depth: 2,// ranker wave (R1) — relational rerank pin, 3 in every bundle (0 = off).relational_rerank_pin: 3,- relational_planner: false,- relational_orient_onehop: null,+ relational_planner: true,+ relational_orient_onehop: false,relational_chain_slots: 10,// ranker wave (Phase E2) — keyword-arm confidence floor OFF in every bundle until the Cat 13 receipt.keyword_arm_confidence_floor: null,@@ -1107,11 +1107,10 @@ describe('ranker wave (R1) — relational_rerank_pin knob (relational rows bypas});describe('multi-hop planner knobs (relational_planner, relational_orient_onehop)', () => {- test('bundles ship the planner off and orientation following it', () => {- for (const m of ['conservative', 'balanced', 'tokenmax'] as const) {- expect(MODE_BUNDLES[m].relational_planner).toBe(false);- expect(MODE_BUNDLES[m].relational_orient_onehop).toBeNull();- }+ test('balanced and tokenmax ship the planner on (held-out verdict); conservative off; one-hop orientation opt-in everywhere', () => {+ expect(MODE_BUNDLES.conservative.relational_planner).toBe(false);+ for (const m of ['balanced', 'tokenmax'] as const) expect(MODE_BUNDLES[m].relational_planner).toBe(true);+ for (const m of ['conservative', 'balanced', 'tokenmax'] as const) expect(MODE_BUNDLES[m].relational_orient_onehop).toBe(false);});test('config booleans parse; garbage falls through', () => {@@ -1123,14 +1122,15 @@ describe('multi-hop planner knobs (relational_planner, relational_orient_onehop)expect(loadOverridesFromConfig({ 'search.relational_chain_slots': '11' }).relational_chain_slots).toBeUndefined();});- test('knobsHash: planner off (default or explicit) hashes like the pre-planner build; on, orientation and slots fold in', () => {+ test('knobsHash: planner off ignores chain slots; on folds slots and orientation in', () => {const dflt = knobsHash(resolveSearchMode({ mode: 'balanced' }));- const off = knobsHash(resolveSearchMode({ mode: 'balanced', overrides: { relational_planner: false, relational_chain_slots: 3 } }));- const on = knobsHash(resolveSearchMode({ mode: 'balanced', overrides: { relational_planner: true } }));- const onSlots = knobsHash(resolveSearchMode({ mode: 'balanced', overrides: { relational_planner: true }, perCall: { relational_chain_slots: 0 } }));- const onNoOrient = knobsHash(resolveSearchMode({ mode: 'balanced', overrides: { relational_planner: true, relational_orient_onehop: false } }));- const orientOnly = knobsHash(resolveSearchMode({ mode: 'balanced', overrides: { relational_orient_onehop: true } }));- expect(off).toBe(dflt);- expect(new Set([dflt, on, onSlots, onNoOrient, orientOnly]).size).toBe(5);+ const explicitOn = knobsHash(resolveSearchMode({ mode: 'balanced', overrides: { relational_planner: true, relational_orient_onehop: false } }));+ const off = knobsHash(resolveSearchMode({ mode: 'balanced', overrides: { relational_planner: false } }));+ const offSlots = knobsHash(resolveSearchMode({ mode: 'balanced', overrides: { relational_planner: false, relational_chain_slots: 3 } }));+ const onSlots = knobsHash(resolveSearchMode({ mode: 'balanced', perCall: { relational_chain_slots: 0 } }));+ const orient = knobsHash(resolveSearchMode({ mode: 'balanced', overrides: { relational_orient_onehop: true } }));+ expect(explicitOn).toBe(dflt);+ expect(offSlots).toBe(off);+ expect(new Set([dflt, off, onSlots, orient]).size).toBe(4);});});