Skip to content

fix(s09): match kana words in the keyword memory-selection fallback - #661

Open
shuhuNB515 wants to merge 1 commit into
shareAI-lab:mainfrom
shuhuNB515:fix/s09-kana-keywords
Open

shuhuNB515 wants to merge 1 commit into
shareAI-lab:mainfrom
shuhuNB515:fix/s09-kana-keywords

Conversation

@shuhuNB515

Copy link
Copy Markdown

Fixes #655

Problem

keyword_memory_selection (s09_memory/code.py:274-276) is the fallback used when LLM-based memory selection fails, but its word regex matches only ASCII words and Han characters:

re.findall(r"[a-z0-9_]{3,}|[\u4e00-\u9fff]{2,}", query.lower())

Hiragana/katakana (\u3040–\u30ff) are not covered, so a kana-only Japanese query (e.g. 「インデントはどうやってる?」) extracts zero words and the fallback always returns [] — despite the chapter clearly targeting Japanese users (TEMPORARY_MEMORY_MARKERS at code.py:51-70 includes Japanese markers; every chapter ships a Japanese README).

Fix

Add the kana range to the alternation:

re.findall(r"[a-z0-9_]{3,}|[\u4e00-\u9fff]{2,}|[\u3040-\u30ff]{2,}",
           query.lower())

English/Chinese tokenization is unchanged; the substring-scoring heuristic stays as-is. The embedded s09 source in web/src/data/generated/versions.json is synced.

Verification

Ran the real chapter module end-to-end:

  • old regex on 「インデントの好みは?」 → 0 words (the bug);
  • new regex on 「インデントはどうやってる?」 → kana token extracted;
  • keyword_memory_selection with a matching kana catalog entry → ["style.md"];
  • English query still scores correctly; an unmatched-token kana query still returns [] (heuristic semantics unchanged).
  • python3 -m pytest tests/ — 503 passed, 118 subtests passed.

Disclosed AI assistance: found and fixed during an AI-assisted review; verified end-to-end against the real module and stand behind the change.

keyword_memory_selection is the fallback used when LLM-based memory
selection fails, but its word regex only matched ASCII words and Han
characters -- a kana-only Japanese query extracted zero words, so the
fallback always returned [] for exactly the audience the chapter
already targets (TEMPORARY_MEMORY_MARKERS includes Japanese markers,
and every chapter ships a Japanese README).

Extend the regex with the kana range (\u3040-\u30ff). English and
Chinese tokenization is unchanged; the substring-scoring heuristic
stays as-is. The embedded s09 source in the web registry is synced.

Fixes shareAI-lab#655

This branch has not been deployed

No deployments
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.

s09: keyword fallback never matches Japanese queries — the word regex has no kana range

1 participant