ANALYSIS
CoPaw 记忆系统使用指南
概述
CoPaw 的记忆系统是一个强大的长期记忆管理工具,能够主动从对话中捕获决策、偏好和待办事项。你使用 CoPaw 越久,它就越了解你。
记忆系统概述
什么是记忆系统
记忆系统是 CoPaw 的核心组件之一,负责:
- 存储对话历史:保存用户与 CoPaw 的对话记录
- 提取关键信息:从对话中提取重要信息
- 长期记忆:持久化存储用户的偏好和习惯
- 智能检索:根据上下文快速检索相关信息
记忆类型
| 类型 | 说明 | 存储方式 | 持久化 |
|---|---|---|---|
| 会话记忆 | 当前会话的对话历史 | 内存 | 否 |
| 长期记忆 | 跨会话的持久化信息 | 文件 / 数据库 | 是 |
| 工作记忆 | 当前任务相关的信息 | 内存 | 否 |
| 知识记忆 | 用户提供的知识库 | 文件 / 数据库 | 是 |
记忆特性
特性:
- 主动性:主动从对话中捕获信息
- 语义化:使用语义搜索而非关键词匹配
- 个性化:根据用户行为调整记忆策略
- 持久化:信息长期保存,跨会话可用
记忆管理
记忆 CLI 命令
查看记忆:
PRTCL // BASH
# 查看所有记忆copaw memory list
# 查看会话记忆copaw memory list --type session
# 查看长期记忆copaw memory list --type long-term
# 搜索记忆copaw memory search keyword添加记忆:
PRTCL // BASH
# 手动添加记忆copaw memory add "我喜欢喝咖啡"
# 添加带标签的记忆copaw memory add "我喜欢喝咖啡" --tags preference删除记忆:
PRTCL // BASH
# 删除记忆copaw memory remove <memory-id>
# 清空所有记忆copaw memory clear更新记忆:
PRTCL // BASH
# 更新记忆copaw memory update <memory-id> "新的内容"
# 更新记忆标签copaw memory update <memory-id> --tags new-tags记忆配置
配置文件:
PRTCL // YAML
memory: enabled: true
# 记忆存储 storage: type: "file" # file, database, vector_db path: "~/.copaw/memory/"
# 记忆限制 limits: max_entries: 1000 max_size: 104857600 # 100MB retention_days: 365
# 记忆策略 strategy: auto_extract: true extraction_threshold: 0.7 consolidation_enabled: true consolidation_interval: 86400 # 1 天
# 检索配置 retrieval: enabled: true method: "semantic" # semantic, keyword, hybrid top_k: 5 threshold: 0.7
# 缓存配置 cache: enabled: true size: 100 ttl: 3600记忆类型配置
会话记忆:
PRTCL // YAML
session_memory: enabled: true max_messages: 20 strategy: "recent" # recent, summary长期记忆:
PRTCL // YAML
long_term_memory: enabled: true max_entries: 1000 auto_extract: true extraction_types: - "preference" - "decision" - "todo" - "fact"工作记忆:
PRTCL // YAML
working_memory: enabled: true max_items: 10 strategy: "priority"记忆提取
自动提取
CoPaw 会自动从对话中提取以下类型的信息:
偏好:
PRTCL // PLAINTEXT
用户:我喜欢喝咖啡,每天早上都要喝一杯CoPaw:[记忆提取] 用户偏好:每天早上喝咖啡决策:
PRTCL // PLAINTEXT
用户:我决定明天去北京出差CoPaw:[记忆提取] 用户决策:明天去北京出差待办事项:
PRTCL // PLAINTEXT
用户:我需要完成这个报告CoPaw:[记忆提取] 用户待办:完成报告事实:
PRTCL // PLAINTEXT
用户:我的手机号码是 13800138000CoPaw:[记忆提取] 用户事实:手机号码 13800138000手动添加
添加记忆:
PRTCL // BASH
# 添加简单记忆copaw memory add "我的生日是 1990 年 1 月 1 日"
# 添加带标签的记忆copaw memory add "我的生日是 1990 年 1 月 1 日" --tags personal
# 添加带优先级的记忆copaw memory add "我的生日是 1990 年 1 月 1 日" --priority high批量导入
从文件导入:
PRTCL // BASH
# 从 CSV 文件导入copaw memory import memories.csv
# 从 JSON 文件导入copaw memory import memories.jsonCSV 格式:
PRTCL // CSV
content,tags,priority我喜欢喝咖啡,preference,high我的生日是 1990 年 1 月 1 日,personal,medium我的电话是 13800138000,contact,highJSON 格式:
PRTCL // JSON
[ { "content": "我喜欢喝咖啡", "tags": ["preference"], "priority": "high" }, { "content": "我的生日是 1990 年 1 月 1 日", "tags": ["personal"], "priority": "medium" }]记忆检索
语义搜索
语义搜索:
PRTCL // BASH
# 语义搜索copaw memory search "咖啡" --method semantic
# 搜索结果- 我喜欢喝咖啡 ( 相似度: 0.95)- 我每天早上都要喝一杯咖啡 ( 相似度: 0.90)关键词搜索
关键词搜索:
PRTCL // BASH
# 关键词搜索copaw memory search "咖啡" --method keyword
# 搜索结果- 我喜欢喝咖啡- 我每天早上都要喝一杯咖啡混合搜索
混合搜索:
PRTCL // BASH
# 混合搜索copaw memory search "咖啡" --method hybrid
# 搜索结果(语义 + 关键词)- 我喜欢喝咖啡 ( 相似度: 0.95, 匹配: 是 )- 我每天早上都要喝一杯咖啡 ( 相似度: 0.90, 匹配: 是 )按标签搜索
按标签搜索:
PRTCL // BASH
# 按标签搜索copaw memory search --tags preference
# 搜索结果- 我喜欢喝咖啡 ( 标签: preference)- 我喜欢编程 ( 标签: preference)记忆管理
记忆维护
查看记忆统计:
PRTCL // BASH
# 查看记忆统计copaw memory stats
# 输出示例总记忆数: 150会话记忆: 20长期记忆: 130记忆大小: 5.2MB清理过期记忆:
PRTCL // BASH
# 清理过期记忆copaw memory cleanup --days 30
# 清理重复记忆copaw memory cleanup --duplicates
# 清理无用记忆copaw memory cleanup --unused合并相似记忆:
PRTCL // BASH
# 合并相似记忆copaw memory merge --threshold 0.8
# 输出示例合并 5 个相似记忆记忆导出
导出记忆:
PRTCL // BASH
# 导出为 JSONcopaw memory export memories.json
# 导出为 CSVcopaw memory export memories.csv
# 导出为 Markdowncopaw memory export memories.md记忆备份
备份记忆:
PRTCL // BASH
# 创建备份copaw memory backup --output backup-$(date +%Y%m%d).json
# 自动备份copaw memory backup --schedule "0 2 * * *"记忆集成
在对话中使用记忆
记忆增强对话:
PRTCL // PLAINTEXT
用户:明天我要去北京CoPaw:[检索记忆] 根据之前的记忆,你喜欢去北京出差。需要我帮你准备什么吗?
用户:帮我订一张去北京的机票CoPaw:[检索记忆] 你的偏好是靠窗座位,我将为你预订靠窗座位。记忆触发器
创建触发器:
PRTCL // YAML
triggers: - name: "birthday_reminder" type: "time" schedule: "0 0 1 1 *" # 每年 1 月 1 日 action: "memory_search" query: "生日" response: "生日快乐!"
- name: "coffee_preference" type: "keyword" keyword: "咖啡" action: "memory_search" query: "咖啡" response: "我知道你喜欢喝咖啡!"记忆与技能集成
技能使用记忆:
PRTCL // PYTHON
from copaw.skills import Skillfrom copaw.memory import MemoryManager
class MySkill(Skill): """我的技能"""
def __init__(self, config): super().__init__(config) self.memory = MemoryManager()
def execute(self, input_data): # 检索记忆 memories = self.memory.search(input_data['query'])
# 使用记忆 result = self.process_with_memory(input_data, memories)
return result记忆安全
访问控制
配置访问权限:
PRTCL // YAML
security: enabled: true access_control: read: enabled: true allowed_users: - "user@example.com" write: enabled: true allowed_users: - "user@example.com" delete: enabled: true allowed_users: - "user@example.com"数据加密
加密配置:
PRTCL // YAML
encryption: enabled: true algorithm: "AES-256" key_source: "env" key_name: "MEMORY_ENCRYPTION_KEY"隐私保护
敏感信息过滤:
PRTCL // YAML
privacy: enabled: true filters: - type: "phone" action: "mask" - type: "email" action: "mask" - type: "address" action: "mask" - type: "password" action: "skip"记忆优化
检索优化
优化检索速度:
PRTCL // YAML
retrieval: enabled: true method: "semantic" top_k: 5 threshold: 0.7 cache: enabled: true size: 100 ttl: 3600 index: type: "faiss" # faiss, hnsw dimension: 768存储优化
优化存储空间:
PRTCL // YAML
storage: type: "file" path: "~/.copaw/memory/" compression: enabled: true algorithm: "gzip" cleanup: enabled: true interval: 86400 retention_days: 365性能监控
监控记忆性能:
PRTCL // BASH
# 查看记忆性能copaw memory performance
# 输出示例检索平均时间: 0.05s检索成功率: 99.5%存储使用率: 52%故障排查
记忆无法保存
问题:记忆无法保存
解决方案:
PRTCL // BASH
# 检查记忆配置copaw memory config validate
# 检查存储权限ls -la ~/.copaw/memory/
# 检查磁盘空间df -h记忆检索失败
问题:记忆检索失败
解决方案:
PRTCL // BASH
# 重建索引copaw memory rebuild-index
# 检查记忆状态copaw memory status
# 查看检索日志copaw logs | grep memory记忆重复
问题:记忆重复
解决方案:
PRTCL // BASH
# 清理重复记忆copaw memory cleanup --duplicates
# 合并相似记忆copaw memory merge --threshold 0.8最佳实践
记忆管理建议
- 定期清理:定期清理过期和无用的记忆
- 合理分类:使用标签对记忆进行分类
- 控制数量:控制记忆数量,避免信息过载
- 备份重要记忆:定期备份重要记忆
记忆提取建议
- 主动标注:对重要记忆进行标注
- 定期整理:定期整理和更新记忆
- 验证准确性:验证记忆的准确性
- 保护隐私:保护敏感信息
记忆使用建议
- 合理检索:使用合适的检索方法
- 上下文相关:确保记忆与上下文相关
- 持续更新:持续更新和优化记忆
- 监控性能:监控记忆系统性能
资源链接
- CoPaw 记忆文档: https://copaw.bot/docs/memory
- 记忆系统论文: https://arxiv.org/abs/xxxx.xxxxx
- 向量数据库文档: https://copaw.bot/docs/vector-db
最后更新: 2026-03-12 作者: EchoHaoRan
R P
Rhine Lab Pioneer Division
Auth_Verified: 2026.03.20
Auth_Verified: 2026.03.20
