SuperAPI AI Directory

memory-cn

Agents & models

View repository

Updated 10-15 09:48

About this skill

Chinese Memory Optimization Skill (memory-cn)

When the user requests diagnosing or optimizing the memory system, follow these steps:

1. Diagnose

Run the diagnostic script to detect problems:

bash SKILL_DIR/scripts/diagnose.sh

The report includes:

  • FTS5 Chinese word segmentation bug detection (unicode61 glues consecutive Chinese characters into a single token)
  • Memory file size distribution
  • tags label coverage
  • lessons knowledge base health

2. Optimize search configuration

If the diagnosis finds problems, apply the optimized configuration:

{
  "agents": {
    "defaults": {
      "memorySearch": {
        "chunking": { "tokens": 250, "overlap": 60 },
        "query": {
          "maxResults": 10,
          "minScore": 0.15,
          "hybrid": {
            "enabled": true,
            "vectorWeight": 0.75,
            "textWeight": 0.25,
            "candidateMultiplier": 8,
            "mmr": { "enabled": true, "lambda": 0.7 },
            "temporalDecay": { "enabled": true, "halfLifeDays": 90 }
          }
        }
      }
    }
  }
}

Use gateway config.patch to apply.

3. Optimize the memoryFlush prompt

Make new logs automatically include tags + Chinese word segmentation:

{
  "agents": {
    "defaults": {
      "compaction": {
        "memoryFlush": {
          "prompt": "将对话内容整理为结构化日志,写入 memory/YYYY-MM-DD.md。\n\n格式要求:\n1. 文件第一行必须是 <!-- tags: 关键词1, 关键词2, ... --> 标签行\n2. 中文关键词之间加空格分隔\n3. 只保留有价值的信息\n4. 控制在 5KB 以内"
        }
      }
    }
  }
}

4. Batch-add tags

For files in memory/projects/*.md that lack tags, automatically add <!-- tags: ... --> lines based on the content.

python3 SKILL_DIR/scripts/add-tags.py /path/to/memory/projects/

5. Compress logs

Compress old logs larger than 8KB to under 5KB, with the original text backed up to archive/:

python3 SKILL_DIR/scripts/compress-logs.py /path/to/memory/ --max-kb 5

6. Rebuild the index

openclaw memory index --force

7. Set up automatic maintenance cron

It is recommended to automatically run compression + cleanup + tag supplementation + index rebuilding every Sunday early morning.

Key technical points

FTS5 unicode61 Bug

  • unicode61 The tokenizer treats consecutive CJK characters as a single token
  • Searching for "pregnancy" cannot match "my wife is newly pregnant" (because the latter is a single token)
  • Workaround: add spaces between Chinese keywords → FTS5 segments correctly

0.6B model parameter tuning

  • vectorWeight 0.75: vector-dominant (FTS5 Chinese is unreliable)
  • minScore 0.15: small model scores are generally lower
  • chunking 250 tokens: smaller chunks help weak models match

Three-layer architecture

  • P0 (MEMORY.md): core facts, <2KB
  • P1 (projects/ + lessons/): search on demand, with tags
  • P2 (logs + archive): historical records