Agent Memory Persistence
Use this skill when an agent needs durable memory storage across sessions.
What it provides
- - SQLite-backed persistence for text, metadata, and embedding vectors
- CRUD operations for memory items
- Semantic retrieval with cosine-similarity vector search
- Memory lifecycle operations including expiration cleanup
- Filters by user, session, type, and time window
Project structure
- -
src/MemoryStore.ts: low-level SQLite storage engine - INLINECODE1 : vector similarity search over stored embeddings
- INLINECODE2 : high-level API used by agents
- INLINECODE3 : shared TypeScript contracts
Usage pattern
- 1. Create a
MemoryManager with a SQLite path. - Write memories with
content, optional metadata, and optional embedding. - Query memories by session/user or use
searchByVector() for semantic lookup. - Periodically call
cleanupExpired() to delete stale memories.
Notes
- - Embeddings are stored as JSON arrays in SQLite.
- Vector search is implemented in TypeScript using cosine similarity, which keeps deployment simple and avoids SQLite extensions.
- If memory volume grows substantially, replace
VectorIndex with an ANN index or SQLite vector extension while preserving the MemoryManager API.
智能体记忆持久化
当智能体需要在会话间实现持久化记忆存储时使用此技能。
功能特性
- - 基于SQLite的持久化存储,支持文本、元数据和嵌入向量
- 记忆条目的增删改查操作
- 基于余弦相似度向量搜索的语义检索
- 记忆生命周期管理,包括过期清理功能
- 支持按用户、会话、类型和时间窗口进行筛选
项目结构
- - src/MemoryStore.ts:底层SQLite存储引擎
- src/VectorIndex.ts:对存储的嵌入向量进行向量相似度搜索
- src/MemoryManager.ts:供智能体使用的高级API
- src/types.ts:共享的TypeScript类型定义
使用模式
- 1. 通过指定SQLite路径创建MemoryManager实例。
- 使用内容、可选元数据和可选嵌入向量写入记忆。
- 按会话/用户查询记忆,或使用searchByVector()进行语义检索。
- 定期调用cleanupExpired()清理过期记忆。
注意事项
- - 嵌入向量以JSON数组形式存储在SQLite中。
- 向量搜索使用TypeScript基于余弦相似度实现,保持部署简洁性,避免依赖SQLite扩展。
- 若记忆量大幅增长,可在保持MemoryManagerAPI不变的前提下,将VectorIndex替换为ANN索引或SQLite向量扩展。