Skip to main content

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())

核心概念

五层记忆sensoryworkingshort_termlong_termarchive

  • 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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

memoria_framework-0.3.6.tar.gz (9.6 MB view details)

Uploaded Source

Built Distribution

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

memoria_framework-0.3.6-py3-none-any.whl (72.3 kB view details)

Uploaded Python 3

File details

Details for the file memoria_framework-0.3.6.tar.gz.

File metadata

  • Download URL: memoria_framework-0.3.6.tar.gz
  • Upload date:
  • Size: 9.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for memoria_framework-0.3.6.tar.gz
Algorithm Hash digest
SHA256 9cdf8213a90fa8459e23d5f0eedb1c84ce5382145263452eb8b6cb2331a4169c
MD5 442bdabb018797fe6cba9a65fa38616a
BLAKE2b-256 a36a2bb2488e3745ba889da4b4f8182fb72f64651a6a921671ab69c876982f92

See more details on using hashes here.

File details

Details for the file memoria_framework-0.3.6-py3-none-any.whl.

File metadata

File hashes

Hashes for memoria_framework-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f0d4f212d6b6712b1a98f09610686fb352e6e11b2edfd4b8090c251e4fcd0d4c
MD5 33f45aa45e8e71f4c790c2532800d575
BLAKE2b-256 299a201eaa470ca17e57bc4569aa82ec544e0c80176b393967eef6f0e1939adf

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 Sentry Error logging StatusPage Status page