Tempera-克劳德码的持久记忆
蛋彩画赋予克劳德密码一种从经验中学习的持久记忆。克劳德可以回忆过去的解决方案,学习什么有效,随着时间的推移变得更聪明,而不是每次都重新开始。
为什么选择蛋彩画?
问题:Claude Code在会话之间会忘记一切。你反复解决同样的问题,克劳德无法从过去的成功或失败中吸取教训。
解决方案Tempera将编码会话捕获为“情节”,对其进行语义搜索索引,并在相关时使用强化学习来呈现最有价值的记忆。
Without Tempera: With Tempera:
┌─────────────┐ ┌─────────────┐
│ Session 1 │ ──forgotten──> │ Session 1 │ ──captured──┐
└─────────────┘ └─────────────┘ │
┌─────────────┐ ┌─────────────┐ ▼
│ Session 2 │ ──forgotten──> │ Session 2 │ ◄──recalls──┤
└─────────────┘ └─────────────┘ │
┌─────────────┐ ┌─────────────┐ │
│ Session 3 │ ──forgotten──> │ Session 3 │ ◄──recalls──┘
└─────────────┘ └─────────────┘
│ │
▼ ▼
No learning Continuous improvement运作原理
学习循环
┌────────────────────────────────────────────────────────────────┐
│ 1. START TASK │
│ User: "Fix the login redirect bug" │
└────────────────────────────────────────────────────────────────┘
│
▼
┌────────────────────────────────────────────────────────────────┐
│ 2. RETRIEVE MEMORIES │
│ Claude searches: "login redirect bug" │
│ Finds: "Fixed similar issue by sanitizing return URLs" │
│ + Session context: related episodes from the same task │
└────────────────────────────────────────────────────────────────┘
│
▼
┌────────────────────────────────────────────────────────────────┐
│ 3. SOLVE FASTER │
│ Claude uses past experience to solve the problem │
└────────────────────────────────────────────────────────────────┘
│
▼
┌────────────────────────────────────────────────────────────────┐
│ 4. CAPTURE SESSION │
│ Claude saves: what was done, what worked, what failed │
│ Auto-links to current session for multi-step tasks │
└────────────────────────────────────────────────────────────────┘
│
▼
┌────────────────────────────────────────────────────────────────┐
│ 5. LEARN FROM FEEDBACK │
│ User: "That memory was helpful!" │
│ → Episode utility increases │
│ → Multi-hop Bellman propagation spreads value │
│ → Session-linked episodes get boosted │
│ → Unhelpful memories fade over time │
└────────────────────────────────────────────────────────────────┘是什么让它“学习”
| 机制 | 它做什么 |
|---|---|
| 反馈 | 有用的剧集获得效用得分 |
| 多跳贝尔曼传播 | 价值通过相似度图在多个跃点上传播 |
| 会话链接 | 多步骤任务中的相关事件相互关联并相互促进 |
| 临时信用 | 成功获得荣誉之前的剧集(甚至跨越会话边界) |
| 近期增长 | 新剧集在检索中的权重可以更高(选择加入) |
| 衰变 | 未使用的记忆会褪色(可配置,默认每天1%) |
| 检索排名 | 结合相似性+效用+新近度评分和权重归一化 |
| BKM合并 | 类似的捕获被合并而不是重复 |
随着时间的推移,经常有用的知识会上升到顶端,而陈旧或无益的记忆会逐渐消失。
安装
从源代码构建
# Clone and build
git clone https://github.com/anvanster/tempera.git
cd tempera
cargo build --release
# Two binaries are created:
# - target/release/tempera (CLI tool)
# - target/release/tempera-mcp (MCP server for Claude Code)从crates.io安装
cargo install tempera首次运行-模型下载
首次使用时,Tempera下载BGE Small嵌入模型(~128MB)进行语义搜索。这会自动发生,而且只发生一次:
# Initialize and trigger model download
tempera init
# Output:
# 🔄 Loading embedding model (this may download the model on first run)...
# ✅ Embedding model loaded该模型全局缓存在 ~/.tempera/models/ 并在所有项目中共享。
使用Claude代码进行设置
1.添加MCP服务器
claude mcp add tempera --scope user -- /path/to/Tempera/target/release/tempera-mcp这 --scope user flag使其在所有项目中都可用。
2.重新启动克劳德代码
退出并重新启动Claude Code以加载新的MCP服务器。
3.验证
跑 /mcp 克劳德密码。你应该看看 tempera 7个工具。
MCP工具
连接后,Claude可以访问这些工具:
| 工具 | 说明 | 何时使用 |
|---|---|---|
tempera_retrieve | 按查询搜索记忆、列出全部或显示详细信息。为链接的剧集显示会话上下文。 | 会话开始 -总是先检查 |
tempera_capture | 将会话另存为剧集。自动检测会话链接并运行传播。 | 任务结束 -主动捕捉成功 |
tempera_feedback | 将剧集标记为有用/无用 | 使用检索到的记忆后 |
tempera_status | 检查当前项目的内存健康状况 | 了解内存状态 |
tempera_stats | 查看统计数据或趋势分析(随时间推移的有用性、领域增长、学习曲线) | 分析和监控 |
tempera_propagate | 具有收敛跟踪的多跳贝尔曼传播 | 定期维护 |
tempera_review | 巩固和清理记忆 | 相关任务系列之后 |
关键生命周期行为
会话开始:Claude应使用以下命令自动检查相关记忆 tempera_retrieve 在开始非琐碎任务之前。
任务结束:Claude应使用以下方式主动捕捉成功的会话 tempera_capture -不要等着被问到。捕获工具会自动运行实用程序传播。
会话链接:在同一项目中连续2小时内捕获的剧集会自动链接到会话中。这允许多步骤任务共享实用程序和上下文。
跨项目洞察:使用 tempera_capture(project: "other-project") 为不同的项目标记记忆。
温度恢复模式
Search: tempera_retrieve(query: "authentication bug")
List all: tempera_retrieve(all: true)
Show details: tempera_retrieve(query: "abc12345") # episode ID对话示例
User: Fix the login redirect vulnerability
Claude: Let me check if we've solved similar problems before...
[Calls tempera_retrieve("login redirect vulnerability")]
Found 2 relevant past experiences:
1. "Fixed open redirect by validating return URLs against whitelist"
- 78% similarity, 85% utility
2. "Auth redirect issue - added URL sanitization"
- 65% similarity, 72% utility
📎 Session abc1 has 2 related episode(s):
- def45678 (Added CSP headers for redirect...)
Based on past experience, I'll implement URL validation...
[Works on the fix]
Done! Let me save this session.
[Calls tempera_capture(summary: "Fixed login redirect...", outcome: "success")]
User: That retrieved memory was really helpful!
Claude: [Calls tempera_feedback(helpful: true, episodes: ["abc123"])]
Marked as helpful - this will improve future retrievals!CLI命令
# Initialize Tempera
tempera init
# Capture an episode manually
tempera capture --prompt "Fixed the authentication bug"
# Index episodes for semantic search
tempera index
# Search memories
tempera retrieve "database connection issues"
# Provide feedback
tempera feedback helpful --episodes abc123,def456
# Run utility propagation (now with multi-hop and convergence tracking)
tempera propagate --temporal
# Prune old/low-value episodes (uses config.toml fallbacks when flags omitted)
tempera prune --older-than 90 --min-utility 0.2 --execute
# View statistics
tempera stats
# View trend analytics (helpfulness over time, domain growth, learning curve)
tempera trends
tempera trends --project myproject --bucket monthly数据存储
Tempera将所有东西都存放在当地 ~/.tempera/ (在所有项目中共享):
~/.tempera/
├── config.toml # Configuration (all RL params configurable)
├── episodes/ # Episode JSON files
│ └── 2026-01-25/
│ └── session-abc123.json
├── vectors/ # Vector database (vectrust/RocksDB)
│ └── episodes/
└── models/ # Embedding model cache (~128MB)
└── models--Xenova--bge-small-en-v1.5/所有项目共享相同的内存数据库,实现跨项目学习。
配置
所有RL参数均可通过以下方式配置 ~/.tempera/config.toml:
[retrieval]
similarity_weight = 0.3 # Weight for semantic similarity
utility_weight = 0.7 # Weight for learned utility
recency_weight = 0.0 # Weight for recency (0 = off, opt-in)
recency_halflife_days = 30.0 # Episodes score 0.5 at this age
mmr_lambda = 0.7 # MMR diversity (0=diverse, 1=relevant)
min_similarity = 0.5 # Filter threshold
[bellman]
gamma = 0.9 # Discount factor for Bellman updates
alpha = 0.1 # Learning rate
decay_rate = 0.01 # Utility decay per day (1%)
propagation_threshold = 0.5 # Min similarity for propagation
max_propagation_depth = 2 # Multi-hop depth (hops)
temporal_credit_window_hours = 1 # Lookback for temporal credit
[storage]
max_age_days = 180 # Max episode age for pruning
min_utility_threshold = 0.05 # Min utility to keep
min_retrievals = 2 # Min retrievals before pruning allowed
consolidation_threshold = 0.85 # BKM merge threshold
cluster_threshold = 0.85 # Duplicate clustering threshold
stale_age_days = 30 # Age threshold for stale detection
stale_utility_threshold = 0.2 # Utility threshold for stale detection幕后的RL
多跳贝尔曼传播
有用剧集的价值在相似性图中以多跳的形式传播:
Hop 0: Source episodes (high helpfulness, ≥2 retrievals)
│
▼ γ¹ discount
Hop 1: Similar episodes updated
│
▼ γ² discount
Hop 2: Episodes similar to hop-1 updated
│
▼ Converges when no updates occur会话链接
同一项目中在2小时内拍摄的剧集会自动链接:
Session abc123:
├── Episode 1: "Investigated auth bug" (debug)
├── Episode 2: "Found root cause in token validation" (research)
└── Episode 3: "Fixed token expiry check" (bugfix, success)
↓
Temporal credit flows back to episodes 1 & 2
Session-linked propagation boosts all 3评分公式
检索排名结合了三个具有归一化权重的信号:
score = (sim_w × similarity + util_w × utility + rec_w × recency) / (sim_w + util_w + rec_w)默认值:30%相似性,70%实用性,0%新近性(新近性是通过配置选择加入的)。
维护
定期运行以保持内存健康:
# Weekly: Propagate utility values (now multi-hop with convergence)
tempera propagate --temporal
# Monthly: Clean up old/useless episodes
tempera prune --older-than 90 --min-utility 0.2 --execute
# As needed: Check trends
tempera trends
# As needed: Review and consolidate
# (via MCP) tempera_review(action: "consolidate")环境变量
| 变量 | 描述 |
|---|---|
ANTHROPIC_API_KEY | 用于基于LLM的意图提取(--extract-intent) |
TEMPERA_DATA_DIR | 覆盖默认数据目录 |
FASTEMBED_CACHE_DIR | 覆盖嵌入模型缓存位置 |
故障排除
MCP服务器未加载
- 检查路径:
ls /path/to/tempera-mcp - 检查配置:
cat ~/.claude.json - 完全重新启动Claude代码
- 跑
/mcp验证
首次运行时嵌入速度较慢
BGE Small型号(约128MB)在首次使用时从HuggingFace下载。这需要互联网接入。下载后,模型将缓存在 ~/.tempera/models/ 离线工作。
矢量搜索未找到任何内容
跑 tempera index 以创建/更新矢量数据库。
模型下载失败
如果位于防火墙或代理之后,请确保访问 huggingface.co。模型文件通过HTTPS下载。
许可证
Apache 2.0
贡献
欢迎投稿!请打开问题或PR。
