Memoria
通用 AI Agent 记忆框架 —— 零成本起步,全功能扩展。
Memoria 为 AI Agent 提供多层级、多类型的长期记忆:从短时工作记忆到长期归档,覆盖 8 种记忆类型,并通过五管线上下文召回把「参考信息、用户画像、技能、情绪、约束」一次性交还给模型,让 Agent 跨会话保持连贯。
安装
pip install memoria
可选扩展:
| Extra | 说明 |
|---|---|
memoria[llm] |
LLM 驱动的类型自动分类(OpenAI 兼容接口) |
memoria[vector] |
向量检索(Qdrant) |
memoria[local-embed] |
本地向量嵌入(sentence-transformers) |
memoria[redis] |
Redis 存储后端 |
memoria[postgres] |
PostgreSQL 存储后端 |
memoria[all] |
全部扩展 |
快速开始
import asyncio
from memoria import MemoriaManager
from memoria.config import DictStoreConfig, MemoriaConfig
# 内存版配置(零依赖起步);持久化时把 DictStoreConfig 换成 MySQLStoreConfig 等
config = MemoriaConfig(
stores={
"working": DictStoreConfig(max_items=200, ttl_seconds=1800),
"short_term": DictStoreConfig(max_items=5000, ttl_seconds=0),
"long_term": DictStoreConfig(max_items=5000, ttl_seconds=0),
},
indexes={
"working": [],
"short_term": ["keyword", "temporal"],
"long_term": ["keyword", "temporal"],
},
default_layer="short_term",
)
async def main():
manager = MemoriaManager(config)
await manager.initialize()
memory_id = await manager.store(
"用户最喜欢的验证饮料是冷萃铁观音-0827",
types=["semantic"],
importance=0.6,
)
ctx = await manager.contextual_recall("用户最喜欢的验证饮料是什么")
print(ctx.to_prompt()) # 结构化的多管线召回上下文
print(await manager.stats()) # 各层记忆数量与生命周期分布
await manager.close()
asyncio.run(main())
核心概念
五层记忆(sensory → working → short_term → long_term → archive)
sensory:感知缓冲,短期原始输入working:工作记忆,当前任务上下文short_term:短期记忆,跨会话近期事实long_term:长期记忆,稳定知识与经验archive:归档,冷数据(通过query_archive检索)
八种记忆类型:episodic(事件)、semantic(事实)、procedural(流程/技能)、relational(关系)、affective(情绪)、spatial(空间)、social(用户画像)、meta(规则/约束)。
五管线上下文召回:contextual_recall() 聚合 reference / profile / skills / emotion / constraints 五条管线,返回 MemoryContext。
主要 API
| 方法 | 说明 |
|---|---|
store(content, *, types, importance, ...) |
存入一条记忆,返回 memory_id |
recall(query, *, layers, types, ...) |
返回 list[MemoryRecord] |
contextual_recall(query, *, limit, ...) |
五管线召回,返回 MemoryContext |
forget(memory_id) / remember(memory_id) |
遗忘 / 恢复一条记忆 |
link(source_id, predicate, target_id) |
建立记忆间关系 |
stats() |
各层记忆计数与生命周期分布 |
DeepSeek Harness 集成
Memoria 提供 memoria.plugin_server(stdio JSON-RPC 服务),配合 dsh-memoria npm 插件,可作为 DeepSeek Harness 的原生长时记忆插件:每个会话自动注入召回上下文,无需显式调用召回工具。
pip install memoria
dsh plugin --profile web add dsh-memoria
License
MIT
Metadata
Release files for memoria-framework 0.3.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| memoria_framework-0.3.6.tar.gz | 9.6 MB | Without provenance | Details for memoria_framework-0.3.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| memoria_framework-0.3.6-py3-none-any.whl | Python 3 | none | any | Details for memoria_framework-0.3.6-py3-none-any.whl |
Total release size: 9.7 MB
Release files / memoria_framework-0.3.6.tar.gz
| Download URL | memoria_framework-0.3.6.tar.gz |
|---|---|
| Size | 9.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9cdf8213a90fa8459e23d5f0eedb1c84ce5382145263452eb8b6cb2331a4169c
|
|
BLAKE2b-256 checksum How to use checksums |
a36a2bb2488e3745ba889da4b4f8182fb72f64651a6a921671ab69c876982f92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / memoria_framework-0.3.6-py3-none-any.whl
| Download URL | memoria_framework-0.3.6-py3-none-any.whl |
|---|---|
| Size | 72.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f0d4f212d6b6712b1a98f09610686fb352e6e11b2edfd4b8090c251e4fcd0d4c
|
|
BLAKE2b-256 checksum How to use checksums |
299a201eaa470ca17e57bc4569aa82ec544e0c80176b393967eef6f0e1939adf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Security for memoria-framework 0.3.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.