GEO

Cognee开源知识引擎如何为AI智能体构建持久记忆?

2026/4/4
Cognee开源知识引擎如何为AI智能体构建持久记忆?
AI Summary (BLUF)

Cognee is an open-source knowledge engine that transforms unstructured data into AI memory through vector search and graph databases, enabling continuous learning and context-aware AI agents.

原文翻译: Cognee是一个开源知识引擎,通过向量搜索和图数据库将非结构化数据转化为AI记忆,实现持续学习和上下文感知的AI智能体。

关于 Cognee

Cognee 是一个开源知识引擎,允许您以任何格式或结构摄取数据,并持续学习,为 AI 智能体提供正确的上下文。它结合了向量搜索图数据库和认知科学方法,使您的文档既能通过含义进行搜索,又能随着变化和发展通过关系相互连接。

Cognee 是一个开源知识引擎,允许您以任何格式或结构摄取数据,并持续学习,为 AI 智能体提供正确的上下文。它结合了向量搜索图数据库和认知科学方法,使您的文档既能通过含义进行搜索,又能随着变化和发展通过关系相互连接。

:star: 帮助我们触达更多开发者,壮大 Cognee 社区。给这个仓库点个星吧!

:star: 帮助我们触达更多开发者,壮大 Cognee 社区。给这个仓库点个星吧!

:books: 查看我们详细的文档以进行设置和配置。

:books: 查看我们详细的文档以进行设置和配置。

:crab: 可作为 OpenClaw 的插件使用 — cognee-openclaw

:crab: 可作为 OpenClaw 的插件使用 — cognee-openclaw

为何选择 Cognee

Cognee 旨在为构建下一代 AI 应用提供坚实、可靠且可学习的基础设施。其核心价值体现在以下三个层面:

Cognee is designed to provide a solid, reliable, and learnable infrastructure for building next-generation AI applications. Its core value is reflected in the following three aspects:

  • 知识基础设施 — 统一的数据摄取、图/向量混合搜索、本地运行、本体论基础、多模态支持 (Knowledge Infrastructure — unified data ingestion, hybrid graph/vector search, local operation, ontological grounding, multimodal support)
  • 持久且可学习的智能体 — 从反馈中学习、上下文管理、跨智能体知识共享 (Persistent and Learning Agents — learn from feedback, context management, cross-agent knowledge sharing)
  • 可靠且可信的智能体 — 智能体级别的用户/租户隔离、可追溯性、OTEL 收集器、审计特性 (Reliable and Trustworthy Agents — agent-level user/tenant isolation, traceability, OTEL collector, audit traits)

产品特性概览

Cognee 提供了一套完整的工具集,涵盖从数据摄取、知识构建到智能体应用的全流程。

Cognee provides a complete set of tools covering the entire workflow from data ingestion and knowledge construction to agent applications.

功能模块 核心描述 关键技术
统一数据摄取 支持任意格式与结构的数据源 多模态解析器,自适应管道
混合知识图谱 结合向量语义与图关系进行搜索 向量数据库,图数据库,RAG 增强
持续学习引擎 智能体从交互反馈中进化 反馈循环,上下文记忆更新
企业级部署 支持多租户隔离与完整可观测性 OTEL,审计日志,安全沙箱

快速入门指南

让我们用几行代码快速体验 Cognee。

Let's quickly experience Cognee with just a few lines of code.

前提条件

  • Python 3.10 至 3.13
  • Python 3.10 to 3.13

步骤 1:安装 Cognee

您可以使用 pippoetryuv 或您喜欢的 Python 包管理器来安装 Cognee。

You can install Cognee using pip, poetry, uv, or your preferred Python package manager.

uv pip install cognee

步骤 2:配置大语言模型

设置您的 LLM API 密钥。以 OpenAI 为例:

Set up your LLM API key. Taking OpenAI as an example:

import os
os.environ["LLM_API_KEY"] = "YOUR_OPENAI_API_KEY"

或者,使用我们的模板创建一个 .env 文件。

Alternatively, create a .env file using our template.

要集成其他 LLM 提供商,请参阅我们的 LLM 提供商文档

To integrate other LLM providers, see our LLM Provider Documentation.

步骤 3:运行核心管道

Cognee 将处理您的文档,将其加载到知识引擎中,并执行结合向量和图关系的搜索。

Cognee will process your documents, load them into the knowledge engine, and perform searches combining vector and graph relationships.

现在,运行一个最简化的管道:

Now, run a minimal pipeline:

