agentic_huge_data_base / wiki
页面 Mem0 · 16.2 Embedchain 配置·DeepWiki 中文全文译文

16.2 · Embedchain 配置(Embedchain Configuration)

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

项目Mem0 章节16.2 状态全文译文 模块文档对象与元数据、记忆与上下文、模型调用与提供方适配、配置治理
源码线索
  • embedchain/docs/api-reference/app/add.mdx
  • embedchain/embedchain/chunkers/base_chunker.py
  • embedchain/embedchain/config/llm/base.py
  • embedchain/embedchain/config/model_prices_and_context_window.json
  • embedchain/embedchain/data_formatter/data_formatter.py
  • embedchain/embedchain/embedchain.py
  • embedchain/embedchain/loaders/base_loader.py
  • embedchain/embedchain/loaders/web_page.py
  • embedchain/embedchain/vectordb/chroma.py
  • embedchain/poetry.lock
模块标签
  • 文档对象与元数据
  • 记忆与上下文
  • 模型调用与提供方适配
  • 配置治理
  • 系统架构

章节正文

Embedchain 配置

Embedchain 配置

相关源文件

以下文件为本维基页面的生成提供了上下文:

  • embedchain/docs/api-reference/app/add.mdx
  • embedchain/embedchain/chunkers/base_chunker.py
  • embedchain/embedchain/config/llm/base.py
  • embedchain/embedchain/config/model_prices_and_context_window.json
  • embedchain/embedchain/data_formatter/data_formatter.py
  • embedchain/embedchain/embedchain.py
  • embedchain/embedchain/loaders/base_loader.py
  • embedchain/embedchain/loaders/web_page.py
  • embedchain/embedchain/vectordb/chroma.py
  • embedchain/poetry.lock
  • embedchain/pyproject.toml
  • embedchain/tests/llm/test_openai.py
  • embedchain/tests/loaders/test_web_page.py

本文档描述了 Mem0 代码库中旧版 Embedchain 组件的配置系统。Embedchain 提供了一种结构化的配置方法,用于定义应用行为、数据库连接、大语言模型(LLM)提供商、嵌入器(Embedder)和向量存储(Vector Store)。

适用范围:本页面涵盖 Embedchain 特定的配置文件、兼容 YAML 的结构、组件级配置类以及数据库设置。有关现代 Mem0 配置,请参阅配置系统

配置架构

Embedchain 使用分层配置系统,其中 EmbedChain 类(定义于 embedchain/embedchain/embedchain.py:38)充当中央编排器。它通过应用、大语言模型(LLM)、向量数据库和嵌入器(Embedder)的配置对象进行初始化。

组件初始化流程

下图展示了 EmbedChain 类在初始化过程中如何将高级配置名称与特定代码实体关联起来。

Mem0 · 组件初始化流程 · 图 1
Mem0 · 组件初始化流程 · 图 1

来源embedchain/embedchain/embedchain.py:38-62embedchain/embedchain/config/llm/base.py:111-142

大语言模型(LLM)配置

BaseLlmConfig 类管理语言模型交互的参数。它包含随机性、Token 限制和提示模板的设置。

