agentic_huge_data_base / wiki
页面 Mem0 · 7.1 托管平台总览·DeepWiki 中文全文译文

7.1 · 托管平台总览(Hosted Platform Overview)

长期记忆与上下文管理 · 聚焦本章的模块关系、源码依据与实现要点。

项目Mem0 章节7.1 状态全文译文 模块系统架构、界面与交互、认证、权限与安全、检索、召回与索引
源码线索
  • docs/api-reference/organizations-projects.mdx
  • docs/changelog/highlights.mdx
  • docs/changelog/platform.mdx
  • docs/core-concepts/memory-operations/add.mdx
  • docs/core-concepts/memory-operations/delete.mdx
  • docs/core-concepts/memory-operations/search.mdx
  • docs/core-concepts/memory-operations/update.mdx
  • docs/core-concepts/memory-types.mdx
  • docs/open-source/configuration.mdx
  • docs/open-source/overview.mdx
模块标签
  • 系统架构
  • 界面与交互
  • 认证、权限与安全
  • 检索、召回与索引
  • 接口与服务契约

章节正文

托管平台总览

托管平台概述

相关源文件

本章引用的主要源码文件:

  • docs/api-reference/organizations-projects.mdx
  • docs/changelog/highlights.mdx
  • docs/changelog/platform.mdx
  • docs/core-concepts/memory-operations/add.mdx
  • docs/core-concepts/memory-operations/delete.mdx
  • docs/core-concepts/memory-operations/search.mdx
  • docs/core-concepts/memory-operations/update.mdx
  • docs/core-concepts/memory-types.mdx
  • docs/open-source/configuration.mdx
  • docs/open-source/overview.mdx
  • docs/platform/advanced-memory-operations.mdx
  • docs/platform/features/memory-decay.mdx
  • docs/platform/features/platform-overview.mdx
  • docs/platform/overview.mdx

Mem0 平台是一个完全托管的云服务,为 AI 应用提供生产就绪的记忆层。它消除了管理向量数据库、图存储或基于大语言模型(LLM)的提取管线等基础设施的需求。该平台通过高性能 REST API 在 https://api.mem0.ai 上提供访问,并支持多租户、Webhook 和自动记忆衰减等高级功能。

平台架构

该平台采用托管客户端-服务器模型。应用程序使用 MemoryClientAsyncMemoryClient 与托管 API 通信,后者在分布式存储和处理层之间编排记忆生命周期。

系统组件与数据流
Mem0 · 系统组件与数据流 · 图 1
Mem0 · 系统组件与数据流 · 图 1

来源: mem0/client/main.py:36-109, docs/platform/overview.mdx:7-15, docs/platform/features/memory-decay.mdx:37-45

自然语言到代码映射:平台操作

下图将高级平台概念映射到实现它们的特定代码实体和 API 端点。

Mem0 · 自然语言到代码映射:平台操作 · 图 2
Mem0 · 自然语言到代码映射:平台操作 · 图 2

来源: mem0/client/main.py:137-175, mem0/client/main.py:251-295, mem0/client/main.py:448-489, docs/platform/features/memory-decay.mdx:61-75

认证与初始化

该平台使用基于 API 密钥的认证。在初始化期间,MemoryClient 会执行一次校验检查以获取项目上下文。

初始化序列
  1. API 密钥解析:客户端会查找 api_key 参数,如果未提供,则回退到 MEM0_API_KEY 环境变量 mem0/client/main.py:70
  2. 用户 ID 生成:会创建 API 密钥的 MD5 哈希值作为唯一的 user_id,用于遥测 mem0/client/main.py:80
  3. HTTP 客户端设置:使用 Authorization 令牌和 Mem0-User-ID 请求头初始化 httpx.Client mem0/client/main.py:93-100
  4. 密钥校验:客户端调用 _validate_api_key(),该函数会访问 /v1/ping/ 端点 mem0/client/main.py:113-117
  5. 上下文注入:返回的 org_idproject_id 会存储在客户端实例上,用于限定请求范围 mem0/client/main.py:122-124