import cognee
import asyncio
from pprint import pprint

async def main():
    # 添加文本到 Cognee
    await cognee.add("Cognee turns documents into AI memory.")

    # 让知识引擎处理并理解内容
    await cognee.cognify()

    # 查询知识图谱
    results = await cognee.search("What does Cognee do?")

    # 展示结果
    for result in results:
        pprint(result)

if __name__ == '__main__':
    asyncio.run(main())

如您所见,输出是基于我们之前存储在 Cognee 中的文档生成的:

As you can see, the output is generated from the document we previously stored in Cognee:

Cognee turns documents into AI memory.

使用 Cognee 命令行界面

作为替代方案,您可以使用以下基本命令快速开始:

As an alternative, you can get started quickly with these essential commands:

cognee-cli add "Cognee turns documents into AI memory."
cognee-cli cognify
cognee-cli search "What does Cognee do?"
cognee-cli delete --all

要打开本地用户界面,请运行:

To open the local UI, run:

cognee-cli -ui

核心应用场景分析

Cognee 的核心优势在于将静态数据转化为动态、可关联、可学习的知识,从而赋能复杂的 AI 智能体任务。以下是两个典型场景的深度剖析。

The core advantage of Cognee lies in transforming static data into dynamic, relatable, and learnable knowledge, thereby empowering complex AI agent tasks. The following is an in-depth analysis of two typical scenarios.

场景一:客户支持智能体

目标:整合客户跨财务、支持、产品历史等维度的个人数据,以解决其问题。

Goal: Integrate customers' personal data across dimensions such as finance, support, and product history to resolve their issues.

用户输入:“我的发票看起来不对,而且问题仍未解决。”

User Input: "My invoice looks wrong and the issue is still not resolved."

Cognee 追踪内容:过去的互动记录、失败的操作、已解决的案例、产品历史。

What Cognee Tracks: Past interactions, failed actions, resolved cases, product history.

智能体响应示例

Agent Response Example:

“我发现上个月有2个类似的计费问题已解决。
问题是由支付系统和发票系统之间的同步延迟引起的——已在您的账户上应用了修复程序。”
"I found 2 similar billing cases resolved last month.
The issue was caused by a sync delay between payment and invoice systems—a fix was applied on your account."

底层运作机制

Underlying Mechanism:

  • 统一数据源:聚合来自公司各渠道的异构数据 (Unifies heterogeneous data sources from various company channels)
  • 重建时间线:重构交互时间线并跟踪结果 (Reconstructs the interaction timeline and tracks outcomes)
  • 关联检索:检索历史上类似的已解决案例 (Retrieves similar resolved cases from history)
  • 策略映射:映射到最佳解决策略 (Maps to the best resolution strategy)
  • 记忆更新:执行后更新记忆,确保智能体永不重复相同错误 (Updates memory after execution, ensuring the agent never repeats the same mistake)

场景二:专家知识提炼

目标:通过复用专家级的 SQL 查询、模式与推理逻辑,帮助初级分析师完成任务。

Goal: Help junior analysts complete tasks by reusing expert-level SQL queries, patterns, and reasoning logic.

用户输入:“我该如何计算这个数据集的客户留存率?”

User Input: "How do I calculate customer retention for this dataset?"

Cognee 追踪内容:专家 SQL 查询、工作流模式、数据库模式结构、成功的实现方案。

What Cognee Tracks: Expert SQL queries, workflow patterns, database schema structures, successful implementations.

智能体响应示例

Agent Response Example:

“以下是高级分析师解决类似留存查询的方法。
Cognee 将您的数据库模式匹配到了一个已知结构,并调整了专家的逻辑以适应您的数据集。”
"Here's how senior analysts solved a similar retention query.
Cognee matched your schema to a known structure and adapted the expert's logic to fit your dataset."

底层运作机制

Underlying Mechanism:

  • 模式提取:从专家 SQL 查询和工作流中提取并存储模式 (Extracts and stores patterns from expert SQL queries and workflows)
  • 模式匹配:将当前数据库模式映射到先前见过的结构 (Maps the current database schema to previously seen structures)
  • 方案检索:检索类似任务及其成功实现方案 (Retrieves similar tasks and their successful implementations)
  • 逻辑适配:将专家推理逻辑适配到当前上下文 (Adapts expert reasoning logic to the current context)
  • 知识进化:用新的成功模式更新记忆,使初级分析师能达到接近专家的水平 (Updates memory with new successful patterns, enabling junior analysts to perform at a near-expert level)

