openclaw-memory-enhancer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

🧠 OpenClaw Memory Enhancer

🧠 OpenClaw 记忆增强器

Give OpenClaw long-term memory - remember important information across sessions and automatically recall relevant context for conversations.
为OpenClaw赋予长期记忆能力——跨会话记住重要信息,并在对话中自动调用相关上下文。

Core Capabilities

核心功能

CapabilityDescription
🔍 Semantic SearchVector similarity search, understanding intent not just keywords
📂 Auto LoadAutomatically reads all files from
memory/
directory
💡 Smart RecallFinds relevant historical memory during conversations
🔗 Memory GraphBuilds connections between related memories
💾 Local Storage100% local, no cloud, complete privacy
🚀 Edge Optimized<10MB memory, runs on Jetson/Raspberry Pi
功能描述
🔍 语义搜索向量相似度搜索,理解意图而非仅匹配关键词
📂 自动加载自动读取
memory/
目录下的所有文件
💡 智能回忆在对话过程中查找相关历史记忆
🔗 记忆图谱构建相关记忆之间的关联
💾 本地存储100%本地运行,无需云端,隐私完全可控
🚀 边缘优化内存占用<10MB,可在Jetson/Raspberry Pi上运行

Quick Reference

快速参考

TaskCommand (Edge Version)Command (Standard Version)
Load memories
python3 memory_enhancer_edge.py --load
python3 memory_enhancer.py --load
Search
--search "query"
--search "query"
Add memory
--add "content"
--add "content"
Export
--export
--export
Stats
--stats
--stats
任务边缘版命令标准版命令
加载记忆
python3 memory_enhancer_edge.py --load
python3 memory_enhancer.py --load
搜索
--search "query"
--search "query"
添加记忆
--add "content"
--add "content"
导出
--export
--export
统计
--stats
--stats

When to Use

使用场景

Use this skill when:
  • You want OpenClaw to remember things across sessions
  • You need to build a knowledge base from chat history
  • You're working on long-term projects that need context
  • You want automatic FAQ generation from conversations
  • You're running on edge devices with limited memory
Don't use when:
  • Simple note-taking apps are sufficient
  • You don't need cross-session memory
  • You have plenty of memory and want maximum accuracy (use standard version)
适合使用本技能的场景:
  • 希望OpenClaw跨会话记住信息
  • 需要基于聊天历史构建知识库
  • 处理需要上下文的长期项目
  • 希望从对话中自动生成FAQ
  • 在内存有限的边缘设备上运行
不适合使用的场景:
  • 简单笔记应用即可满足需求
  • 不需要跨会话记忆
  • 内存充足且追求最高准确率(请使用标准版)

Versions

版本说明

Edge Version ⭐ Recommended

边缘版 ⭐ 推荐

Best for: Jetson, Raspberry Pi, embedded devices
bash
python3 memory_enhancer_edge.py --load
Features:
  • Zero dependencies (Python stdlib only)
  • Memory usage < 10MB
  • Lightweight keyword + vector matching
  • Perfect for resource-constrained devices
适用设备: Jetson、Raspberry Pi、嵌入式设备
bash
python3 memory_enhancer_edge.py --load
特性:
  • 零依赖(仅使用Python标准库)
  • 内存占用<10MB
  • 轻量关键词+向量匹配
  • 完美适配资源受限设备

Standard Version

标准版

Best for: Desktop/server, maximum accuracy
bash
pip install sentence-transformers numpy
python3 memory_enhancer.py --load
Features:
  • Uses sentence-transformers for high-quality embeddings
  • Better semantic understanding
  • Memory usage 50-100MB
  • Requires model download (~50MB)
适用设备: 桌面/服务器,追求最高准确率
bash
pip install sentence-transformers numpy
python3 memory_enhancer.py --load
特性:
  • 使用sentence-transformers生成高质量嵌入向量
  • 语义理解能力更强
  • 内存占用50-100MB
  • 需要下载模型(约50MB)

Installation

安装方式

Via ClawHub (Recommended)

通过ClawHub(推荐)

bash
clawhub install openclaw-memory-enhancer
bash
clawhub install openclaw-memory-enhancer

Via Git

通过Git

bash
git clone https://github.com/henryfcb/openclaw-memory-enhancer.git \
  ~/.openclaw/skills/openclaw-memory-enhancer
bash
git clone https://github.com/henryfcb/openclaw-memory-enhancer.git \
  ~/.openclaw/skills/openclaw-memory-enhancer

