Cognee开源知识引擎:2024年构建AI动态记忆指南
Cognee 是一款开源知识引擎,能将原始数据转化为智能体持久动态的AI记忆。它结合向量搜索与图数据库,实现语义搜索与数据关联,并提供高度可定制的模块化管道。
原文翻译: Cognee is an open-source knowledge engine that transforms raw data into persistent, dynamic AI memory for agents. It combines vector search and graph databases to enable semantic search and data interconnections, offering highly customizable modular pipelines.
Cognee: 将原始数据转化为智能体持久动态记忆的开源知识引擎
关于 Cognee
Cognee 是一个开源知识引擎,能够将您的原始数据转化为智能体(Agents)持久且动态的 AI 记忆。它结合了向量搜索、图数据库和自我改进能力,使您的文档不仅可以通过语义进行搜索,还能随着数据的变化和发展,通过关系相互连接。
Cognee 是一个开源知识引擎,能够将您的原始数据转化为智能体(Agents)持久且动态的 AI 记忆。它结合了向量搜索、图数据库和自我改进能力,使您的文档不仅可以通过语义进行搜索,还能随着数据的变化和发展,通过关系相互连接。
Cognee 提供了默认的知识创建和搜索功能,我们将在下文进行描述。但更重要的是,您可以使用 Cognee 构建自己的模块化知识块!
Cognee provides default knowledge creation and search capabilities, which we describe below. However, with Cognee, you can build your own modular knowledge blocks!
⭐ 帮助我们触达更多开发者,壮大 Cognee 社区。请为这个仓库点个 Star!
⭐ Help us reach more developers and grow the Cognee community. Star this repository!
Cognee 开源版的核心优势
- 互连各类数据 — 包括历史对话、文件、图像和音频转录文本。
Interconnects any type of data — including past conversations, files, images, and audio transcriptions.
- 统一知识引擎 — 用基于图和向量的统一知识引擎替代传统的数据库查询。
Replaces traditional database lookups with a unified knowledge engine built with graphs and vectors.
- 降本增效提精度 — 减少开发工作量与基础设施成本,同时提升质量和精度。
Reduces developer effort and infrastructure cost while improving quality and precision.
- 灵活的 Python 数据管道 — 提供从 30 多种数据源进行数据摄取的 Pythonic 管道。
Provides Pythonic data pipelines for ingestion from 30+ data sources.
- 高度可定制 — 支持用户自定义任务、模块化管道和内置搜索端点。
Offers high customizability through user-defined tasks, modular pipelines, and built-in search endpoints.
基础使用与功能指南
要了解更多信息,请查看这个简短、端到端的 Colab 教程,了解 Cognee 的核心功能。
To learn more, check out this short, end-to-end Colab walkthrough of Cognee's core features.
快速开始
让我们用几行代码尝试一下 Cognee。有关详细设置和配置,请参阅 Cognee 文档。
Let's try Cognee in just a few lines of code. For detailed setup and configuration, see the Cognee Docs.
先决条件
- Python 3.10 至 3.13
Python 3.10 to 3.13
步骤 1:安装 Cognee
您可以使用 pip、poetry、uv 或您喜欢的 Python 包管理器来安装 Cognee。
You can install Cognee with pip, poetry, uv, or your preferred Python package manager.
uv pip install cognee
步骤 2:配置大语言模型 (LLM)
import os
os.environ["LLM_API_KEY"] = "YOUR_OPENAI_API_KEY"
或者,使用我们的模板创建一个 .env 文件。
要集成其他 LLM 提供商,请参阅我们的 LLM 提供商文档。
Alternatively, create a
.envfile using our template. To integrate other LLM providers, see our LLM Provider Documentation.
步骤 3:运行管道
Cognee 将处理您的文档,从中生成知识图谱,然后基于组合关系查询该图谱。 现在,运行一个最小化的管道:
Cognee will take your documents, generate a knowledge graph from them, and then query the graph based on combined 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()
# 向图谱添加记忆算法
await cognee.memify()
# 查询知识图谱
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 CLI
作为替代方案,您可以使用以下基本命令开始:
As an alternative, you can get started 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 的实际应用:
See Cognee in action:
持久化智能体记忆
Persistent Agent Memory
简单 GraphRAG
Simple GraphRAG
Cognee 与 Ollama 集成
Cognee with Ollama
社区与支持
贡献
我们欢迎社区的贡献!您的意见有助于让 Cognee 对每个人变得更好。请参阅 CONTRIBUTING.md 开始贡献。
We welcome contributions from the community! Your input helps make Cognee better for everyone. See CONTRIBUTING.md to get started.
行为准则
我们致力于培育一个包容和尊重的社区。请阅读我们的 行为准则 了解指导方针。
We're committed to fostering an inclusive and respectful community. Read our Code of Conduct for guidelines.
研究与引用
我们最近发表了一篇关于优化知识图谱以提升 LLM 推理能力的研究论文:
We recently published a research paper on optimizing knowledge graphs for LLM reasoning:
@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},
}
版权与免责声明:本文仅用于信息分享与交流,不构成任何形式的法律、投资、医疗或其他专业建议,也不构成对任何结果的承诺或保证。
文中提及的商标、品牌、Logo、产品名称及相关图片/素材,其权利归各自合法权利人所有。本站内容可能基于公开资料整理,亦可能使用 AI 辅助生成或润色;我们尽力确保准确与合规,但不保证完整性、时效性与适用性,请读者自行甄别并以官方信息为准。
若本文内容或素材涉嫌侵权、隐私不当或存在错误,请相关权利人/当事人联系本站,我们将及时核实并采取删除、修正或下架等处理措施。 也请勿在评论或联系信息中提交身份证号、手机号、住址等个人敏感信息。