Skip to content

memory-core: CJK LIKE fallback returns wrong results for multi-character queries #92728

Description

@rrriiiccckkk

Summary

The LIKE fallback in searchKeyword returns results from unrelated files when querying with multi-character CJK strings (e.g. "飞书插件配置"). The LIKE query uses the full token as a single substring pattern, which matches files that discuss the search issue itself rather than files with relevant content.

Environment

  • OpenClaw version: 2026.6.5
  • FTS tokenizer: trigram
  • Embedding provider: Ollama (qwen3-embedding:4b)

Root Cause

In planKeywordSearch, CJK tokens are routed to substringTerms as-is:

if (SHORT_CJK_TRIGRAM_RE.test(token)) {
    substringTerms.push(token);  // "飞书插件配置" pushed as one term
    continue;
}

This generates: WHERE text LIKE '%飞书插件配置%'

Problem: The exact substring "飞书插件配置" rarely appears in actual content. The relevant text is "飞书配置", "飞书插件", "插件配置" etc. spread across different positions. The LIKE query only matches files that literally contain the exact phrase — typically files that discuss the CJK search issue itself (e.g. memory/2026-06-12-cjk-pr-draft.md).

Reproduction

  1. Configure agents.defaults.memorySearch.store.fts.tokenizer: "trigram"
  2. Index memory files containing Chinese text about 飞书配置
  3. Run memory_search with query "飞书插件配置"
  4. Observe: keyword results come from memory/2026-06-12-cjk-*.md (issue discussion files), not from files with actual 飞书配置 content

Expected Behavior

The LIKE fallback should find results from files that contain the query terms, not just files that contain the exact phrase. Possible approaches:

  1. Trigram-style splitting: Split CJK tokens into overlapping 2-3 character substrings (e.g. "飞书插", "书插件", "插件配", "件配置") and use OR matching
  2. Character-level AND: Split into individual characters with AND matching (e.g. LIKE '%飞%' AND LIKE '%书%' AND LIKE '%插%' AND ...*) — tested but too broad
  3. Bigram AND: Split into character pairs with AND matching (e.g. LIKE '%飞书%' AND LIKE '%书插%' AND LIKE '%插件%' AND ...) — likely best balance

Impact

  • Affected: All CJK memory searches with multi-character queries
  • Severity: Medium (keyword results are included but from wrong files, ranked low)
  • Frequency: Always for multi-character CJK queries
  • Consequence: Keyword search doesn't boost relevance for CJK queries

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper 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:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, 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.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions