360 Secure SkillHub
360 安全技能中心

Agent Memory Persistence

提供 SQLite 持久化、记忆 CRUD、按用户/会话/时间过滤、向量余弦相似度检索和过期清理;嵌入以 JSON 数组存储,检索在 TypeScript 内实现,未包含嵌入生成或 ANN 索引。

imgolye
imgolye
热度 74.77
最近更新 2026-05-11 17:29:24
分类:知识依赖:代码执行 / 读写文件应用场景:笔记整理 / 工作流 / 数据处理

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add agent-memory-persistence
Metadata
name
agent-memory-persistence
description
Provide long-term memory persistence for AI agents with SQLite-backed storage, structured metadata, vector embeddings, semantic retrieval, lifecycle management, and queries by user, session, and time.

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
  • src/VectorIndex.ts: vector similarity search over stored embeddings
  • src/MemoryManager.ts: high-level API used by agents
  • src/types.ts: shared TypeScript contracts

Usage pattern

  1. Create a MemoryManager with a SQLite path.
  2. Write memories with content, optional metadata, and optional embedding.
  3. Query memories by session/user or use searchByVector() for semantic lookup.
  4. 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.