Usage Examples

使用示例

Command Line

命令行方式

bash
undefined
bash
undefined

Load existing OpenClaw memories

加载现有OpenClaw记忆

cd ~/.openclaw/skills/openclaw-memory-enhancer python3 memory_enhancer_edge.py --load
cd ~/.openclaw/skills/openclaw-memory-enhancer python3 memory_enhancer_edge.py --load

Search for memories

搜索记忆

python3 memory_enhancer_edge.py --search "voice-call plugin setup"
python3 memory_enhancer_edge.py --search "voice-call plugin setup"

Add a new memory

添加新记忆

python3 memory_enhancer_edge.py --add "User prefers dark mode"
python3 memory_enhancer_edge.py --add "User prefers dark mode"

Show statistics

查看统计信息

python3 memory_enhancer_edge.py --stats
python3 memory_enhancer_edge.py --stats

Export to Markdown

导出为Markdown格式

python3 memory_enhancer_edge.py --export
undefined
python3 memory_enhancer_edge.py --export
undefined

Python API

Python API方式

python
from memory_enhancer_edge import MemoryEnhancerEdge
python
from memory_enhancer_edge import MemoryEnhancerEdge

Initialize

初始化

memory = MemoryEnhancerEdge()
memory = MemoryEnhancerEdge()

Load existing memories

加载现有记忆

memory.load_openclaw_memory()
memory.load_openclaw_memory()

Search for relevant memories

搜索相关记忆

results = memory.search_memory("AI trends report", top_k=3) for r in results: print(f"[{r['similarity']:.2f}] {r['content'][:100]}...")
results = memory.search_memory("AI trends report", top_k=3) for r in results: print(f"[{r['similarity']:.2f}] {r['content'][:100]}...")

Recall context for a conversation

为对话调用上下文

context = memory.recall_for_prompt("Help me check billing")
context = memory.recall_for_prompt("Help me check billing")

Returns formatted memory context

返回格式化的记忆上下文

Add new memory

添加新记忆

memory.add_memory( content="User prefers direct results", source="chat", memory_type="preference" )
undefined
memory.add_memory( content="User prefers direct results", source="chat", memory_type="preference" )
undefined

OpenClaw Integration

OpenClaw集成方式

python
undefined
python
undefined

In your OpenClaw agent

在你的OpenClaw agent中

from skills.openclaw_memory_enhancer.memory_enhancer_edge import MemoryEnhancerEdge
class EnhancedAgent: def init(self): self.memory = MemoryEnhancerEdge() self.memory.load_openclaw_memory()
def process(self, user_input: str) -> str:
    # 1. Recall relevant memories
    memory_context = self.memory.recall_for_prompt(user_input)
    
    # 2. Enhance prompt with context
    enhanced_prompt = f"""
{memory_context}
User: {user_input} """
    # 3. Call LLM with enhanced context
    response = call_llm(enhanced_prompt)
    
    return response
undefined
from skills.openclaw_memory_enhancer.memory_enhancer_edge import MemoryEnhancerEdge
class EnhancedAgent: def init(self): self.memory = MemoryEnhancerEdge() self.memory.load_openclaw_memory()
def process(self, user_input: str) -> str:
    # 1. 调用相关记忆
    memory_context = self.memory.recall_for_prompt(user_input)
    
    # 2. 用上下文增强提示词
    enhanced_prompt = f"""
{memory_context}
User: {user_input} """
    # 3. 调用大语言模型生成响应
    response = call_llm(enhanced_prompt)
    
    return response
undefined

Memory Types

记忆类型

TypeDescriptionExample
daily_log
Daily memory files
memory/2026-02-22.md
capability
Capability recordsSkills, tools
core_memory
Core conventionsImportant rules
qa
Question & AnswerQ: How to... A: You should...
instruction
Direct instructions"Remember: always do X"
solution
Technical solutionsStep-by-step guides
preference
User preferences"User likes dark mode"
类型描述示例
daily_log
每日记忆文件
memory/2026-02-22.md
capability
能力记录技能、工具
core_memory
核心约定重要规则
qa
问答记录Q: 如何... A: 你应该...
instruction
直接指令"记住:始终执行X操作"
solution
技术解决方案分步指南
preference
用户偏好"用户喜欢深色模式"

How It Works

工作原理

Memory Encoding (Edge Version)

