Pidan Memory Skill

本地持久化向量记忆系统,为 AI Assistant 提供长期记忆能力。支持多用户/共享模式。

3,891 stars

Best use case

Pidan Memory Skill is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

本地持久化向量记忆系统,为 AI Assistant 提供长期记忆能力。支持多用户/共享模式。

Teams using Pidan Memory Skill should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/pidan-memory/SKILL.md --create-dirs "https://raw.githubusercontent.com/openclaw/skills/main/skills/2830201534/pidan-memory/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/pidan-memory/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How Pidan Memory Skill Compares

Feature / AgentPidan Memory SkillStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

本地持久化向量记忆系统,为 AI Assistant 提供长期记忆能力。支持多用户/共享模式。

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# Pidan Memory Skill

本地持久化向量记忆系统,为 AI Assistant 提供长期记忆能力。支持多用户/共享模式。

## 概述

基于 **LanceDB + Ollama** 实现的本地向量记忆系统,支持语义搜索和多用户隔离。

## 架构

```
用户输入 → Ollama (向量化) → LanceDB (存储/搜索)
                    ↑
              nomic-embed-text (768维向量)
```

## 功能

### 1. 自动记忆(推荐)

**安装 Hook 后自动生效,无需手动调用!**

每次对话后自动评估并存储重要信息,覆盖 16 大类场景。

**安装方式:**
```bash
# 1. 复制文件
mkdir -p ~/.openclaw/hooks/pidan-memory
cp HOOK.md handler.ts ~/.openclaw/hooks/pidan-memory/
cp auto_memory.py ~/.openclaw/workspace/memory/

# 2. 启用
openclaw hooks enable pidan-memory
openclaw gateway restart
```

### 2. 记住信息 (remember)

手动存储重要信息到向量数据库

**参数:**
- `content`: 记忆内容 (必填)
- `summary`: 摘要 (可选)
- `importance`: 重要程度 1-5 (默认 3)
- `user_id`: 用户 ID (默认 default)

**示例:**
```json
{
  "command": "remember",
  "parameters": {
    "content": "用户最喜欢吃火锅",
    "summary": "饮食偏好",
    "importance": 4,
    "user_id": "default"
  }
}
```

### 3. 搜索记忆 (recall)

语义向量搜索

**参数:**
- `query`: 搜索关键词
- `limit`: 返回数量 (默认 5)
- `user_id`: 用户 ID

### 4. 获取最近记忆 (recent_memories)

获取用户的有权限访问的记忆

### 5. 模式管理

#### 获取当前模式 (get_mode)
```json
{
  "command": "get_mode",
  "parameters": {}
}
```

#### 设置模式 (set_mode)
```json
{
  "command": "set_mode",
  "parameters": {
    "mode": "private"  // 或 "shared"
  }
}
```

**模式说明:**
- `private`: 多用户模式(默认),每个用户记忆独立隔离
- `shared`: 共享模式,所有用户可互相查询共享记忆

### 6. 删除记忆 (delete_memory)

删除记忆(需二次确认,只有创建人可删除)

**参数:**
- `memory_id`: 记忆 ID (必填)
- `confirm`: 是否确认删除 (默认 false)

**首次请求(获取确认):**
```json
{
  "command": "delete_memory",
  "parameters": {
    "memory_id": "uuid-xxx",
    "confirm": false
  }
}
```

**确认删除:**
```json
{
  "command": "delete_memory",
  "parameters": {
    "memory_id": "uuid-xxx",
    "confirm": true
  }
}
```

**权限规则:**
- ✅ 创建人本人可以删除
- ❌ 非创建人无法删除
- ⚠️ 删除前必须二次确认

### 7. 共享记忆 (share_memory)

将记忆共享给指定用户(只有创建人可以共享)

**参数:**
- `memory_id`: 记忆 ID (必填)
- `visible_to`: 可见用户列表 (默认 []) - 空=私有
- `user_id`: 请求者 ID (用于权限校验)

**示例 - 共享给指定用户:**
```json
{
  "command": "share_memory",
  "parameters": {
    "memory_id": "uuid-xxx",
    "visible_to": ["user_a", "user_b"],
    "user_id": "default"
  }
}
```

**示例 - 取消共享(设为私有):**
```json
{
  "command": "share_memory",
  "parameters": {
    "memory_id": "uuid-xxx",
    "visible_to": [],
    "user_id": "default"
  }
}
```

**权限规则:**
- ✅ 创建人本人可以共享
- ❌ 非创建人无法共享
- ⚠️ visible_to 为空时 = 私有模式

### 8. 列表记忆 (list_memories)

列出用户有权限访问的所有记忆

### 8. 手动去重 (deduplicate)

手动触发去重(每 20 条自动触发)

### 9. 统计 (stats)

获取记忆统计信息

## 配置

配置文件:`~/.openclaw/workspace/memory/config.yaml`

```yaml
memory:
  mode: private              # private | shared
  deduplicate_after: 20      # 每N条自动去重
```

或通过环境变量:
```bash
MEMORY_MODE=private
MEMORY_DEDUP_AFTER=20
```

## 存储位置

```
~/.openclaw/workspace/memory/lance/  # LanceDB 数据
```

## 技术栈

| 组件 | 作用 |
|------|------|
| LanceDB | 向量存储/搜索 |
| Ollama | 本地 embedding 模型 |
| nomic-embed-text | 768维向量 |

## CLI 测试

```bash
# 添加记忆
echo '{"command": "remember", "parameters": {"content": "测试"}}' | python3 run.py

# 搜索
echo '{"command": "recall", "parameters": {"query": "测试"}}' | python3 run.py

# 获取模式
echo '{"command": "get_mode", "parameters": {}}' | python3 run.py

# 设置模式
echo '{"command": "set_mode", "parameters": {"mode": "shared"}}' | python3 run.py

# 删除记忆(首次)
echo '{"command": "delete_memory", "parameters": {"memory_id": "xxx"}}' | python3 run.py
```

## 安全说明

### 用户身份验证

所有命令通过 **环境变量 `OPENCLAW_USER_ID`** 获取真实用户ID,防止伪造:

```bash
# 设置用户ID
export OPENCLAW_USER_ID=your_user_id
python3 run.py ...
```

### 权限控制

- **删除/共享记忆**:只有创建人可以操作
- **查询记忆**:根据模式(private/shared)决定访问权限
- **参数中的 user_id**:无效,必须通过环境变量

### Hook 模式

通过 Hook 自动触发时,用户ID由平台传递( DingTalk openid 等),自动注入环境变量。
```

Related Skills

Agent Memory Architecture

3891
from openclaw/skills

Complete zero-dependency memory system for AI agents — file-based architecture, daily notes, long-term curation, context management, heartbeat integration, and memory hygiene. No APIs, no databases, no external tools. Works with any agent framework.

memory-cache

3891
from openclaw/skills

High-performance temporary storage system using Redis. Supports namespaced keys (mema:*), TTL management, and session context caching. Use for: (1) Saving agent state, (2) Caching API results, (3) Sharing data between sub-agents.

General Utilities

Memory

3891
from openclaw/skills

Infinite organized memory that complements your agent's built-in memory with unlimited categorized storage.

Memory Management

auto-memory

3891
from openclaw/skills

Indestructible agent memory — permanently stored, never lost. Save decisions, identity, and context as a memory chain on the Autonomys Network. Rebuild your full history from a single CID, even after total state loss.

AI Persistence & Memory

Triple-Layer Memory System

3880
from openclaw/skills

三层记忆系统 - 解决 AI Agent 长对话记忆丢失和上下文管理问题

Memory & Context Management

agent-memory-os

3891
from openclaw/skills

Stop agents from "forgetting, mixing projects, and rotting over time" by giving them a practical memory operating system: global memory, project memory, promotion rules, validation cases, and a maintenance loop.

benos-memory-core

3891
from openclaw/skills

Core runtime/volatile memory module for BenOS agent environment. Use to: store and retrieve active session state, open loops, decisions, and scratch notes at runtime.

elite-longterm-memory

3891
from openclaw/skills

Ultimate AI agent memory system with WAL protocol, vector search, git-notes, and cloud backup. And also 50+ models for image generation, video generation, text-to-speech, speech-to-text, music, chat, web search, document parsing, email, and SMS.

memory-agent

3891
from openclaw/skills

维护用户审美偏好与创作历史,为其他 Agent 提供可复用的风格参考。当开始新任务或用户表达喜好时触发。

bamdra-memory-upgrade-operator

3891
from openclaw/skills

Safely install, uninstall, reinstall, or upgrade the Bamdra OpenClaw memory suite when stale config, existing plugin directories, or partial installs break normal `openclaw plugins install` flows.

hierarchical-memory

3891
from openclaw/skills

Manage and navigate a multi-layered, branch-based memory system. This skill helps organize complex agent context into Root, Domain, and Project layers to prevent context bloat. It includes a helper script `add_branch.py` which creates local markdown files and directories to structure your memory.

agentmemory

3891
from openclaw/skills

End-to-end encrypted cloud memory for AI agents. 100GB free storage. Store memories, files, and secrets securely.