Skip to content

wooluo/openclaw-memory-manager

Repository files navigation

OpenClaw Memory Manager 🧠

License: MIT Python 3.8+ OpenClaw

🧠 智能记忆管理系统,为OpenClaw AI助手提供高效的知识库管理

English | 中文


中文

🎯 功能特性

1. 记忆清理

  • 🧹 自动检测并删除过时记忆
  • 🔍 识别重复内容
  • ❌ 移除脏数据和错误信息
  • 📊 记忆质量评分

2. 知识库管理

  • ➕ 快速添加新知识
  • 📝 编辑现有记忆
  • 🏷️ 自动分类和标记
  • 🔗 关联相关记忆

3. 智能检索

  • 🔎 语义搜索
  • 📌 关键词高亮
  • 🎯 精准匹配
  • 📈 相关性排序

4. 记忆优化

  • 🔄 合并相似条目
  • 📋 结构化整理
  • 💾 压缩存储
  • ⚡ 提升检索速度

5. 备份恢复

  • 💾 自动备份
  • 📂 版本管理
  • 🔙 一键恢复
  • ☁️ 云端同步(可选)

🚀 快速开始

安装

# 从GitHub安装
git clone https://github.com/yourusername/openclaw-memory-manager.git
cd openclaw-memory-manager
pip install -r requirements.txt

# 或使用pip安装(即将推出)
pip install openclaw-memory-manager

基本使用

from memory_manager import OpenClawMemoryManager

# 初始化记忆管理器
manager = OpenClawMemoryManager()

# 清理记忆
report = manager.clean_memories()
print(report.summary())

# 添加新知识
manager.add_knowledge(
    category="技术",
    content="Python 3.12新增了性能优化特性",
    tags=["python", "性能", "更新"]
)

# 搜索记忆
results = manager.search("股票交易策略")
for result in results:
    print(result)

命令行使用

# 清理所有记忆
python -m memory_manager clean --all

# 检查记忆质量
python -m memory_manager check

# 添加知识
python -m memory_manager add --category "技术" --content "新知识内容"

# 搜索记忆
python -m memory_manager search "关键词"

# 生成报告
python -m memory_manager report --output memory_report.html

# 备份记忆
python -m memory_manager backup

# 恢复记忆
python -m memory_manager restore --backup backup_20260303.zip

📊 记忆质量评分

系统会为每条记忆计算质量评分(0-100):

分数 等级 说明
90-100 🟢 优秀 完整、准确、最新
70-89 🟡 良好 基本完整,可能需要更新
50-69 🟠 中等 有缺失或过时信息
0-49 🔴 差 严重过时或错误

🧹 清理规则

自动清理

  • ✅ 超过90天未使用的临时记忆
  • ✅ 重复或相似度>80%的条目
  • ✅ 明显错误的配置信息
  • ✅ 过时的版本信息

手动确认

  • ⚠️ 重要决策记录
  • ⚠️ 用户偏好设置
  • ⚠️ 长期记忆条目

📝 知识库结构

memory/
├── 2026-03-01.md          # 日期记忆
├── 2026-03-02.md
├── 2026-03-03.md
├── technical/             # 技术知识
│   ├── python.md
│   ├── security.md
│   └── trading.md
├── personal/              # 个人信息
│   ├── preferences.md
│   └── contacts.md
└── projects/              # 项目记录
    ├── openclaw.md
    └── trading.md

🔄 工作流程

1. 日常维护

# 每天运行(可设置cron)
python -m memory_manager daily-maintenance

自动执行:

  • 清理临时记忆
  • 合并重复条目
  • 更新索引
  • 生成报告

2. 周度整理

# 每周运行
python -m memory_manager weekly-cleanup

执行:

  • 深度清理
  • 知识库优化
  • 备份创建
  • 统计报告

3. 月度审计

# 每月运行
python -m memory_manager monthly-audit

包括:

  • 全面审计
  • 质量评估
  • 结构优化
  • 版本归档

📈 使用示例

示例1:快速添加知识

from memory_manager import OpenClawMemoryManager

manager = OpenClawMemoryManager()

# 添加单条知识
manager.add_knowledge(
    category="技术",
    content="OpenAI发布了GPT-5模型",
    tags=["AI", "GPT", "OpenAI"],
    importance="high"
)

# 批量添加
knowledge_batch = [
    {
        "category": "技术",
        "content": "Python 3.12性能提升30%",
        "tags": ["python", "性能"]
    },
    {
        "category": "业务",
        "content": "股票交易策略更新",
        "tags": ["股票", "交易"]
    }
]

manager.batch_add(knowledge_batch)

示例2:智能搜索

# 语义搜索
results = manager.search("如何优化股票交易", limit=10)

for result in results:
    print(f"相关性: {result.relevance:.2f}")
    print(f"内容: {result.content}")
    print(f"来源: {result.source}")
    print(f"时间: {result.timestamp}")
    print()

示例3:清理脏数据

# 检测脏数据
dirty_data = manager.detect_dirty_data()

print(f"发现 {len(dirty_data)} 条脏数据:")
for item in dirty_data:
    print(f"  - {item.reason}: {item.content[:50]}")

# 清理脏数据
cleaned = manager.clean_dirty_data(auto_confirm=False)
print(f"清理了 {cleaned} 条数据")

🛠️ 高级功能

1. 记忆模板

# templates/daily_log.yaml
template:
  name: "日常日志"
  fields:
    - name: date
      type: date
      required: true
    - name: tasks
      type: list
      required: true
    - name: notes
      type: text
      required: false

2. 自动分类规则

# rules/classification.yaml
rules:
  - pattern: "股票|交易|投资"
    category: "金融"
    tags: ["股票", "交易"]
  
  - pattern: "Python|Java|编程"
    category: "技术"
    tags: ["编程", "开发"]

3. 知识关联

# 自动关联相关记忆
manager.link_related(
    source_id="mem_001",
    target_id="mem_002",
    relationship="related"
)

# 查询关联
related = manager.get_related("mem_001")

💰 支持项目

如果这个项目对你有帮助,欢迎支持开发:

加密货币捐赠

Ethereum / BSC / Base:

0x2F2E602b8fa520e9363773361A2e671d67f91902

支持网络:

  • Ethereum Mainnet
  • Binance Smart Chain (BSC)
  • Base Network

其他支持方式

  • ⭐ Star这个仓库
  • 🐛 报告Bug
  • 💡 提出新功能建议
  • 📢 推广给其他人

📜 许可证

MIT License - 详见 LICENSE


English

🎯 Features

1. Memory Cleaning

  • 🧹 Auto-detect and remove outdated memories
  • 🔍 Identify duplicates
  • ❌ Remove dirty data and errors
  • 📊 Memory quality scoring

2. Knowledge Base Management

  • ➕ Quick add new knowledge
  • 📝 Edit existing memories
  • 🏷️ Auto-categorize and tag
  • 🔗 Link related memories

3. Smart Search

  • 🔎 Semantic search
  • 📌 Keyword highlighting
  • 🎯 Precise matching
  • 📈 Relevance ranking

💰 Support the Project

Cryptocurrency Donations:

0x2F2E602b8fa520e9363773361A2e671d67f91902

📜 License

MIT License - see LICENSE


📞 Contact


Made with ❤️ by the OpenClaw Community

About

🧠 Intelligent memory management tool for OpenClaw AI assistant

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors