Skip to content

docs(CC-548): FTS5 trigram-tokenizer spike — AMBER, defer - #538

Merged
screenleon merged 1 commit into
mainfrom
docs/CC-548-fts5-trigram-spike
Aug 26, 2026
Merged

docs(CC-548): FTS5 trigram-tokenizer spike — AMBER, defer#538
screenleon merged 1 commit into
mainfrom
docs/CC-548-fts5-trigram-spike

Conversation

@screenleon

Copy link
Copy Markdown
Owner

Summary

CC-548 was explicitly a spike ("不預設要做——先 spike,再決定"): decide whether switching context.db's FTS5 tokenizer from unicode61 to trigram is worth implementing for CJK query quality. This PR is the spike result, not an implementation.

Verdict: AMBER — defer, do not implement now.

All three measurements were made on the real repo corpus (64MB context.db), not estimated:

  • Version floor: sqlite ≥3.34.0 needed; no conflict with docs/platform-support.md (pins no sqlite minimum). A three-tier degraded path would be cheap to add on the existing _ctx_fts5_available() idiom.
  • Rebuild cost: migration machinery is zero-cost (rebuild is already an unconditional full DROP+recreate), but measured rebuild is ~4.9x slower (0.87s → 4.24s) and the index grows +32.6%.
  • Quality delta: real but narrow — unicode61 tokenizes contiguous CJK text into large indivisible runs, silently missing a query term that's a true substring of a longer run. Only 1 extra hit out of ~68 sampled on this repo's actual (punctuation-delimited) corpus. The ticket's original "unicode61 has no ranking" premise did not hold under measurement — bm25() ranks non-degenerately today.

No implementation slice opened, per the ticket's own instruction that a verdict color isn't an automatic green light.

Also surfaced, not fixed or ticketed (documented in the spike's Open risks): _ctx_fts_rebuild() wraps nothing in BEGIN/COMMIT, so a concurrent query can observe a window where content_fts doesn't exist or is half-populated. Pre-existing, unrelated to this ticket's tokenizer question — flagged for visibility, not scope-crept into a fix here.

Verification

  • bash pm/scripts/validate.sh BACKLOG.md — exit 0
  • tests/shell/test-pmctl-backlog.sh — 18 passed, 0 failed
  • Docs-only; no code changed.

🤖 Generated with Claude Code

https://claude.ai/code/session_0177ds9nxEMtsh3bwpBxNHYx

Per the ticket's own instruction ("不預設要做——先 spike,再決定"), investigated
whether switching context.db's FTS5 tokenizer from unicode61 to trigram is
worth implementing for CJK query quality. Three angles, all measured on the
real repo corpus rather than estimated:

- sqlite version floor (3.34.0) has no conflict with docs/platform-support.md
  (which pins no sqlite minimum); a three-tier degraded path (trigram ->
  unicode61 -> LIKE) would be structurally trivial on top of the existing
  _ctx_fts5_available() probe/cache idiom.
- Rebuild migration cost is zero (the rebuild path is already an
  unconditional full DROP+recreate), but rebuild is measurably ~4.9x slower
  (0.87s -> 4.24s on this repo's 64MB corpus) and the index grows +32.6%.
- CJK query quality delta is real but narrow: unicode61 tokenizes contiguous
  CJK text into large indivisible multi-character runs, silently missing a
  query term that's a true substring of a longer run -- but this only
  produced 1 extra hit out of ~68 sampled on this repo's actual
  punctuation-delimited corpus. The ticket's original "unicode61 has no
  ranking" premise did not hold under measurement -- bm25() ranks
  non-degenerately today; the real defect is narrower than assumed.

Verdict: AMBER, defer -- benefit is real but small on this corpus today,
cost is real and non-trivial, neither side is a hard blocker. No
implementation slice opened.

Also surfaced (not fixed, not ticketed -- flagged in the spike's Open
risks): _ctx_fts_rebuild() wraps nothing in BEGIN/COMMIT, so a concurrent
query can already observe a window where content_fts doesn't exist or is
half-populated. Pre-existing, unrelated to this ticket's tokenizer question.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0177ds9nxEMtsh3bwpBxNHYx
@screenleon
screenleon merged commit b529541 into main Aug 26, 2026
64 checks passed
@screenleon
screenleon deleted the docs/CC-548-fts5-trigram-spike branch August 27, 2026 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant