home / skills / bahayonghang / my-claude-code-settings / memory-system

This skill enables cross-session memory via a local Markdown/indexed SQLite, providing fast memory search, add, and prune workflows.

npx playbooks add skill bahayonghang/my-claude-code-settings --skill memory-system

Review the files below or copy the command above to add this skill to your agents.

Files (4)
SKILL.md
2.2 KB
---
name: memory-system
description: "本地记忆系统,将 Markdown 文件索引到 SQLite 实现跨会话语义搜索。当用户提到:记忆、memory、知识库、索引笔记、搜索记忆、跨会话记忆、记住这个、memory search、memory index、memory status、回忆、查找记忆 时触发。支持增量索引、混合搜索(向量+全文)、记忆添加和清理。"
category: knowledge-management
tags:
  - memory
  - search
  - knowledge-base
  - sqlite
  - vector-search
  - semantic-search
  - indexing
---

# Memory System

脚本路径: `~/.claude/skills/public/memory-system/scripts/memory.py`

## 自动行为

### 当用户说"搜索记忆"或"在记忆中查找 X"

```bash
python3 ~/.claude/skills/public/memory-system/scripts/memory.py search "用户的查询" \
  --db ./memory/memory.sqlite --json --top 6
```

读取 JSON 结果后,用搜索到的上下文回答用户问题。如果数据库不存在,先执行索引。

### 当用户说"记住这个"或"添加到记忆"

将内容写入 `memory/` 目录的 .md 文件:

```bash
python3 ~/.claude/skills/public/memory-system/scripts/memory.py add "内容" \
  --file 合适的文件名.md --dir ./memory --db ./memory/memory.sqlite
```

### 当用户说"索引记忆"或"更新记忆索引"

```bash
python3 ~/.claude/skills/public/memory-system/scripts/memory.py index \
  --dir ./memory --db ./memory/memory.sqlite
```

### 当用户说"记忆状态"或"memory status"

```bash
python3 ~/.claude/skills/public/memory-system/scripts/memory.py status \
  --db ./memory/memory.sqlite -v
```

### 当用户说"清理记忆"

```bash
python3 ~/.claude/skills/public/memory-system/scripts/memory.py cleanup \
  --days 90 --dir ./memory --force
```

## 首次使用

如果运行脚本报 `ModuleNotFoundError`,安装依赖:

```bash
pip3 install sentence-transformers numpy
```

## 注意事项

- `./memory/` 和 `--db` 路径相对于项目工作目录
- 索引是增量的(SHA256 哈希比对),重复运行不会重新处理未变化的文件
- 搜索只查 SQLite,不读源文件
- `--json` 输出适合程序解析,不加则人类可读
- 详细配置参考: [references/config.md](references/config.md)

Overview

This skill provides a local memory system that indexes Markdown files into a SQLite-backed store to enable cross-session semantic search. It supports incremental indexing, hybrid search (vector + full-text), adding and cleaning memories, and program-friendly JSON output. The system is optimized for repeatable, fast lookups without reprocessing unchanged files.

How this skill works

The skill scans a memory directory of .md files, computes content hashes, extracts embeddings, and stores metadata and vectors in a SQLite database for hybrid semantic + keyword search. Commands allow adding new notes, running an incremental index, performing JSON search queries, checking status, and cleaning old entries. Searches read only from the database (not source files) and return structured JSON suitable for programmatic consumption.

When to use it

  • You need cross-session recall of user facts, notes, or context.
  • You want fast semantic search over Markdown notes without a remote service.
  • You need to add single items programmatically or via a conversational trigger.
  • You want to periodically clean or audit old memories.
  • You need machine-readable JSON search results for automated workflows.

Best practices

  • Keep memory files as small, focused Markdown notes to improve relevance and retrieval speed.
  • Use the incremental index frequently; unchanged files are skipped via SHA256 hashing to save work.
  • Run searches against the SQLite DB (not source files) to get deterministic, fast responses.
  • Enable JSON output for downstream automation and use human-readable output for manual review.
  • Regularly run status and cleanup to keep the database size manageable and remove stale entries.

Example use cases

  • Save a user preference or profile snippet when they say “remember this” and recall it in a later session.
  • Index a project’s meeting notes folder and ask semantic queries like “what decisions were made about X?”
  • Automate ingestion from other tools by writing .md files into the memory directory and triggering an incremental index.
  • Run periodic cleanup to remove notes older than N days and audit memory health with the status command.
  • Integrate JSON search responses into a chat agent flow to provide context-aware replies without reading all files at runtime.

FAQ

What happens if the database is missing when I run a search?

If the SQLite DB does not exist, the index command will run first to create it and ingest files before performing the search.

How does incremental indexing avoid reprocessing files?

Files are hashed with SHA256 and the index checks stored hashes; unchanged files are skipped so only modified or new files are processed.