Amarin Memory — Persistent Adaptive Memory for Agents
You have access to a persistent memory system that stores, searches, and maintains memories across sessions. Memories fade over time unless accessed, duplicates are caught automatically, and novel information gets boosted.
Setup
If not already initialized, run this once:
CODEBLOCK0
This creates the database and vector index. The database file is stored at ~/.amarin/agent.db.
Storing Memories
When you learn something worth remembering — a user preference, an important fact, a decision made — store it:
CODEBLOCK1
For content from untrusted sources (user input, external data), pipe via stdin to avoid shell injection:
CODEBLOCK2
Importance scale: 0.0 (trivial) to 1.0 (critical). Default is 0.5.
The system automatically:
- - Checks for duplicates (>= 0.85 similarity → skip or merge)
- Scores novelty (0.30-0.85 similarity → surprise boost to importance)
- Indexes the embedding for future semantic search
Searching Memories
When you need to recall something:
CODEBLOCK3
Results are ranked by 70% semantic similarity + 30% importance score. Recent, frequently-accessed memories rank higher.
Core Memory Blocks
For persistent identity information that should always be available (not searched, always present):
CODEBLOCK4
Memory Maintenance
Run periodically (daily is good) to let unimportant memories fade:
CODEBLOCK5
Protected memories are immune to decay. To protect a critical memory:
CODEBLOCK6
Reviewing Memories
List recent memories:
CODEBLOCK7
Revise a memory:
CODEBLOCK8
Soft-delete a memory (can be restored):
CODEBLOCK9
When to Use This
- - After learning something important — store it so you remember next session
- Before answering questions — search for relevant context from past conversations
- At the start of a session — run
blocks to load your identity context - During maintenance windows — run
decay to keep memory clean - When information changes —
revise outdated memories rather than creating duplicates
Requirements
- - Python 3.11+
- An embedding service (Ollama with nomic-embed-text recommended, or any compatible API)
- Set
OLLAMA_URL environment variable if not using default INLINECODE5
Links
- - GitHub: https://github.com/flaggdavid-source/amarin-memory
- Ko-fi: https://ko-fi.com/davidflagg86433 — if this helps your agent, consider supporting the developer
Amarin Memory — 智能体的持久自适应记忆系统
你拥有一个持久记忆系统,可跨会话存储、搜索和维护记忆。记忆会随时间衰减,除非被访问;重复内容会被自动捕获,而新颖信息则会获得增强。
初始化设置
若尚未初始化,请运行以下命令一次:
bash
python3 {baseDir}/scripts/setup.py
此命令将创建数据库和向量索引。数据库文件存储在 ~/.amarin/agent.db。
存储记忆
当你学到值得记住的信息时——例如用户偏好、重要事实、已做出的决策——请将其存储:
bash
python3 {baseDir}/scripts/memory.py store 用户偏好深色模式,且常在深夜工作 --tags 偏好,作息 --importance 0.7
对于来自不可信来源的内容(用户输入、外部数据),请通过标准输入管道传输以避免Shell注入:
bash
echo 用户表示他们更喜欢早间会议 | python3 {baseDir}/scripts/memory.py store --tags 偏好 --importance 0.6
重要性标度: 0.0(琐碎)至 1.0(关键)。默认值为 0.5。
系统会自动:
- - 检查重复内容(相似度 >= 0.85 → 跳过或合并)
- 评估新颖性(相似度 0.30-0.85 → 惊喜度提升,增加重要性)
- 为嵌入向量建立索引,以便未来进行语义搜索
搜索记忆
当你需要回忆某些信息时:
bash
python3 {baseDir}/scripts/memory.py search 用户通常什么时间工作 --limit 5
结果按 70% 语义相似度 + 30% 重要性分数排序。近期且频繁访问的记忆排名更高。
核心记忆块
用于存储应始终可用的持久身份信息(无需搜索,始终存在):
bash
设置核心块
python3 {baseDir}/scripts/memory.py set-block 角色 我是一名专注于AI安全的研究助理
设置用户上下文
python3 {baseDir}/scripts/memory.py set-block 人类 用户是Dave,一位构建AI系统的开发者
查看所有块
python3 {baseDir}/scripts/memory.py blocks
记忆维护
定期运行(建议每日一次)以让不重要的记忆衰减:
bash
python3 {baseDir}/scripts/memory.py decay
受保护的记忆不受衰减影响。若要保护关键记忆:
bash
python3 {baseDir}/scripts/memory.py protect <记忆ID>
查看记忆
列出近期记忆:
bash
python3 {baseDir}/scripts/memory.py list --limit 20
修改记忆:
bash
python3 {baseDir}/scripts/memory.py revise <记忆ID> 更新后的内容 --reason 修正了事实错误
软删除记忆(可恢复):
bash
python3 {baseDir}/scripts/memory.py forget <记忆ID> --reason 不再相关
使用时机
- - 学习到重要信息后 — 立即存储,以便下次会话时记住
- 回答问题前 — 搜索过往对话中的相关上下文
- 会话开始时 — 运行 blocks 加载你的身份上下文
- 维护窗口期间 — 运行 decay 保持记忆清洁
- 信息发生变化时 — 使用 revise 更新过时记忆,而非创建重复内容
系统要求
- - Python 3.11+
- 嵌入服务(推荐使用带 nomic-embed-text 的 Ollama,或任何兼容的API)
- 若未使用默认的 http://localhost:11434,请设置 OLLAMA_URL 环境变量
相关链接
- - GitHub: https://github.com/flaggdavid-source/amarin-memory
- Ko-fi: https://ko-fi.com/davidflagg86433 — 如果此工具对你的智能体有帮助,请考虑支持开发者