Skip to content

fix(vfs-store): segment CJK/mixed queries and relax short-term recall drop - #254

Open
humandebri wants to merge 3 commits into
mainfrom
fix/vfs-store-multilingual-fts-recall
Open

humandebri wants to merge 3 commits into
mainfrom
fix/vfs-store-multilingual-fts-recall

Conversation

@humandebri

Copy link
Copy Markdown
Collaborator

Summary

Fixes the root causes in crates/vfs_store/src/fs_search.rs that caused unspaced CJK and mixed-language natural-language queries to return zero or irrelevant hits on the first search/context call:

  1. Unicode script-boundary segmentation (segment_cjk_query_token):

    • Previously, build_search_query_plan only split on whitespace, turning unspaced CJK/mixed clauses (e.g. "Hono リクエストJSONをZodスキーマで検証する" or "今年副業で35万円くらい稼いだんだけど確定申告いる?") into a single unmatchable FTS5 phrase.
    • Now segments CJK/mixed tokens along Unicode script boundaries (AsciiWord, Han, Katakana including ー while trimming leading ー, Hangul, Hiragana), dropping hiragana particle/conjugation noise when >=3-char content terms exist while preserving standalone hiragana roots (e.g. "ふるさと納税"), and capping FTS terms at 16.
    • Pure ASCII tokens and single-script CJK tokens ("検索改善", "長期記憶 検索精度", "shared-bench-search") keep exact parity.
  2. Per-term CJK content-substring matching & Hangul support:

    • Previously, load_content_substring_candidates searched for literal instr(content, raw_query) on CJK queries, failing on multi-term 2-char CJK queries ("家賃 退去") or punctuation-suffixed queries ("設計?").
    • Now matches segmented content_terms individually (capped at 12) with AND first, and falls back to OR across >=2-char terms when exact_fts is None and AND yields zero rows. Also includes Hangul in contains_cjk so 2-char Korean terms ("유출") work via content_substring, and adds content_terms as fallback anchors for Light previews.
  3. Preserve FTS recall when strict short-term filtering empties all candidates:

    • In filter_candidates_on_short_terms, strict all-short-term matches are still preferred (preserving "AI agents" and "AI ML" precision). When strict is empty and multi-term FTS recall (recall_fts) is active (e.g. "Hono 日本語 CORS origin 許可" or query_context with natural-language task + entities), retain the FTS recall candidates instead of dropping everything to 0.

Frozen Corpus Impact (tests/fs_search_corpus.rs)

  • English hit@20: 34 -> 34 (0 regressions)
  • Japanese / mixed queries (6 labeled positives): 1/6 -> 5/6 hit@20:
    • dev-japanese-mixed (Hono 日本語 CORS origin 許可): None (0 hits) -> rank 1
    • holdout-basic (Hono ユーザー名とパスワードでBasic認証をかけたい): None -> rank 4
    • holdout-upload (Hono parseBody 同名ファイルを複数受け取る): rank 4 -> rank 4
    • holdout-pretty (Hono JSONレスポンスを見やすく整形したい): None -> rank 9
    • holdout-dom-stable (Motoko アップグレード時のstable memoryへのシリアライズを不要にする仕組み): None -> rank 1
    • holdout-zod (unlabeled): top 5 are now all with-zod / zod-validator-middleware docs

Verification

  • cargo fmt -p vfs-store -- --check: clean
  • cargo clippy -p vfs-store --tests -- -D warnings: clean
  • cargo test -p vfs-store: all unit, integration, corpus, and proptests pass (including new tests in fs_search.rs and fs_store_search.rs)

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