A memory management system for large language models
Project description
LLM Memory
一个专为大语言模型设计的记忆管理系统,支持基于重要性的记忆筛选和持久化存储。
安装
使用以下命令安装: pip install llm-memory
使用示例:
from llm_memory import CombinedMemory
初始化记忆系统
memory = CombinedMemory( system_prompt="你是一个助手", # 系统提示词 uid="user123", # 用户ID,用于数据库存储 max_size=100, # 最大记忆容量 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
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.0.tar.gz.
File metadata
- Download URL: llm_memory-0.2.0.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 |
c444d90884718d2082821dc5fa96ee9c0b54e025420fc9115761ca42c550ffd2
|
|
| MD5 |
4619639870c498eaf448c0f6f6d43248
|
|
| BLAKE2b-256 |
ee0a6ce9eb6f306e24b98a9cc916bc48860d1df59932c176e52753cece54043b
|
File details
Details for the file llm_memory-0.2.0-py3-none-any.whl.
File metadata
- Download URL: llm_memory-0.2.0-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 |
ee4d46139a2ec6481de951b0d21a72f3de264938a1eaf5e8b5e2d1e62d563aae
|
|
| MD5 |
fa8cf5ee2376e95031c5b18daa6792bf
|
|
| BLAKE2b-256 |
6d004a6ba2dde0660f9ac5616f503f4a032b22eea1c7ef285a50128dda50317d
|