Skip to content

fix: exclude tool messages from FTS indexes to prevent trigram bloat - #35826

Closed
503496348-ops wants to merge 1 commit into
NousResearch:mainfrom
503496348-ops:fix/fts-trigram-bloat
Closed

fix: exclude tool messages from FTS indexes to prevent trigram bloat#35826
503496348-ops wants to merge 1 commit into
NousResearch:mainfrom
503496348-ops:fix/fts-trigram-bloat

Conversation

@503496348-ops

Copy link
Copy Markdown

Problem

FTS triggers index ALL messages including role='tool' (JSON execution output). Tool messages are 72% of indexed content but rarely useful for search. Trigram tokenizer amplifies to 3-5x source size.

Impact: cto-bot state.db 650MB (425MB FTS) -> 310MB after fix.

Fix

  • WHEN new.role != 'tool' on INSERT/UPDATE triggers
  • Index only content (not tool_name + tool_calls)

Storage Impact

Metric Before After
Indexed 123.6 MB 14.6 MB (-88%)
FTS 717 MB ~60 MB (-92%)

Tool messages (role='tool') are 72% of indexed content but
useless for search. Add WHEN new.role != 'tool' to triggers.
Reduces FTS index by ~80%.
@alt-glitch alt-glitch added type/perf Performance improvement or optimization P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint tool/memory Memory tool and memory providers labels May 31, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for targeting a real FTS storage cost. This needs rework before the proposed behavior can be evaluated safely.

Problems

  • Existing databases would retain the old triggers: FTS setup uses CREATE ... IF NOT EXISTS (hermes_state.py:1157-1171), and the existing v11 migration explicitly drops/recreates FTS objects because those statements do not replace existing triggers (hermes_state.py:1499-1550). This PR adds no equivalent migration or backfill.
  • Replacing the indexed expression with content alone removes current tool-metadata search behavior. tests/test_hermes_state.py:4627-4663 requires tool_name and serialized tool_calls to be FTS-searchable, while tests/tools/test_session_search.py:290-296 covers an explicit role_filter='tool' search.

Suggested changes

  • Preserve the current assistant tool-call metadata contract, or propose and test a replacement search surface.
  • If tool-result exclusion is intended, add a versioned migration that rebuilds both FTS indexes and tests populated upgrades plus fresh databases.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-broad Sweeper blast radius: broad — a core path most sessions hit labels Jul 13, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Closing with credit — tool-row exclusion from the FTS indexes shipped on main in PR #65798 (schema v23). You were the earliest submitter on this idea (May 31) and the diagnosis was exactly right: tool output dominates indexed bytes and the trigram tokenizer amplifies it.

The merged design differs in one respect: tool rows are excluded from the trigram index only, while the standard FTS index keeps them — tool-output search (role_filter=['tool']) is a supported session_search path (#16751), so dropping tool rows from both indexes would have broken it. Combined with the external-content layout, the result on a real 25 GB production DB was −60%.

Thanks @503496348-ops for flagging this early with real numbers (650 MB → 310 MB).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists sweeper:blast-broad Sweeper blast radius: broad — a core path most sessions hit sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades tool/memory Memory tool and memory providers type/perf Performance improvement or optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants