-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
memory-core: CJK text FTS5 search returns textScore=0 with trigram tokenizer #92061
Copy link
Copy link
Closed
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.ClawSweeper found an open linked pull request for this issue.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.clownfishTracked by Clownfish automationTracked by Clownfish automationimpact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Description
Metadata
Metadata
Assignees
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.ClawSweeper found an open linked pull request for this issue.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.clownfishTracked by Clownfish automationTracked by Clownfish automationimpact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Type
Fields
Priority
None yet
Summary
When using
memory-corewith thetrigramFTS5 tokenizer, Chinese (CJK) text queries always returntextScore: 0in hybrid search results. The vector component works correctly, but the BM25/full-text component contributes nothing to the final score for CJK queries.English queries work fine with both
unicode61andtrigramtokenizers.Environment
agents.defaults.memorySearch.store.fts.tokenizer: "trigram"Root Cause Analysis
Two bugs in
extensions/memory-core(manager-*.js→searchKeyword/planKeywordSearch):Bug 1: CJK tokens not split for trigram matching
In
planKeywordSearch, the regex/[\p{L}\p{N}_]+/gutreats consecutive CJK characters as a single token (e.g., "飞书插件配置" → 1 token of 6 chars). The code then checks:Since 6 >= 3, the entire CJK string goes to
matchTermsand becomesMATCH "飞书插件配置"(quoted phrase). But this exact substring rarely exists in documents, so MATCH returns 0 results.Fix: Split CJK tokens into individual characters for LIKE matching:
Bug 2: No LIKE fallback on empty MATCH results
The LIKE fallback only triggers when MATCH throws an exception, not when it returns 0 rows:
If
MATCH "飞书插件配置"returns empty without throwing, the LIKE path never runs, and all keyword results are empty → textScore=0 for all hybrid results.Fix: Add LIKE fallback when MATCH returns empty:
Reproduction
agents.defaults.memorySearch.store.fts.tokenizer: "trigram"memory_searchwith a Chinese querytextScore: 0for all results, despite vector search returning correct matchesWorkaround
Vector search still works for CJK text (vectorScore is correct). The textScore=0 reduces the final hybrid score but doesn't break recall entirely. Setting
textWeight: 0in query config would eliminate the misleading BM25 component.Suggested Fix
Both bugs are in the
searchKeyword/planKeywordSearchfunctions. The CJK token splitting and MATCH-empty-to-LIKE fallback should be added upstream.Additional Note
The
trigramtokenizer has an inherent limitation: it requires at least 3 characters to create a searchable token. Single/double CJK characters (e.g., "飞", "配置") cannot be matched via FTS5 MATCH at all, only via LIKE. The code already partially handles this (the< 3check), but the threshold logic is incorrect for multi-character CJK strings.