轻量级 AI 记忆系统
Project description
PalaceLite
轻量级 AI 记忆系统,灵感来自 MemPalace。默认离线运行,数据完全本地化。
安装
pip install palacelite
首次使用需下载嵌入模型(约 100MB),添加 --online 参数即可自动下载,之后可永久离线运行:
palacelite chat -m /path/to/model.gguf --online
核心概念
采用三层结构组织记忆:
- Wing:项目或人
- Room:具体话题
- Drawer:记忆条目
每条记忆存储原文和向量,支持混合检索(向量相似度 + 关键词匹配 + 时间衰减 + 重要性加权)。
快速开始
CLI 命令
# 添加记忆
palacelite add -w default -r chat -c "用户喜欢 PostgreSQL"
# 搜索记忆
palacelite search -q "数据库"
# 带记忆对话
palacelite chat -m /path/to/model.gguf -w default -r chat
# 列出活跃记忆
palacelite list
# 统计信息
palacelite stats
# 列出所有 Wing
palacelite wings
# 列出指定 Wing 下的 Room
palacelite rooms default
Python API
from palacelite import PalaceLite
p = PalaceLite() # 默认离线,offline=False 可联网下载模型
# 添加记忆
p.add_memory("用户喜欢 PostgreSQL", "default", "chat")
# 搜索
results = p.search("数据库")
# 构建 LLM 上下文
context = p.build_context("数据库选型")
对话模式
# 首次使用(下载嵌入模型)
palacelite chat -m /path/to/model.gguf --online
# 日常使用
palacelite chat -m /path/to/model.gguf
# 指定 GPU 层数
palacelite chat -m /path/to/model.gguf -g 30
# 使用提炼模型压缩记忆(推荐 3B 小模型,如 Qwen2.5-3B-Instruct)
palacelite chat -m /path/to/model.gguf --distiller-model /path/to/small.gguf
# 手动指定 prompt 模板(支持 qwen/gemma/llama/mistral)
palacelite chat -m /path/to/model.gguf --prompt-template qwen
对话内命令
| 命令 | 说明 |
|---|---|
/help |
显示帮助 |
/mem <关键词> |
搜索记忆 |
/add <内容> |
手动添加记忆 |
/list [数量] |
列出最近记忆 |
/stats |
显示统计信息 |
/clear |
清屏 |
/quit |
退出对话 |
记忆维护
归档旧记忆
# 归档超过 90 天且重要性低于 2 的记忆
palacelite archive-old --days 90 --importance 2
# 列出已归档记忆
palacelite list-archived
# 导出归档记忆到 JSON
palacelite export-archived
# 永久删除归档记忆
palacelite delete-archived
数据清洗与重建
# 清洗导出数据(用于微调)
python scripts/clean_memories.py ~/backup.json ~/cleaned.json
# 更换嵌入模型后重建向量库
python scripts/rebuild_embeddings.py
命令速查
| 命令 | 说明 |
|---|---|
add -w <wing> -r <room> -c <内容> |
添加记忆 |
search -q <关键词> |
搜索记忆 |
chat -m <模型路径> |
启动对话 |
list [-w wing] [-r room] |
列出活跃记忆 |
stats |
显示统计信息 |
wings |
列出所有 Wing |
rooms <wing> |
列出 Wing 下的 Room |
archive-old [--days 90] [--importance 2] |
批量归档 |
list-archived |
列出已归档记忆 |
export-archived [-o 路径] |
导出归档 |
delete-archived |
删除归档 |
配置
| 环境变量 | 默认值 | 说明 |
|---|---|---|
PALACE_MODEL_PATH |
- | GGUF 模型文件路径 |
PALACE_MODEL_DIR |
~/Public/ai/models |
模型存放目录 |
GPU_LAYERS |
20 |
GPU 加速层数 |
工作目录默认为 ~/.palacelite,可通过 PalaceLite(workspace="/path") 自定义。
架构
当前版本 (0.5.1) 已完成:
- SQLite-vec 向量存储,无需外部向量数据库
- 异步记忆提炼(Distiller),支持技术参数原样保留
- 混合检索:向量相似度 + 关键词匹配 + 时间衰减 + 重要性加权
- 关系图谱 Schema(relations、patrol_queue),为后续版本做准备
- 记忆归档与导出
- 对话内手动添加记忆(
/add) - 自动 prompt 模板检测
许可证
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
palacelite-0.5.1.tar.gz
(28.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file palacelite-0.5.1.tar.gz.
File metadata
- Download URL: palacelite-0.5.1.tar.gz
- Upload date:
- Size: 28.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fccbe42fd490f665e2512a32545770342c99b4c1889a436d847a14412d14558
|
|
| MD5 |
9380c00cb586d3752ae86d44d7812501
|
|
| BLAKE2b-256 |
0dd12785b4f58c5125805618b1eb1362816dbfa7822b2c3fa29339d6bc13f2f0
|
File details
Details for the file palacelite-0.5.1-py3-none-any.whl.
File metadata
- Download URL: palacelite-0.5.1-py3-none-any.whl
- Upload date:
- Size: 31.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f3bcdd0339281bfe4fe3ca27ea2808fbe7c4d4dab677ed2bd1047c822505f62
|
|
| MD5 |
cb61258933d6d08575ecb0c3cef1c10a
|
|
| BLAKE2b-256 |
4e5c89833f355a56dcfbd03d8697781b74082438db2c748bbe3c90911a764643
|