部署方案对比

您可以使用 Cognee Cloud 获得完全托管的体验,或者使用以下一键部署配置自行托管。

You can use Cognee Cloud for a fully managed experience, or self-host using one of the one-click deployment configurations below.

平台/方案 最佳适用场景 核心特点 部署方式
Cognee Cloud 完全托管服务,无需维护基础设施 开箱即用,自动扩展,企业支持 注册使用
Modal 无服务器、自动扩缩容、GPU 工作负载 高性能计算,按需付费 bash distributed/deploy/modal-deploy.sh
Railway 最简单的 PaaS,原生 Postgres 集成 极简配置,快速上线 railway init && railway up
Fly.io 边缘部署,持久化存储卷 低延迟全球分发 bash distributed/deploy/fly-deploy.sh
Render 带有托管 Postgres 的简单 PaaS 一键部署按钮,易于管理 使用 “Deploy to Render” 按钮
Daytona 云端开发沙箱 适合开发与测试环境 参考 distributed/deploy/daytona_sandbox.py

有关部署脚本、工作程序配置和更多详细信息,请参阅 distributed/ 文件夹。

See the distributed/ folder for deployment scripts, worker configurations, and additional details.

社区与支持

贡献指南

我们欢迎社区贡献!您的参与有助于让 Cognee 对每个人变得更好。请参阅 CONTRIBUTING.md 开始贡献。

We welcome contributions from the community! Your participation helps make Cognee better for everyone. See CONTRIBUTING.md to get started.

行为准则

我们致力于培育一个包容和尊重的社区环境。请阅读我们的行为准则了解相关指南。

We are committed to fostering an inclusive and respectful community environment. Please read our Code of Conduct for guidelines.

研究与引用

我们最近发表了一篇关于优化知识图谱以提升大语言模型推理能力的研究论文:

We recently published a research paper on optimizing knowledge graphs to enhance the reasoning capabilities of large language models:

@misc{markovic2025optimizinginterfaceknowledgegraphs,
      title={Optimizing the Interface Between Knowledge Graphs and LLMs for Complex Reasoning},
      author={Vasilije Markovic and Lazar Obradovic and Laszlo Hajdu and Jovan Pavlovic},
      year={2025},
      eprint={2505.24478},
      archivePrefix={arXiv},
      primaryClass={cs.AI},
      url={https://arxiv.org/abs/2505.24478},
}

Cognee 代表了构建下一代具备记忆、学习和推理能力的 AI 智能体的重要基础设施方向。通过将数据转化为互联、可演化的知识,它为开发更可靠、更智能的 AI 应用提供了强大的基石。

Cognee represents a significant infrastructure direction for building the next generation of AI agents with memory, learning, and reasoning capabilities. By transforming data into interconnected, evolvable knowledge, it provides a powerful foundation for developing more reliable and intelligent AI applications.

常见问题(FAQ)

Cognee 是什么?它如何帮助 AI 智能体?

Cognee 是一个开源知识引擎,能将任何格式的非结构化数据转化为 AI 记忆。它通过向量搜索图数据库技术,为 AI 智能体提供持续学习和上下文感知的能力。

为什么我应该选择 Cognee 而不是其他知识库方案?

Cognee 提供统一的数据摄取、混合图/向量搜索、本地运行支持以及企业级的多租户隔离和可观测性。它旨在为构建下一代可靠、可学习的 AI 应用提供基础设施。

如何快速开始使用 Cognee?需要哪些准备?

首先确保 Python 3.10-3.13 环境,使用 pip 等工具安装 cognee 包。然后配置 LLM API 密钥,最后通过几行代码运行核心管道即可添加、处理并查询文档。

← 返回文章列表
分享到:微博

版权与免责声明:本文仅用于信息分享与交流,不构成任何形式的法律、投资、医疗或其他专业建议,也不构成对任何结果的承诺或保证。

文中提及的商标、品牌、Logo、产品名称及相关图片/素材,其权利归各自合法权利人所有。本站内容可能基于公开资料整理,亦可能使用 AI 辅助生成或润色;我们尽力确保准确与合规,但不保证完整性、时效性与适用性,请读者自行甄别并以官方信息为准。

若本文内容或素材涉嫌侵权、隐私不当或存在错误,请相关权利人/当事人联系本站,我们将及时核实并采取删除、修正或下架等处理措施。 也请勿在评论或联系信息中提交身份证号、手机号、住址等个人敏感信息。