fix(memory): CJK-aware short query threshold + Chinese synonym expansion

1. MemoryMiddleware: replace byte-length check (query.len() < 4) with
   char-count check (query.chars().count() < 2). Single CJK characters
   are 3 UTF-8 bytes but 1 meaningful character — the old threshold
   incorrectly skipped 1-2 char Chinese queries like "你好".

2. QueryAnalyzer: add Chinese synonym mappings for 13 common technical
   terms (错误→bug, 优化→improve, 配置→config, etc.) so CJK queries
   can find relevant English-keyword memories and vice versa.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
iven
2026-04-02 01:21:29 +08:00
parent 07099e3ef0
commit 1bf0d3a73d
2 changed files with 44 additions and 7 deletions

View File

@@ -216,9 +216,10 @@ impl QueryAnalyzer {
expansions
}
/// Get synonyms for a keyword (simplified)
/// Get synonyms for a keyword (simplified, English + Chinese)
fn get_synonyms(&self, keyword: &str) -> Option<Vec<String>> {
let synonyms: &[&str] = match keyword {
// English synonyms
"code" => &["program", "script", "source"],
"error" => &["bug", "issue", "problem", "exception"],
"fix" => &["solve", "resolve", "repair", "patch"],
@@ -226,6 +227,20 @@ impl QueryAnalyzer {
"slow" => &["performance", "optimize", "speed"],
"help" => &["assist", "support", "guide", "aid"],
"learn" => &["study", "understand", "know", "grasp"],
// Chinese synonyms — critical for Chinese-language queries
"错误" => &["问题", "bug", "异常", "故障"],
"修复" => &["解决", "修正", "处理", "fix"],
"优化" => &["改进", "提升", "加速", "improve"],
"配置" => &["设置", "参数", "选项", "config"],
"性能" => &["速度", "效率", "performance"],
"问题" => &["错误", "故障", "issue", "problem"],
"帮助" => &["协助", "支持", "help"],
"学习" => &["了解", "掌握", "learn"],
"代码" => &["程序", "脚本", "code"],
"数据库" => &["DB", "database", "存储"],
"部署" => &["发布", "上线", "deploy"],
"测试" => &["验证", "检验", "test"],
"安全" => &["防护", "加密", "security"],
_ => return None,
};