BaseLlmConfig 的关键参数
参数类型默认值描述
number_documentsint3要检索的上下文文档数量 embedchain/embedchain/config/llm/base.py:118
modelstrNone具体的模型 ID(例如 gpt-4o-miniembedchain/embedchain/config/llm/base.py:121
temperaturefloat0控制随机性(0 表示确定性)embedchain/embedchain/config/llm/base.py:122
max_tokensint1000生成的最大 Token 数 embedchain/embedchain/config/llm/base.py:123
streamboolFalse启用响应流式传输 embedchain/embedchain/config/llm/base.py:125
system_promptstrNone自定义系统指令 embedchain/embedchain/config/llm/base.py:129
token_usageboolFalse是否返回 Token 使用量和成本 embedchain/embedchain/config/llm/base.py:127
默认提示模板

Embedchain 提供了几个内置的提示模板来指导大语言模型(LLM)的行为:

  • 标准问答DEFAULT_PROMPT embedchain/embedchain/config/llm/base.py:15-29
  • 带历史记录DEFAULT_PROMPT_WITH_HISTORY embedchain/embedchain/config/llm/base.py:31-52
  • Mem0 增强DEFAULT_PROMPT_WITH_MEM0_MEMORY embedchain/embedchain/config/llm/base.py:54-81
  • 开发者支持DOCS_SITE_DEFAULT_PROMPT embedchain/embedchain/config/llm/base.py:83-99

来源embedchain/embedchain/config/llm/base.py:111-142embedchain/embedchain/config/llm/base.py:15-104

向量数据库配置

Embedchain 支持多种向量存储,其中 ChromaDB 是主要实现。配置涉及设置持久化目录和连接参数。

ChromaDB 配置示例

ChromaDBembedchain/embedchain/vectordb/chroma.py:29 使用 ChromaDbConfig 来初始化客户端。它支持本地持久化和基于服务器的连接 embedchain/embedchain/vectordb/chroma.py:51-62

Mem0 · ChromaDB 配置示例 · 图 2
Mem0 · ChromaDB 配置示例 · 图 2

来源embedchain/embedchain/vectordb/chroma.py:32-64embedchain/embedchain/vectordb/chroma.py:94-110

数据入库配置

通过 EmbedChain.add() 添加数据时,系统会使用 DataFormatter 根据 DataType 确定正确的加载器(Loader)和片段切分器(Chunker)。

入库数据流
  1. 检测:系统检测源的 DataType embedchain/embedchain/embedchain.py:162-181
  2. 映射DataFormatterDataType 映射到特定的 BaseLoaderBaseChunker embedchain/embedchain/data_formatter/data_formatter.py:34-35
  3. 加载:加载器(例如 WebPageLoader)获取原始内容并生成 doc_id embedchain/embedchain/loaders/web_page.py:15-32
  4. 片段切分:片段切分器将内容分割成可管理的片段,按 min_chunk_size 过滤,并生成唯一的 chunk_idembedchain/embedchain/chunkers/base_chunker.py:18-74
支持的数据类型(部分列表)
  • PDF_FILE:使用 PdfFileLoaderPdfFileChunker embedchain/embedchain/data_formatter/data_formatter.py:63,111
  • WEB_PAGE:使用 WebPageLoaderWebPageChunker embedchain/embedchain/data_formatter/data_formatter.py:64,112
  • JSON:使用 JSONLoaderJSONChunker embedchain/embedchain/data_formatter/data_formatter.py:75,123
  • GMAIL:使用 GmailLoaderGmailChunker embedchain/embedchain/data_formatter/data_formatter.py:77,125

来源embedchain/embedchain/embedchain.py:117-154embedchain/embedchain/data_formatter/data_formatter.py:61-91embedchain/embedchain/chunkers/base_chunker.py:18-74

模型元数据和定价

Embedchain 在 model_prices_and_context_window.json 中维护了一个模型能力注册表,包括上下文窗口大小和定价。

模型 ID最大输入 Token 数最大输出 Token 数输入成本(每 Token)
openai/gpt-4o128,0004,096$0.000005 embedchain/embedchain/config/model_prices_and_context_window.json:13
openai/gpt-4o-mini128,0004,096$0.00000015 embedchain/embedchain/config/model_prices_and_context_window.json:20
openai/text-embedding-3-large8,191不适用(向量:3072)$0.00000013 embedchain/embedchain/config/model_prices_and_context_window.json:157
openai/gpt-3.5-turbo-012516,3854,096$0.0000005 embedchain/embedchain/config/model_prices_and_context_window.json:136

来源embedchain/embedchain/config/model_prices_and_context_window.json:9-22embedchain/embedchain/config/model_prices_and_context_window.json:153-159embedchain/embedchain/config/model_prices_and_context_window.json:132-138

环境和依赖

旧版 Embedchain 系统依赖于几个可选的额外组件来支持特定提供商,这些组件通过 pyproject.toml 进行管理。

  • 开源sentence-transformerstorchgpt4all embedchain/pyproject.toml:161
  • 向量存储qdrant-clientchromadbpymilvuslancedb embedchain/pyproject.toml:101,121,122,162
  • 云提供商google-cloud-aiplatformlangchain-awslangchain-google-vertexai embedchain/pyproject.toml:123,143,169
  • 集成gmail(google-api-python-client)、notionslack embedchain/pyproject.toml:171-178

来源embedchain/pyproject.toml:95-144embedchain/pyproject.toml:160-185