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
核心功能
| Capability | Description |
|---|---|
| 🔍 Semantic Search | Vector similarity search, understanding intent not just keywords |
| 📂 Auto Load | Automatically reads all files from |
| 💡 Smart Recall | Finds relevant historical memory during conversations |
| 🔗 Memory Graph | Builds connections between related memories |
| 💾 Local Storage | 100% local, no cloud, complete privacy |
| 🚀 Edge Optimized | <10MB memory, runs on Jetson/Raspberry Pi |
| 功能 | 描述 |
|---|---|
| 🔍 语义搜索 | 向量相似度搜索,理解意图而非仅匹配关键词 |
| 📂 自动加载 | 自动读取 |
| 💡 智能回忆 | 在对话过程中查找相关历史记忆 |
| 🔗 记忆图谱 | 构建相关记忆之间的关联 |
| 💾 本地存储 | 100%本地运行,无需云端,隐私完全可控 |
| 🚀 边缘优化 | 内存占用<10MB,可在Jetson/Raspberry Pi上运行 |
Quick Reference
快速参考
| Task | Command (Edge Version) | Command (Standard Version) |
|---|---|---|
| Load memories | | |
| Search | | |
| Add memory | | |
| Export | | |
| 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 --loadFeatures:
- 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 --loadFeatures:
- 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-enhancerbash
clawhub install openclaw-memory-enhancerVia Git
通过Git
bash
git clone https://github.com/henryfcb/openclaw-memory-enhancer.git \
~/.openclaw/skills/openclaw-memory-enhancerbash
git clone https://github.com/henryfcb/openclaw-memory-enhancer.git \
~/.openclaw/skills/openclaw-memory-enhancerUsage Examples
使用示例
Command Line
命令行方式
bash
undefinedbash
undefinedLoad 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
undefinedpython3 memory_enhancer_edge.py --export
undefinedPython API
Python API方式
python
from memory_enhancer_edge import MemoryEnhancerEdgepython
from memory_enhancer_edge import MemoryEnhancerEdgeInitialize
初始化
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"
)
undefinedmemory.add_memory(
content="User prefers direct results",
source="chat",
memory_type="preference"
)
undefinedOpenClaw Integration
OpenClaw集成方式
python
undefinedpython
undefinedIn 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 responseundefinedfrom 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 responseundefinedMemory Types
记忆类型
| Type | Description | Example |
|---|---|---|
| Daily memory files | |
| Capability records | Skills, tools |
| Core conventions | Important rules |
| Question & Answer | Q: How to... A: You should... |
| Direct instructions | "Remember: always do X" |
| Technical solutions | Step-by-step guides |
| User preferences | "User likes dark mode" |
| 类型 | 描述 | 示例 |
|---|---|---|
| 每日记忆文件 | |
| 能力记录 | 技能、工具 |
| 核心约定 | 重要规则 |
| 问答记录 | Q: 如何... A: 你应该... |
| 直接指令 | "记住:始终执行X操作" |
| 技术解决方案 | 分步指南 |
| 用户偏好 | "用户喜欢深色模式" |
How It Works
工作原理
Memory Encoding (Edge Version)
记忆编码(边缘版)
- Keyword Extraction: Extract important words from text
- Hash Vector: Map keywords to vector positions
- Normalization: L2 normalize the vector
- Storage: Save to local JSON file
- 关键词提取:从文本中提取重要词汇
- 哈希向量:将关键词映射到向量位置
- 归一化:对向量进行L2归一化
- 存储:保存到本地JSON文件
Memory Retrieval
记忆检索
- Query Encoding: Convert query to same vector format
- Keyword Pre-filter: Fast filter by common keywords
- Similarity Calculation: Cosine similarity between vectors
- Ranking: Return top-k most similar memories
- 查询编码:将查询转换为相同格式的向量
- 关键词预过滤:通过共同关键词快速过滤
- 相似度计算:计算向量间的余弦相似度
- 排序:返回相似度最高的前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: < 100msyaml
Vector Dimensions: 128
Memory Usage: < 10MB
Dependencies: None (Python stdlib)
Storage Format: JSON
Max Memories: 1000 (可配置)
Query Latency: < 100msStandard Version
标准版
yaml
Vector Dimensions: 384
Memory Usage: 50-100MB
Dependencies: sentence-transformers, numpy
Storage Format: NumPy + JSON
Model Size: ~50MB download
Query Latency: < 50msyaml
Vector Dimensions: 384
Memory Usage: 50-100MB
Dependencies: sentence-transformers, numpy
Storage Format: NumPy + JSON
Model Size: ~50MB download
Query Latency: < 50msConfiguration
配置说明
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
undefinedpython
undefinedLower 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
undefinedresults = memory.search_memory(query, top_k=10) # 默认值5
undefinedMemory 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调整为5000Slow performance
性能缓慢
- Use Edge version instead of Standard
- Reduce
max_memory_size - Use keyword pre-filtering (automatic)
- 使用边缘版替代标准版
- 减小的值
max_memory_size - 启用关键词预过滤(默认已开启)
Contributing
贡献指南
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a Pull Request
- Fork本仓库
- 创建功能分支
- 提交修改
- 发起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密钥。