Simple Local Memory 🧠
The zero-dependency memory system for AI agents.
No API keys. No external services. No cloud dependencies. Just pure local storage with intelligent search.
Architecture
CODEBLOCK0
The 3 Memory Layers
Layer 1: HOT RAM (SESSION-STATE.json)
Fast, active working memory
CODEBLOCK1
Benefits:
- - Fast JSON read/write
- Survives compaction
- Easy to parse programmatically
Layer 2: COLD STORE (Indexed Memories)
Persistent, searchable memory
CODEBLOCK2
Storage: memories/ directory with indexed JSON files
Layer 3: CURATED ARCHIVE (MEMORY.md + daily/)
Human-readable long-term memory
CODEBLOCK3
Quick Setup
Step 1: Initialize
CODEBLOCK4
This creates:
- -
SESSION-STATE.json - Active working memory - INLINECODE2 - Long-term curated memory
- INLINECODE3 - Directory for memory storage
Step 2: Use with Your AI Agent
For Claude Code:
CODEBLOCK5
For ChatGPT/Cursor:
Add to your system prompt:
CODEBLOCK6
Memory CLI Commands
CODEBLOCK7
WAL Protocol (Write-Ahead Logging)
CRITICAL: Write to memory BEFORE responding
| Trigger | Action |
|---|
| User states preference | Update SESSION-STATE.json → Store → Respond |
| User makes decision |
Update SESSION-STATE.json → Store → Respond |
| User gives deadline | Update SESSION-STATE.json → Store → Respond |
| User corrects you | Update SESSION-STATE.json → Store → Respond |
Why? If response crashes before saving, context is lost.
Memory Storage Format
memories/YYYY-MM-DD.json
CODEBLOCK8
memories/preferences.json
CODEBLOCK9
memories/decisions.json
CODEBLOCK10
Search Algorithm
TF-IDF based local search:
- 1. Tokenize query and memories
- Calculate term frequency
- Rank by relevance + importance + recency
- Return top N results
CODEBLOCK11
Example Workflow
CODEBLOCK12
Memory Categories
| Type | When to Use | Importance |
|---|
| INLINECODE4 | User expresses like/dislike | 0.8-1.0 |
| INLINECODE5 |
Project decision made | 0.9-1.0 |
|
fact | Important information | 0.6-0.8 |
|
lesson | Learned from mistake | 0.9-1.0 |
|
context | Background info | 0.4-0.6 |
Maintenance
Daily
CODEBLOCK13
Weekly
CODEBLOCK14
Monthly
CODEBLOCK15
Memory Hygiene Tips
- 1. Be specific - "User likes dark mode" > "User has preference"
- Add context - Why was this decision made?
- Use importance - Not everything is 1.0
- Tag properly - Helps with retrieval
- Archive regularly - Keep SESSION-STATE.json small
Troubleshooting
Search returns nothing:
→ Check memories/ directory exists
→ Verify JSON files are valid
→ Try broader search terms
SESSION-STATE.json grows too large:
→ Move old items to memory-store
→ Archive completed tasks
→ Keep only active context
Memories not being saved:
→ Check file permissions
→ Verify disk space
→ Check JSON syntax
Advanced Features
Memory Relationships
CODEBLOCK16
Confidence Scores
CODEBLOCK17
Expiry Dates
CODEBLOCK18
Comparison with elite-longterm-memory
| Feature | Elite | Simple Local |
|---|
| API keys required | Yes (OpenAI) | No |
| External dependencies |
LanceDB, Mem0 | None |
| Cloud sync | Yes | No (can add) |
| Vector search | Yes | TF-IDF local |
| Auto-extraction | Mem0 | Manual/Simple rules |
| Setup complexity | Medium | Simple |
| Privacy | Cloud-dependent | 100% local |
| Cost | Free tiers limit | 100% free |
Migration from elite-longterm-memory
CODEBLOCK19
Future Enhancements (Optional)
- - Add local embedding models (Transformers.js)
- Add compression for old memories
- Add encryption for sensitive data
- Add sync via GitHub Gist
- Add web UI for memory management
No API keys. No cloud. No tracking. Just pure local memory.
Perfect for:
- - Privacy-conscious users
- Offline development
- Learning how memory systems work
- Building custom AI agents
- Projects with strict data policies
简单本地记忆 🧠
AI代理的零依赖记忆系统。
无需API密钥。无需外部服务。无需云依赖。只需带有智能搜索的纯本地存储。
架构
┌─────────────────────────────────────────────────┐
│ 简单本地记忆 │
├─────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ 热内存 │ │ 冷存储 │ │
│ │ │ │ │ │
│ │ 会话状态 │ │ 索引化 │ │
│ │ .json │ │ 记忆 │ │
│ │ │ │ (JSON + │ │
│ │ (活跃上下文)│ │ 搜索) │ │
│ └─────────────┘ └─────────────┘ │
│ │ │ │
│ └────────────────┼─────────────────┘ │
│ ▼ │
│ ┌─────────────┐ │
│ │ MEMORY.md │ ← 人类可读 │
│ │ + daily/ │ │
│ └─────────────┘ │
│ │
└─────────────────────────────────────────────────┘
三层记忆架构
第一层:热内存 (SESSION-STATE.json)
快速、活跃的工作记忆
json
{
current_task: ...,
key_context: [..., ...],
pending_actions: [..., ...],
recent_decisions: [...],
last_updated: 2026-03-15T10:30:00Z
}
优势:
第二层:冷存储 (索引化记忆)
持久化、可搜索的记忆
bash
存储记忆
memory-store --type preference --content 用户偏好深色模式 --importance 0.9
搜索记忆
memory-search 用户关于CSS说了什么
列出最近记忆
memory-list --limit 10
存储: memories/ 目录,包含索引化JSON文件
第三层:策展归档 (MEMORY.md + daily/)
人类可读的长期记忆
workspace/
├── MEMORY.md # 策展洞察
├── SESSION-STATE.json # 活跃上下文
└── memories/
├── 2026-03-15.json # 每日记忆转储
├── preferences.json # 用户偏好
├── decisions.json # 关键决策
└── lessons.json # 经验教训
快速设置
步骤1:初始化
bash
npm install -g simple-local-memory
cd your-project
memory-init
这将创建:
- - SESSION-STATE.json - 活跃工作记忆
- MEMORY.md - 长期策展记忆
- memories/ - 记忆存储目录
步骤2:与AI代理配合使用
对于Claude Code:
markdown
添加到您的自定义指令
当我给您重要信息时:
- 1. 首先写入SESSION-STATE.json
- 然后使用memory-store存储
- 最后回复我
开始对话时:
- 1. 读取SESSION-STATE.json
- 使用memory-search搜索相关记忆
- 检查MEMORY.md获取上下文
对于ChatGPT/Cursor:
添加到系统提示:
您可以访问本地记忆工具:
- - memory-store:保存重要信息
- memory-search:查找相关历史上下文
- 回复前读取SESSION-STATE.json
- 用户分享偏好时更新SESSION-STATE.json
记忆CLI命令
bash
初始化记忆系统
memory-init
存储记忆
memory-store --type preference --content 用户喜欢TypeScript --importance 0.9
搜索记忆
memory-search TypeScript偏好
列出最近记忆
memory-list --limit 10 --type preference
显示记忆统计
memory-stats
导出记忆
memory-export --format json --output backup.json
导入记忆
memory-import --file backup.json
WAL协议(预写日志)
关键: 在回复前写入记忆
| 触发条件 | 操作 |
|---|
| 用户陈述偏好 | 更新SESSION-STATE.json → 存储 → 回复 |
| 用户做出决策 |
更新SESSION-STATE.json → 存储 → 回复 |
| 用户给出截止日期 | 更新SESSION-STATE.json → 存储 → 回复 |
| 用户纠正您 | 更新SESSION-STATE.json → 存储 → 回复 |
为什么? 如果回复在保存前崩溃,上下文将丢失。
记忆存储格式
memories/YYYY-MM-DD.json
json
{
date: 2026-03-15,
memories: [
{
id: uuid,
type: preference|decision|fact|lesson,
content: 用户偏好深色模式,
importance: 0.9,
tags: [ui, preferences],
timestamp: 2026-03-15T10:30:00Z,
context: 在UI设置期间讨论
}
]
}
memories/preferences.json
json
{
preferences: [
{
key: css_framework,
value: Tailwind,
set_at: 2026-03-15T10:30:00Z,
reason: 用户偏好于原生CSS
}
]
}
memories/decisions.json
json
{
decisions: [
{
id: uuid,
title: 使用React作为前端,
reason: 用户要求基于组件的架构,
made_at: 2026-03-15T10:30:00Z,
status: active
}
]
}
搜索算法
基于TF-IDF的本地搜索:
- 1. 对查询和记忆进行分词
- 计算词频
- 按相关性 + 重要性 + 时效性排序
- 返回前N个结果
javascript
// 搜索逻辑示例
function searchMemories(query, limit = 5) {
const queryTokens = tokenize(query);
const allMemories = loadAllMemories();
const scored = allMemories.map(memory => {
const score = calculateTFIDF(queryTokens, memory.content);
const recencyBoost = calculateRecencyBoost(memory.timestamp);
const importanceBoost = memory.importance || 0.5;
return {
...memory,
totalScore: score + recencyBoost + importanceBoost
};
});
return scored
.sort((a, b) => b.totalScore - a.totalScore)
.slice(0, limit);
}
示例工作流程
用户:让我们在这个项目中使用Tailwind,而不是原生CSS
代理处理过程:
- 1. 用决策更新SESSION-STATE.json
- 执行:memory-store --type decision --content 使用Tailwind,不是原生CSS --importance 0.9
- 执行:memory-store --type preference --content 用户偏好Tailwind而非原生CSS --importance 0.95
- 然后回复:收到——就用Tailwind。我已保存此偏好。
记忆分类
| 类型 | 使用时机 | 重要性 |
|---|
| preference | 用户表达喜欢/不喜欢 | 0.8-1.0 |
| decision |
做出项目决策 | 0.9-1.0 |
| fact | 重要信息 | 0.6-0.8 |
| lesson | 从错误中学习 | 0.9-1.0 |
| context | 背景信息 | 0.4-0.6 |
维护
每日
bash
检查记忆健康状态
memory-stats
查看今日记忆
memory-list --date today
每周
bash
归档旧记忆
memory-archive --days 7
清理重复项
memory-deduplicate
用洞察更新MEMORY.md
(手动:查看memories/并添加到MEMORY.md)
每月
bash
导出备份
memory-export --format json --output monthly-backup.json
清理旧每日文件
memory-cleanup --days 30
记忆卫生技巧
- 1. 具体化 - 用户喜欢深色模式 > 用户有偏好
- 添加上下文 - 为什么做出这个决定?
- 使用重要性 - 并非所有内容都是1.0
- 正确标记