介绍
# Memory System v2.0
**适用于 AI 智能体的快速语义记忆,具有 JSON 索引和低于 20ms 的搜索速度。**
## 概述
记忆系统 v2.0 是一个轻量级的、基于文件的记忆系统,专为需要执行以下操作的 AI 智能体设计: - 跨会话记住学习内容、决策、见解、事件和交互 - 在 20ms 内进行语义搜索 - 将每日记忆自动整合为周报 - 追踪重要性和上下文以实现更好的召回
使用纯 bash + jq 构建。无需数据库。
## 功能特性
- ⚡ **快速搜索:** 平均搜索时间 <20ms(通过 36 项测试) - 🧠 **语义记忆:** 捕获 5 种类型的记忆(学习、决策、见解、事件、交互) - 📊 **重要性评分:** 1-10 分制用于记忆优先级排序 - 🏷️ **标签系统:** 使用标签组织记忆 - 📝 **上下文追踪:** 记住创建记忆时正在做的事情 - 📅 **自动整合:** 每周自动生成摘要 - 🔍 **智能搜索:** 带重要性权重的多词搜索 - 📈 **统计与分析:** 追踪记忆数量、类型、重要性分布
## 快速开始
### 安装
```bash # Install jq (required dependency) brew install jq
# Copy memory-cli.sh to your workspace # Already installed if you're using Clawdbot ```
### 基本用法
**捕获记忆:** ```bash ./memory/memory-cli.sh capture \ --type learning \ --importance 9 \ --content "Learned how to build iOS apps with SwiftUI" \ --tags "swift,ios,mobile" \ --context "Building Life Game app" ```
**搜索记忆:** ```bash ./memory/memory-cli.sh search "swiftui ios" ./memory/memory-cli.sh search "build app" --min-importance 7 ```
**最近记忆:** ```bash ./memory/memory-cli.sh recent learning 7 10 ./memory/memory-cli.sh recent all 1 5 ```
**查看统计:** ```bash ./memory/memory-cli.sh stats ```
**自动整合:** ```bash ./memory/memory-cli.sh consolidate ```
## 记忆类型
### 1. 学习(重要性:7-9) 你掌握的新技能、工具、模式、技术。
**示例:** ```bash ./memory/memory-cli.sh capture \ --type learning \ --importance 9 \ --content "Learned Tron Ares aesthetic: ultra-thin 1px red circuit traces on black" \ --tags "design,tron,aesthetic" ```
### 2. 决策(重要性:6-9) 做出的选择、采用的策略、采取的方法。
**示例:** ```bash ./memory/memory-cli.sh capture \ --type decision \ --importance 8 \ --content "Switched from XP grinding to achievement-based leveling with milestones" \ --tags "life-game,game-design,leveling" ```
### 3. 见解(重要性:8-10) 突破、领悟、顿悟时刻。
**示例:** ```bash ./memory/memory-cli.sh capture \ --type insight \ --importance 10 \ --content "Simple binary yes/no tracking beats complex detailed logging" \ --tags "ux,simplicity,habit-tracking" ```
### 4. 事件(重要性:5-8) 里程碑、完成、发布、重大事件。
**示例:** ```bash ./memory/memory-cli.sh capture \ --type event \ --importance 10 \ --content "Shipped Life Game iOS app with Tron Ares aesthetic in 2 hours" \ --tags "shipped,life-game,milestone" ```
### 5. 交互(重要性:5-7) 关键对话、反馈、用户请求。
**示例:** ```bash ./memory/memory-cli.sh capture \ --type interaction \ --importance 7 \ --content "User requested simple yes/no habit tracking instead of complex quests" \ --tags "feedback,user-request,simplification" ```
## 架构
### 文件结构
``` memory/ ├── memory-cli.sh # Main CLI tool ├── index/ │ └── memory-index.json # Fast search index ├── daily/ │ └── YYYY-MM-DD.md # Daily memory logs └── consolidated/ └── YYYY-WW.md # Weekly consolidated summaries ```
### JSON 索引格式
```json { "version": 1, "lastUpdate": 1738368000000, "memories": [ { "id": "mem_20260131_12345", "type": "learning", "importance": 9, "timestamp": 1738368000000, "date": "2026-01-31", "content": "Memory content here", "tags": ["tag1", "tag2"], "context": "What I was doing", "file": "memory/daily/2026-01-31.md", "line": 42 } ] } ```
### 性能基准
**所有 36 项测试通过:** - 搜索:平均 <20ms(最快:8ms,最慢:18ms) - 捕获:平均 <50ms - 统计:<10ms - 最近:<15ms - 所有操作:<100ms 目标 ✅
## 命令参考
### capture ```bash ./memory-cli.sh capture \ --type <learning|decision|insight|event|interaction> \ --importance <1-10> \ --content "Memory content" \ --tags "tag1,tag2,tag3" \ --context "What you were doing" ```
### search ```bash ./memory-cli.sh search "keywords" [--min-importance N] ```
### recent ```bash ./memory-cli.sh recent <type|all> <days> <min-importance> ```
### stats ```bash ./memory-cli.sh stats ```
### consolidate ```bash ./memory-cli.sh consolidate [--week YYYY-WW] ```
## 与 Clawdbot 集成
记忆系统 v2.0 专为与 Clawdbot 无缝协作而设计:
**在 AGENTS.md 中自动捕获:** ```markdown ## Memory Recall Before answering anything about prior work, decisions, dates, people, preferences, or todos: run memory_search on MEMORY.md + memory/*.md ```
**示例工作流:** 1. 智能体学到新知识 → `memory-cli.sh capture` 2. 用户问“我们昨天构建了什么?” → `memory-cli.sh search "build yesterday"` 3. 智能体通过文件和行号引用回忆起确切的细节
## 用例
### 1. 学习追踪 捕获你学到的每一项新技能、工具或技术: ```bash ./memory-cli.sh capture \ --type learning \ --importance 8 \ --content "Learned how to publish ClawdHub packages with clawdhub publish" \ --tags "clawdhub,publishing,packaging" ```
### 2. 决策历史 记录你做出特定选择的原因: ```bash ./memory-cli.sh capture \ --type decision \ --importance 9 \ --content "Chose binary yes/no tracking over complex RPG quests for simplicity" \ --tags "ux,simplicity,design-decision" ```
### 3. 里程碑追踪 记录主要成就: ```bash ./memory-cli.sh capture \ --type event \ --importance 10 \ --content "Completed Memory System v2.0: 36/36 tests passed, <20ms search" \ --tags "milestone,memory-system,shipped" ```
### 4. 每周回顾 自动生成每周摘要: ```bash ./memory-cli.sh consolidate --week 2026-05 ```
## 高级用法
### 带重要性过滤的搜索 ```bash # Only high-importance learnings ./memory-cli.sh search "swiftui" --min-importance 8
# All memories mentioning "API" ./memory-cli.sh search "API" --min-importance 1 ```
### 最近的高优先级决策 ```bash # Decisions from last 7 days with importance ≥ 8 ./memory-cli.sh recent decision 7 8 ```
### 批量分析 ```bash # See memory distribution ./memory-cli.sh stats
# Output: # Total memories: 247 # By type: learning=89, decision=67, insight=42, event=35, interaction=14 # By importance: 10=45, 9=78, 8=63, 7=39, 6=15, 5=7 ```
## 局限性
- **仅文本搜索:** 尚无语义嵌入 - **单用户:** 并非为多用户场景设计 - **基于文件:** 在约 1 万条记忆之前性能良好,之后可能会变慢 - **Bash 依赖:** 需要 bash + jq(适用于 macOS/Linux)
## 未来增强
- [ ] 语义嵌入以实现更好的搜索 - [ ] AI 自动打标签 - [ ] 记忆图谱(记忆之间的连接) - [ ] 导出到 Notion/Obsidian - [ ] 多语言支持 - [ ] 云同步(可选)
## 测试
包含 36 项测试的完整测试套件,涵盖: - 捕获操作(10 项测试) - 搜索功能(12 项测试) - 最近查询(6 项测试) - 统计生成(4 项测试) - 整合(4 项测试)
**运行测试:** ```bash ./memory-cli.sh test # If test suite is included ```
**所有测试通过 ✅** - 详情请参阅 `memory-system-v2-test-results.md`。
## 性能
**设计目标:** - 搜索:<20ms ✅ - 捕获:<50ms ✅ - 统计:<10ms ✅ - 所有操作:<100ms ✅
**测试环境:** M1 Mac,索引中有 247 条记忆
## 为什么选择记忆系统 v2.0?
**问题:** AI 智能体在会话之间会忘记所有内容。上下文会丢失。
**解决方案:** 快速、可搜索的跨会话持久记忆。
**优势:** - 智能体可以回忆以前的工作、决策和学习内容 - 用户无需重复自己 - 上下文随时间积累 - 智能体会越用越聪明
## 致谢
由 Kelly Claude(AI 行政助理)构建,作为自我改进项目。
**设计理念:** 快速、简单、基于文件。无复杂依赖。
## 许可证
MIT 许可证 - 可自由使用,按需修改。
## 支持
问题:https://github.com/austenallred/memory-system-v2/issues 文档:本文件 + `memory-system-v2-design.md`
---
**记忆系统 v2.0 - 记住一切。毫秒级搜索。**