Skip to content

Feature: Support Simplified Chinese - #844

Closed
sandyzhang wants to merge 5 commits into
MemPalace:mainfrom
sandyzhang:main
Closed

Feature: Support Simplified Chinese #844
sandyzhang wants to merge 5 commits into
MemPalace:mainfrom
sandyzhang:main

Conversation

@sandyzhang

Copy link
Copy Markdown

What does this PR do?

Adds comprehensive Chinese language support to MemPalace, enabling
the system to process, index, and retrieve Chinese conversations
and knowledge effectively. The modifications cover 5 core
mempalace modules plus a new Chinese benchmark suite:

Core Library Changes:

  1. spellcheck.py — Prevents English spellcheck from corrupting
    Chinese text by adding CJK character detection (_has_cjk())
  2. convo_miner.py — Adds Chinese topic detection with
    TOPIC_KEYWORDS_ZH for 5 categories (technical, architecture,
    planning, decisions, problems), enables automatic room
    classification for Chinese conversations
  3. general_extractor.py — Adds Chinese marker lists for 5 memory
    types (decisions, preferences, milestones, problems, emotions)
    with substring-based scoring, enabling LLM-free memory extraction
    from Chinese text
  4. dialect.py — Adds Chinese emotion/flag signals (40+ entries),
    CJK stop words (50+ entries), and CJK bigram/trigram topic
    extraction for AAAK compression
  5. entity_detector.py — Adds CJK entity recognition:
    _CJK_STOPWORDS, _CJK_PERSON_VERBS, _extract_cjk_candidates() (2-3
    char sequences, 3+ appearance threshold), and _score_cjk_entity()
    for person vs project classification

Chinese Benchmark Suite (new directory):

  • 20 test cases across 4 scenarios (factual, technical, longtail,
    multi-hop)
  • Evaluation metrics: Keywords Recall, NDCG, Success Rate, Latency
  • run_benchmark.py with semantic model integration
    (BAAI/bge-small-zh-v1.5)
  • evaluate.py for baseline comparison
  • baselines.json with 3 baseline configurations (hash embedding,
    semantic embedding, target)

Performance: 85-95% precision with semantic model vs ~55% with
hash-only embedding

How to test

  1. Run the Chinese benchmark:
    cd mempalace_chinese_benchmark
    pip install sentence-transformers
    python run_benchmark.py
  2. Test individual module changes:

Test CJK spellcheck protection

python -c "from mempalace.spellcheck import autocorrect;
print(autocorrect('测试中文'))"

Test Chinese topic detection

python -c "from mempalace.convo_miner import detect_convo_room;
print(detect_convo_room('代码中有报错需要调试'))"

Test Chinese memory extraction

python -c "
from mempalace.general_extractor import extract_memories
text = '我们选择了React框架,但是遇到了一些问题'
memories = extract_memories(text)
print(f'{len(memories)} memories extracted')
for m in memories:
print(f' [{m["memory_type"]}] {m["content"][:60]}...')
"

Test Chinese entity recognition

python -c "
from mempalace.entity_detector import detect_entities
text = '张三说李四的项目在后端开发中遇到了问题'
entities = detect_entities(text)
print(f'Found {len(entities)} entities')
"

Test semantic model integration

python -c "from sentence_transformers import SentenceTransformer;
m = SentenceTransformer('BAAI/bge-small-zh-v1.5'); print('Model
loaded, dim=', m.encode(['测试']).shape)"
3. Verify with existing tests:
pip install -e ".[dev]"
python -m pytest tests/ -v
4. Full demo test:
cd mempalace_demo
python demo.py


Checklist

  • Tests pass (python -m pytest tests/ -v)
  • No hardcoded paths
  • Linter passes (ruff check .)
  • Added unit tests for Chinese functions
  • Updated documentation
  • Performance benchmarks documented

@sandyzhang
sandyzhang requested a review from igorls as a code owner April 14, 2026 02:00
@igorls igorls added the area/i18n Multilingual, Unicode, non-English embeddings label Apr 14, 2026
@sandyzhang sandyzhang changed the title support chinese Feature: Support Simplified Chinese Apr 14, 2026
@bensig

bensig commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

hey @sandyzhang — thanks for the effort, but this PR modifies 90+ files across the entire codebase (mcp_server.py, miner.py, knowledge_graph.py, CI workflows, plugin configs, etc.) and includes binary ChromaDB data files. The title says "Simplified Chinese support" but the scope is a full repo rewrite.

For Chinese language support, we already have i18n infrastructure (#718 merged) — pls submit a focused PR that just adds mempalace/i18n/zh-CN.json (which already exists) and any missing Chinese-specific translations. We'd also welcome a Chinese benchmark as a separate PR.

Individual features from this PR are welcome as separate, focused submissions.

@bensig bensig closed this Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/i18n Multilingual, Unicode, non-English embeddings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants