A memory management system for large language models
Project description
LLM Memory
一个专为大语言模型设计的记忆管理系统,支持基于重要性的记忆筛选和持久化存储。
安装
使用以下命令安装:
pip install llm-memory
使用示例:
from llm_memory import CombinedMemory
# 初始化记忆系统
memory = CombinedMemory(
max_size=100, # 最大记忆容量
system_prompt="你是一个助手", # 系统提示词
uid="user123", # 用户ID,用于数据库存储
recent_size=20 # 保留最近对话轮数
)
# 添加消息
memory.add_message("user", "你好", importance=1)
memory.add_message("assistant", "你好!有什么我可以帮你的吗?", importance=1)
# 获取上下文
context = memory.get_context()
# 保存到数据库
memory.save_memory_to_db()
参数说明:
- system_prompt: 系统提示词,可选
- uid: 用户唯一标识,用于数据库存储,可选
- max_size: 最大记忆容量,必需
- recent_size: 保留最近对话轮数,默认为20轮
特性:
- 基于重要性的记忆管理
- 自动保持最近的对话(可配置保留轮数)
- 支持数据库持久化
- 可配置的系统提示词
数据持久化:
当提供 uid 参数时,会自动将对话历史保存到本地数据库(使用 TinyDB)。数据库文件默认保存为 memory.json。
依赖:
Python >= 3.7 tinydb >= 4.7.0
许可证:
MIT License
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
llm_memory-0.2.1.tar.gz
(4.3 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 llm_memory-0.2.1.tar.gz.
File metadata
- Download URL: llm_memory-0.2.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35826dfe875b2822ad9afed17884b4a38b3995426dac95454dd08bef4c69a214
|
|
| MD5 |
dc06a721ae4459e1e4bad2983bd7efa0
|
|
| BLAKE2b-256 |
cb61ef761ad4bbec5328663c804bdec99c9ebb53fabbcfe4df5b9c463a4c0fcb
|
File details
Details for the file llm_memory-0.2.1-py3-none-any.whl.
File metadata
- Download URL: llm_memory-0.2.1-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9ef8b9255922306273c6caa5d7f045b9fdec72ce21927e1e49e7c660af9173d
|
|
| MD5 |
76189e31e8c185b836c07ef4c3cce08b
|
|
| BLAKE2b-256 |
7bee83a072aa3db6e8e51f75c6369c63a124dee6a57cb462d9b7f8131cbcd9f8
|