Skip to main content

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

Metadata

Release files for llm-memory 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-memory 0.2.1
File Size Uploaded
llm_memory-0.2.1.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-memory 0.2.1
File Interpreter ABI Platform
llm_memory-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.5 kB

Release files / llm_memory-0.2.1.tar.gz

Download URL llm_memory-0.2.1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
35826dfe875b2822ad9afed17884b4a38b3995426dac95454dd08bef4c69a214
BLAKE2b-256 checksum
How to use checksums
cb61ef761ad4bbec5328663c804bdec99c9ebb53fabbcfe4df5b9c463a4c0fcb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.6

Release files / llm_memory-0.2.1-py3-none-any.whl

Download URL llm_memory-0.2.1-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b9ef8b9255922306273c6caa5d7f045b9fdec72ce21927e1e49e7c660af9173d
BLAKE2b-256 checksum
How to use checksums
7bee83a072aa3db6e8e51f75c6369c63a124dee6a57cb462d9b7f8131cbcd9f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page