fix(state): honour HERMES_DISABLE_FTS_TRIGRAM to skip CJK index - #42190
fix(state): honour HERMES_DISABLE_FTS_TRIGRAM to skip CJK index#42190bilawalriaz wants to merge 1 commit into
Conversation
The CJK trigram FTS5 index is currently created unconditionally when FTS5 is available, and on large histories it accounts for the majority of state.db size (~70% per #22478). The docstring on optimize_fts already referenced an env-var opt-out, but no code path checked it. Introduce _trigram_fts_disabled() reading HERMES_DISABLE_FTS_TRIGRAM (accepts 1/true/yes/on, case-insensitive). Gate the v10 / v11 schema migrations, the normal-startup schema creation, _rebuild_fts_indexes, and _fts_trigger_count on the helper. Split _FTS_TRIGGERS into the porter and trigram halves so _drop_fts_triggers still cleans up stale trigram triggers for users who flip the var back on. search_messages() now falls through to the LIKE-based CJK path when the trigram table is absent, so non-CJK and short-CJK queries still work after disabling the index. Fixes #22478
|
Thanks for tackling the documented state.db bloat; the reports in #22478 substantiate the storage cost of the trigram index. This automated hermes-sweeper review is closing the PR under the standing configuration policy:
Please feel free to re-scope the opt-out as a Closed as not-planned per standing maintainer policy ( Closed as not-planned per standing maintainer policy ( |
What & why
Closes #22478.
The CJK trigram FTS5 index is currently created unconditionally when FTS5 is available. On large histories it accounts for the majority of
state.dbsize — the user-reported numbers in #22478 showmessages_fts_trigramalone at 247 MB (49% of a 505 MB DB), and the trigram index is 2.2× larger than the porter-stemmer index that indexes the same data.The docstring on
optimize_fts()already promised anHERMES_DISABLE_FTS_TRIGRAMopt-out, but no code path actually read the variable — it was dead documentation. This PR wires the gate up everywhere it matters.Changes
_trigram_fts_disabled()helper readingHERMES_DISABLE_FTS_TRIGRAM(accepts1/true/yes/on, case-insensitive, whitespace-trimmed)._FTS_TRIGGERSinto_PORTER_FTS_TRIGGERSand_TRIGRAM_FTS_TRIGGERS._drop_fts_triggersstill iterates the full union so a user who flips the var back on doesn't leave stale triggers on disk._rebuild_fts_indexes, and_fts_trigger_counton the helper.search_messages()now falls through to the LIKE-based CJK path when the trigram table is absent, so English / short-CJK / mixed queries still work after disabling the index.TestTrigramFtsDisabledclass with 7 tests covering: env-var truthy parsing, default behaviour, table non-creation, trigger non-creation, English search still functional, andoptimize_fts()returning 1 (porter only) instead of 2.How to test
To verify end-to-end space reclamation on a real DB:
Platforms tested
Notes
tests/agent/test_auxiliary_client.py(8 tests) is unrelated and reproduces onmainbefore this branch.import osadded tohermes_state.py.