Skip to main content

轻量级 AI 记忆系统

Project description

PalaceLite

License: MIT Python 3.9+ Version PyPI version

轻量级 AI 记忆系统,灵感来自MemPalace。默认离线运行,数据完全本地化。

核心概念

采用三层结构组织记忆:Wing(项目或人)→ Room(具体话题)→ Drawer(记忆条目)。每条记忆存储原文和向量,支持混合检索(向量相似度 + 时间衰减 + 重要性加权)。

安装

git clone https://github.com/fajknli/palacelite.git
cd palacelite
pip install -e .
pip install -r requirements.txt

或者:

pip install palacelite

首次使用需下载嵌入模型(约百MB,BAAI/bge-small-zh-v1.5),添加 --online 参数即可自动下载,之后可永久离线运行。

快速开始

CLI

# 添加记忆
palacelite add -w default -r chat -c "用户喜欢 PostgreSQL"

# 搜索
palacelite search -q "数据库"

# 带记忆对话(需要 GGUF 模型)
palacelite chat -m /path/to/model.gguf -w default -r chat

# 列出活跃记忆
palacelite list

# 归档超过90天且重要性低于2的记忆
palacelite archive-old --days 90 --importance 2

# 导出已归档记忆(自动保存到 ~/.palacelite/exports/)
palacelite export-archived

# 永久删除已归档记忆
palacelite delete-archived

# 统计
palacelite stats

Python API

from palacelite import PalaceLite

p = PalaceLite()  # 默认离线,offline=False 可联网下载模型

p.add_memory("用户喜欢 PostgreSQL", "default", "chat")
results = p.search("数据库")
context = p.build_context("数据库选型")  # 构建 LLM 上下文

验证安装:

python -c "from palacelite import PalaceLite; print('OK')"

带记忆对话

examples/ 目录提供了完整的对话示例:

# 离线模式(默认)
python examples/chat.py -m /path/to/model.gguf

# 联网模式(首次下载嵌入模型)
python examples/chat.py -m /path/to/model.gguf --online

# 指定 GPU 层数
python examples/chat.py -m /path/to/model.gguf -g 30

对话命令:/help/mem/list/stats/clear/quit

命令速查

命令 说明
add -w <wing> -r <room> -c <内容> 添加记忆
search -q <关键词> 搜索记忆
chat -m <模型> -w <wing> -r <room> 带记忆对话
list [-w wing] [-r room] 列出活跃记忆
archive-old [--days 90] [--importance 2] 批量归档旧记忆
list-archived 列出已归档记忆
export-archived [-o 路径] 导出归档到 JSON
delete-archived 永久删除归档记忆
stats 显示统计信息
wings 列出所有 Wing
rooms <wing> 列出指定 Wing 下的 Room

配置

环境变量 默认值 说明
PALACE_MODEL_PATH - GGUF 模型文件路径
PALACE_MODEL_DIR ~/Public/ai/models 模型存放目录
GPU_LAYERS 20 GPU 加速层数

工作目录默认为 ~/.palacelite,可通过 PalaceLite(workspace="/path") 自定义。

数据维护

导出数据清洗(用于微调):

python scripts/clean_memories.py ~/backup.json ~/cleaned.json

更换嵌入模型后重建向量库:

python scripts/rebuild_embeddings.py

许可证

MIT

Project details


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.4.1.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

palacelite-0.4.1-py3-none-any.whl (24.9 kB view details)

Uploaded Python 3

File details

Details for the file palacelite-0.4.1.tar.gz.

File metadata

  • Download URL: palacelite-0.4.1.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for palacelite-0.4.1.tar.gz
Algorithm Hash digest
SHA256 3d6cd00e1c06df065da199c96b6dd75af598e9f6b7726a085cfb159006e982f4
MD5 3487c586a2e3fc2be4bbdcaf054fc387
BLAKE2b-256 f4aa1da6de919f95c1c1932f96ee5353385c7205d53251bbc9d0abd24b1096d7

See more details on using hashes here.

File details

Details for the file palacelite-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: palacelite-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 24.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for palacelite-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5b3855f61fd30457919010d40e9855dcc5435d85c19588fe36a4059527c13936
MD5 acd73a43c8021e98ed27dd98f5614edd
BLAKE2b-256 4af34fc5dbd2bed4dac953533d9abac1661b960a8e4a805c6e319cec70de4715

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page