Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
docs: diverse-pool KEY_FILES entry carries the BEAM-1M S1 retrieval result (ships off)
garrytan755839596b20
diff --git a/docs/architecture/key-files/core-search-1.md b/docs/architecture/key-files/core-search-1.mdindex 9fea0d2511..f07ca44ab2 100644--- a/docs/architecture/key-files/core-search-1.md+++ b/docs/architecture/key-files/core-search-1.md@@ -19,7 +19,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL- `src/core/search/date-labels.ts` — row-date honesty for `search` / `query`. `effectiveDateLabel(source)` maps `effective_date_source` to a document date (`date`, `published`, `filename`), an event date (`event_date`) or a fallback (`created`, `fallback`: when the page was created or imported); `dateLabelLine(rows)` is the one model-visible `[gbrain dates]` line `src/mcp/dispatch.ts` appends when rows carry dates, naming only the sources present and saying the date is never a contract's effective or validity date. Lean rows (`lean-rows.ts`) keep `effective_date_source` for it. Test: `test/search-date-labels.test.ts`.- `src/core/search/dedup.ts` — 4-layer result dedup + compiled-truth guarantee: (1) top 3 chunks per page by score, (2) drop chunks >0.85 Jaccard-similar to already-kept chunks of the SAME page (cross-page near-dups survive — two legitimately similar pages both return), (3) no page type exceeds 60% of results — applied only when the candidate set actually contains multiple page types; a homogeneous set passes through unchanged because dropping (for example) one of three distinct LongMemEval `note` sessions cannot introduce diversity and destroys multi-session recall (pinned by the homogeneous-set case in `test/dedup.test.ts`), (4) max 2 chunks per page (default; the two-pass structural expansion in `hybrid.ts` widens it), (5) ensure at least 1 compiled_truth chunk per page — the page's best compiled_truth chunk is APPENDED (never swapped over a kept chunk, so matching evidence survives) and the final output is re-sorted by score, because slice / token budget / evidence consumers assume score order. Page identity is the composite `pageKey()` (source_id, slug) — the one canonical key helper every layer uses, so slug collisions across sources can't collapse recall.-- `src/core/search/diverse-pool.ts` — the session-diverse candidate pool before the reranker, `search.diverse_pool_depth` (integer 0..100, `off` = 0; 0 in every bundle, so off by default). With N > 0: every retrieval arm fetches at least N candidates (`hybrid/request.ts` passes `max(PRE_FUSION_POOL_FLOOR, N)` as the `perArmPoolLimit` floor; still capped at `MAX_SEARCH_LIMIT` unless an eval pool depth is set), `capPerSession` keeps the first row of each session in the deduped pool (`hybrid/rank.ts` `capSessionPool`, called on `dedupResults`' output; a session is `sessionPrefix(slug)` from `graph-signals.ts`, else the page, keyed with the source id) and `rerankAndPin` raises the reranker's `topNIn` to at least N. The keyword-only paths have no reranker and are unchanged. `normalizeDiversePoolDepth` is the one range contract (mode.ts config parse and the `gbrain config set` refusal through `search/config-values.ts`); the mode field folds into `knobsHash` as an append-only `dpd=` part only when on. Motivation and measurement: BEAM-1M S1 in gbrain-evals (`docs/benchmarks/2026-10-12-beam-1m-s1-fixes.md`). Tests: `test/search/diverse-pool.test.ts`, `test/search/diverse-pool-hybrid.serial.test.ts`.+- `src/core/search/diverse-pool.ts` — the session-diverse candidate pool before the reranker, `search.diverse_pool_depth` (integer 0..100, `off` = 0; 0 in every bundle, so off by default). With N > 0: every retrieval arm fetches at least N candidates (`hybrid/request.ts` passes `max(PRE_FUSION_POOL_FLOOR, N)` as the `perArmPoolLimit` floor; still capped at `MAX_SEARCH_LIMIT` unless an eval pool depth is set), `capPerSession` keeps the first row of each session in the deduped pool (`hybrid/rank.ts` `capSessionPool`, called on `dedupResults`' output; a session is `sessionPrefix(slug)` from `graph-signals.ts`, else the page, keyed with the source id) and `rerankAndPin` raises the reranker's `topNIn` to at least N. The keyword-only paths have no reranker and are unchanged. `normalizeDiversePoolDepth` is the one range contract (mode.ts config parse and the `gbrain config set` refusal through `search/config-values.ts`); the mode field folds into `knobsHash` as an append-only `dpd=` part only when on. Motivation and measurement: BEAM-1M S1 in gbrain-evals (`docs/benchmarks/2026-10-12-beam-1m-s1-fixes.md`): at depth 100 on BEAM-1M dev (voyage-4, balanced reranker) strict recall at 10 rose 76 → 83 of 198 (+3.5 points, 95% interval [0, +6.6]) and at 5 was flat (55 → 56), with search p50 latency 340 → 455 ms and about 4x the rerank tokens per query; the preregistered flip rule needed an interval above zero, so every bundle keeps 0. Tests: `test/search/diverse-pool.test.ts`, `test/search/diverse-pool-hybrid.serial.test.ts`.- `src/core/search/embedding-column.ts` — single source of truth for "which `content_chunks.*` column does this query rank against?" Pure functions, no engine I/O: `loadRegistry(cfg)` walks the `embedding_columns` config (DB plane, JSON map keyed by column name with `{provider, dimensions, type}` entries), seeds the OpenAI `embedding` builtin when unset, validates everything before it lands (column-name regex, type ∈ `vector | halfvec`, dims in [1, 8192], provider format) using `Object.create(null)` + `Object.hasOwn` so a key like `constructor` rejects instead of resolving to `Object.prototype.constructor`. `resolveColumn(registry, override?, cfg)` is the boundary call: returns a frozen `ResolvedColumn` descriptor (`{name, provider, dimensions, type}`) honoring per-call override → `search_embedding_column` config → `'embedding'` default; throws `UnknownEmbeddingColumnError` with the list of registered names on miss. `isCacheSafe(resolved, cfg)` compares the full embedding SPACE (provider + dimensions + name) against cfg's default so a repointed `embedding` builtin doesn't serve OpenAI-shaped cache rows. `validateResolvedColumn(descriptor)` re-validates hand-rolled descriptors that bypass the registry (internal-SDK passthrough) so the SQL-injection escape hatch through the descriptor field is closed. Consumed by `hybridSearch`, `gateway.embedQuery(text, {embeddingModel, dimensions})`, `cosineReScore`, and the `query` MCP op (per-call `embedding_column` param). Engine column routing is covered by `test/e2e/embedding-column-pglite.test.ts`, `test/e2e/embedding-column-postgres.test.ts` and `test/cosine-rescore-column.test.ts`. Write side: `resolveWriteColumnFromConfigRows({searchEmbeddingColumn, embeddingColumnsJson})` resolves upsertChunks's active write target from the raw DB-plane config rows through the same registry/validation chain (legacy `embedding` descriptor when neither row routes elsewhere; `embedding_image` falls back to the legacy text column since image vectors travel in their own INSERT column; malformed registry JSON is forgiven like loadConfigWithEngine; unregistered names throw the paste-ready error), and `vectorCastSuffix(resolved)` is the placeholder-free `'::vector' | '::halfvec(N)'` cast shared by the read fragment builder and the write path so the two casts can't drift. Pinned by `test/e2e/upsert-chunks-registry-column.test.ts`.