记忆编码(边缘版)

  1. Keyword Extraction: Extract important words from text
  2. Hash Vector: Map keywords to vector positions
  3. Normalization: L2 normalize the vector
  4. Storage: Save to local JSON file
  1. 关键词提取:从文本中提取重要词汇
  2. 哈希向量:将关键词映射到向量位置
  3. 归一化:对向量进行L2归一化
  4. 存储:保存到本地JSON文件

Memory Retrieval

记忆检索

  1. Query Encoding: Convert query to same vector format
  2. Keyword Pre-filter: Fast filter by common keywords
  3. Similarity Calculation: Cosine similarity between vectors
  4. Ranking: Return top-k most similar memories
  1. 查询编码:将查询转换为相同格式的向量
  2. 关键词预过滤:通过共同关键词快速过滤
  3. 相似度计算:计算向量间的余弦相似度
  4. 排序:返回相似度最高的前k条记忆

Privacy Protection

隐私保护

  • All data stored locally in
    ~/.openclaw/workspace/knowledge-base/
  • No network requests
  • No external API calls
  • No data leaves your device
  • 所有数据存储在本地
    ~/.openclaw/workspace/knowledge-base/
    目录
  • 无网络请求
  • 无外部API调用
  • 数据不会离开你的设备

Technical Specifications

技术规格

Edge Version

边缘版

yaml
Vector Dimensions: 128
Memory Usage: < 10MB
Dependencies: None (Python stdlib)
Storage Format: JSON
Max Memories: 1000 (configurable)
Query Latency: < 100ms
yaml
Vector Dimensions: 128
Memory Usage: < 10MB
Dependencies: None (Python stdlib)
Storage Format: JSON
Max Memories: 1000 (可配置)
Query Latency: < 100ms

Standard Version

标准版

yaml
Vector Dimensions: 384
Memory Usage: 50-100MB
Dependencies: sentence-transformers, numpy
Storage Format: NumPy + JSON
Model Size: ~50MB download
Query Latency: < 50ms
yaml
Vector Dimensions: 384
Memory Usage: 50-100MB
Dependencies: sentence-transformers, numpy
Storage Format: NumPy + JSON
Model Size: ~50MB download
Query Latency: < 50ms

Configuration

配置说明

Edit these parameters in the code:
python
self.config = {
    "vector_dim": 128,        # Vector dimensions
    "max_memory_size": 1000,  # Max number of memories
    "chunk_size": 500,        # Content chunk size
    "min_keyword_len": 2,     # Minimum keyword length
}
在代码中编辑以下参数:
python
self.config = {
    "vector_dim": 128,        # 向量维度
    "max_memory_size": 1000,  # 最大记忆数量
    "chunk_size": 500,        # 内容分块大小
    "min_keyword_len": 2,     # 关键词最小长度
}

Troubleshooting

故障排除

No results found

无搜索结果

python
undefined
python
undefined

Lower the threshold

降低阈值

results = memory.search_memory(query, threshold=0.2) # Default 0.3
results = memory.search_memory(query, threshold=0.2) # 默认值0.3

Increase top_k

增加返回数量

results = memory.search_memory(query, top_k=10) # Default 5
undefined
results = memory.search_memory(query, top_k=10) # 默认值5
undefined

Memory limit reached

达到记忆上限

The system automatically removes oldest memories when limit is reached.
To increase limit:
python
self.config["max_memory_size"] = 5000  # Increase from 1000
当达到记忆上限时,系统会自动删除最旧的记忆。
如需增加上限:
python
self.config["max_memory_size"] = 5000  # 从1000调整为5000

Slow performance

性能缓慢

  • Use Edge version instead of Standard
  • Reduce
    max_memory_size
  • Use keyword pre-filtering (automatic)
  • 使用边缘版替代标准版
  • 减小
    max_memory_size
    的值
  • 启用关键词预过滤(默认已开启)

Contributing

贡献指南

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a Pull Request
  1. Fork本仓库
  2. 创建功能分支
  3. 提交修改
  4. 发起Pull Request

License

许可证

MIT License - See LICENSE file for details.
MIT许可证 - 详情请查看LICENSE文件。

Acknowledgments

致谢

  • Built for the OpenClaw ecosystem
  • Optimized for edge computing devices
  • Inspired by long-term memory systems in AI

Not an official OpenClaw or Moonshot AI product.
Users must provide their own OpenClaw workspace and API keys.
  • 为OpenClaw生态系统打造
  • 针对边缘计算设备优化
  • 灵感来源于AI中的长期记忆系统

非官方OpenClaw或Moonshot AI产品。
用户需自行提供OpenClaw工作区和API密钥。