Skip to content

fix(wiki-mcp): preserve katakana prolonged mark and add multilingual zero-hit fallback - #253

Merged
humandebri merged 3 commits into
mainfrom
fix/hub-router-katakana-and-multilingual-fallback
Dec 3, 2026
Merged

humandebri merged 3 commits into
mainfrom
fix/hub-router-katakana-and-multilingual-fallback

Conversation

@humandebri

Copy link
Copy Markdown
Collaborator

Summary

Fixes two generic multilingual routing & retrieval issues in workers/wiki-mcp/src/hub-router.ts:

  1. Preserve Katakana prolonged sound mark (ー / \u30FC):

    • Previously, tokenizeMultilingual and CJK_TOKEN split Katakana words at ー (e.g., フリーランス → フリ + ランス, メールアドレス → ルアドレス).
    • Updated both regexes to \p{Script=Katakana}[\p{Script=Katakana}\u30FC]+, preserving valid Katakana words including short forms (キー) and NFKC-normalized half-width katakana (ルーター → ルーター) while rejecting standalone or leading prolonged marks (ーネ, ーーー).
  2. Multilingual zero-hit fallback recovery (buildFallbackAttempts + needsSearchFallback):

    • Previously, zero-hit fallback only retried with asciiTokens and only triggered when /Knowledge/index.md was the sole node. Natural-language CJK/multilingual queries (or datasets with canonical pages like overview.md alongside index.md) skipped recovery.
    • Now detects zero-hit responses via ctx.searchHits.length === 0, extracts catalog-matched keywords (preserving exact hiragana name/tag matches like ふるさと, collapsing nested CJK variants like 个人信息保护法 vs 个人信息, and keeping ASCII-first retries when all ASCII query tokens match), and retries up to 2 attempts with error resilience (catching retry failures so the best prior context is preserved).

Review & Verification

  • Addressed all 6 findings from Codex review (0 High, 3 Medium, 3 Low).
  • tsc --noEmit: 0 errors.
  • vitest run: 18/18 test files, 342/342 tests passed (including randomized EN/CJK property tests, 411x inverted-index benchmark speedup, and JA/KO/ZH/EN/mixed fallback contract tests).

@humandebri
humandebri merged commit dc6ae96 into main Dec 3, 2026
20 checks passed
@humandebri
humandebri deleted the fix/hub-router-katakana-and-multilingual-fallback branch December 3, 2026 06:37
@humandebri
humandebri restored the fix/hub-router-katakana-and-multilingual-fallback branch December 3, 2026 06:38
@humandebri
humandebri deleted the fix/hub-router-katakana-and-multilingual-fallback branch December 3, 2026 06:39
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