Skip to content

Commit 30138b5

Browse files
committed
fix(searcher): align i18n stop_words with tokenizer and fix lang docstring
_tokenize() emits only \w{2,} tokens, so single-character entries in ja.json and zh-CN.json regex.stop_words could never match. Removed single-char kana from ja and single-char hanzi from zh-CN; remaining ≥2-char entries are what _tokenize actually produces. Also updated the search_memories(lang=) docstring to reflect the opt-in lang_explicit resolution implemented in fb1a133; prior text described the pre-opt-in MempalaceConfig().lang fallback chain. Reported by qodo-ai-reviewer on MemPalace#977.
1 parent 9a19af4 commit 30138b5

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

mempalace/i18n/ja.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"regex": {
3939
"topic_pattern": "[\\u30A0-\\u30FF]{3,}|[\\u4E00-\\u9FFF]{2,}|[A-Za-z][A-Za-z0-9_]{2,}",
40-
"stop_words": "は が を に で と も の へ から まで より した します している されて です ます ました こと もの ため それ これ その この あの ない なく ある いる する",
40+
"stop_words": "から まで より した します している されて です ます ました こと もの ため それ これ その この あの ない なく ある いる する",
4141
"quote_pattern": "「([^」]{10,100})」",
4242
"action_pattern": "(構築|修正|追加|削除|確認|作成|実装|修復|書き直し|テスト|検証|更新|設定|起動|停止)(?:し|した|して|する|します)"
4343
}

mempalace/i18n/zh-CN.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"regex": {
3939
"topic_pattern": "[\\u4E00-\\u9FFF]{2,}|[A-Za-z][A-Za-z0-9_]{2,}",
40-
"stop_words": "的 了 在 是 我 有 和 就 不 人 都 一 一个 上 也 很 到 说 要 去 你 会 着 没有 看 好 自己 这 那 她 他 它 们 但是 因为 所以 如果 虽然 然后 或者 而且",
40+
"stop_words": "一个 没有 自己 但是 因为 所以 如果 虽然 然后 或者 而且",
4141
"quote_pattern": "\\u201C([^\\u201D]{10,100})\\u201D|\"([^\"]{10,200})\"",
4242
"action_pattern": "(构建|修复|添加|删除|确认|创建|实现|修理|编写|测试|验证|更新|配置|启动|停止)(?:了|完成|成功)"
4343
},

mempalace/searcher.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,12 @@ def search_memories(
822822
When ``max_distance > 0.0`` is also set, BM25-only candidates
823823
are skipped — they have no vector distance and would silently
824824
violate the requested distance threshold.
825-
lang: Locale code for BM25 stop-word filtering. When omitted, reads
826-
``MempalaceConfig().lang`` which resolves via env, config.json,
827-
``entity_languages[0]``, then falls back to English.
825+
lang: Locale code for BM25 stop-word filtering (opt-in). When
826+
omitted, reads ``MempalaceConfig().lang_explicit`` — returns an
827+
empty set unless the user has set ``MEMPALACE_LANG`` /
828+
``MEMPAL_LANG`` or ``config.json["lang"]``. Palaces without an
829+
explicit language skip filtering entirely, preserving pre-PR
830+
byte-identical scoring.
828831
"""
829832
# Validate the strategy eagerly so invalid values fail the same way
830833
# regardless of whether the call routes through the vector path or

0 commit comments

Comments
 (0)