来源: mem0/client/main.py:49-111, mem0/client/main.py:113-135

多租户与作用域

该平台强制执行严格的层级结构:组织 > 项目 > 实体

作用域参数

所有记忆操作都可以使用 ENTITY_PARAMS 中定义的实体类型进行作用域限定 mem0/client/main.py:33

  • user_id:将记忆绑定到特定人类用户 docs/core-concepts/memory-types.mdx:23
  • agent_id:将记忆绑定到特定 AI 代理 docs/core-concepts/memory-types.mdx:24
  • app_id:将记忆作用域限定到特定应用程序实例。
  • run_id:将记忆作用域限定到特定会话或执行运行 docs/core-concepts/memory-types.mdx:80
过滤逻辑

平台搜索支持复杂的逻辑运算符(ANDOR)和字段级比较(ingtecontainsdocs/core-concepts/memory-operations/search.mdx:92-97

过滤示例代码实现
简单client.search(query, filters={"user_id": "alice"})
复杂client.search(query, filters={"OR": [{"user_id": "alice"}, {"agent_id": "bot"}]})

来源: mem0/client/main.py:33, docs/core-concepts/memory-operations/search.mdx:159-207

高级平台功能

1. 记忆衰减

记忆衰减是一种可选加入的排序偏差,它会强化近期访问过的记忆,并削弱过时的记忆 docs/platform/features/memory-decay.mdx:8

  • 机制:对相关性评分应用从 0.3x1.5x 的缩放因子 docs/platform/features/memory-decay.mdx:25
  • 强化:每次记忆在搜索中被返回时,其访问历史都会更新,从而提升其未来的排名 docs/platform/features/memory-decay.mdx:44
  • 激活:通过 client.project.update(decay=True) 启用 docs/platform/features/memory-decay.mdx:63
2. 异步客户端

对于高并发代理,AsyncMemoryClient 提供非阻塞操作 docs/platform/features/platform-overview.mdx:20

  • 用法await client.add(messages, user_id="...") docs/platform/advanced-memory-operations.mdx:80
  • 性能:将记忆提取和存储卸载到平台上的后台工作进程 docs/platform/overview.mdx:23
3. 托管图记忆

该平台提供托管图层,用于实体关系提取。

  • 提取:在 add 操作期间自动提取实体并建立链接 docs/changelog/highlights.mdx:34
  • 集成:将向量搜索与图遍历无缝结合,用于复杂查询 docs/platform/features/platform-overview.mdx:28
4. 企业治理
  • 审计日志:追踪工作空间内的活动和延迟 docs/platform/overview.mdx:15
  • 合规性:通过细粒度删除方法支持 GDPR/CCPA docs/core-concepts/memory-operations/delete.mdx:14
  • 通配符删除:通过将所有过滤器设置为 "*" 来显式清除项目 docs/core-concepts/memory-operations/delete.mdx:156

来源: docs/platform/features/memory-decay.mdx:7-46, docs/platform/advanced-memory-operations.mdx:35-41, docs/core-concepts/memory-operations/delete.mdx:139-179, docs/api-reference/organizations-projects.mdx:80-110

API 版本与规范化

该平台管理多个 API 版本,以确保向后兼容。

版本主要用例响应结构
v1项目与组织管理通常是原始列表或特定对象 mem0/client/main.py:774
v2实体与元数据操作标准化的结果包装器 mem0/client/main.py:441
v3高级记忆搜索标准化并包含置信度评分 docs/changelog/highlights.mdx:16

MemoryClient 会对响应进行规范化,确保如果端点返回原始列表,则会将其包装在 {"results": ...} 字典中,以保持一致性 mem0/client/main.py:247-249

来源: mem0/client/main.py:169-171, mem0/client/main.py:291-295, docs/changelog/highlights.mdx:10-16