topoteretes / cognee
topoteretes / cognee
Cognee - The Open-Source AI Memory Platform for Agents Cognee - 面向 AI Agent 的开源记忆平台
Demo · Docs · Learn More · Join Discord · Join r/AIMemory · Community Plugins & Add-ons 演示 · 文档 · 了解更多 · 加入 Discord · 加入 r/AIMemory · 社区插件与扩展
Cognee is the open-source AI memory platform that gives AI agents persistent long-term memory across sessions. Ingest data in any format, build a self-hosted knowledge graph, and let every agent recall, connect, and act with full context 🌐 Cognee 是一个开源的 AI 记忆平台,为 AI Agent 提供跨会话的持久化长期记忆。它支持摄入任何格式的数据,构建自托管的知识图谱,让每个 Agent 都能在完整上下文的基础上进行回忆、关联和行动。
This README is also available in: : Deutsch | Español | Français | 日本語 | 한국어 | Português | Русский | 中文 本 README 文档还提供以下语言版本:德语 | 西班牙语 | 法语 | 日语 | 韩语 | 葡萄牙语 | 俄语 | 中文
📄 Read the research paper: Optimizing the Interface Between Knowledge Graphs and LLMs for Complex Reasoning — Markovic et al., 2025 📄 阅读研究论文:优化知识图谱与大语言模型之间的接口以实现复杂推理 — Markovic 等人,2025
About Cognee
关于 Cognee
Cognee is an open-source AI memory platform for AI Agents. Ingest data in any format, and Cognee continuously builds a self-hosted knowledge graph that gives your agents persistent long-term memory across sessions. Cognee combines vector embeddings, graph reasoning, and cognitive-science-grounded ontology generation to make documents both searchable by meaning and connected by relationships that evolve as your knowledge does. Cognee 是一个面向 AI Agent 的开源记忆平台。通过摄入任意格式的数据,Cognee 会持续构建一个自托管的知识图谱,为你的 Agent 提供跨会话的持久化长期记忆。Cognee 结合了向量嵌入、图推理以及基于认知科学的本体生成技术,使文档不仅可以通过语义进行搜索,还能通过随知识演进而变化的关联关系连接起来。
⭐ Help us reach more developers and grow the cognee community. Star this repo! ⭐ 帮助我们触达更多开发者并壮大 Cognee 社区。请为本项目点赞(Star)!
📚 Check our detailed documentation for setup and configuration. 📚 查看我们的详细文档以获取安装与配置指南。
🦀 Available as a plugin for your OpenClaw — cognee-openclaw 🦀 可作为 OpenClaw 的插件使用 — cognee-openclaw
✴️ Available as a plugin for your Claude Code — claude-code-plugin ✴️ 可作为 Claude Code 的插件使用 — claude-code-plugin
🦀 Available as a Rust client — cognee-rs 🦀 提供 Rust 客户端 — cognee-rs
🟦 Available as a TypeScript client — @cognee/cognee-ts 🟦 提供 TypeScript 客户端 — @cognee/cognee-ts
Why use Cognee:
为什么选择 Cognee:
- Easily Build Company Brain - unify data from various sources in one place and enable Agents with your domain knowledge
- 轻松构建企业大脑 - 将来自不同来源的数据统一整合,并利用你的领域知识赋能 Agent。
- Knowledge infrastructure — unified ingestion, graph/vector search, runs locally, ontology grounding, multimodal
- 知识基础设施 - 提供统一的数据摄入、图/向量搜索、本地运行、本体接地(Ontology Grounding)以及多模态支持。
- Persistent and Learning Agents - learn from feedback, context management, cross-agent knowledge sharing
- 持久化与学习型 Agent - 从反馈中学习,支持上下文管理及跨 Agent 的知识共享。
- Reliable and Trustworthy Agents - agentic user/tenant isolation, traceability, OTEL collector, audit traits
- 可靠且可信的 Agent - 支持 Agent 级别的用户/租户隔离、可追溯性、OTEL 收集器以及审计追踪功能。
How it Works
工作原理
Basic Usage & Feature Guide: To learn more, check out this short, end-to-end Colab walkthrough of Cognee’s core features. 基础用法与功能指南:欲了解更多信息,请查看这份关于 Cognee 核心功能的简短端到端 Colab 演示。
Quickstart
快速开始
Let’s try Cognee in just a few lines of code. 让我们用几行代码来体验 Cognee。
Prerequisites 前置条件 Python 3.10 to 3.14 Python 3.10 至 3.14
Step 1: Install Cognee
第一步:安装 Cognee
You can install Cognee with pip, poetry, uv, or your preferred Python package manager.
你可以使用 pip、poetry、uv 或你偏好的 Python 包管理器来安装 Cognee。
uv pip install cognee
Step 2: Configure the LLM 第二步:配置大语言模型 (LLM)
import os
os.environ["LLM_API_KEY"] = "YOUR OPENAI_API_KEY"
Alternatively, create a .env file using our template. To integrate other LLM providers, see our LLM Provider Documentation. 或者,使用我们的模板创建一个 .env 文件。如需集成其他 LLM 提供商,请参阅我们的 LLM 提供商文档。
Step 3: Run the Pipeline 第三步:运行流水线 Cognee’s API gives you four operations — remember, recall, forget, and improve: Cognee 的 API 提供四种操作:remember(记忆)、recall(回忆)、forget(遗忘)和 improve(优化):
import cognee
import asyncio
async def main():
# Store permanently in the knowledge graph (runs add + cognify + improve)
# 永久存储到知识图谱中(执行 add + cognify + improve)
await cognee.remember("Cognee turns documents into AI memory.")
# Store in session memory (fast cache, syncs to graph in background)
# 存储到会话记忆中(快速缓存,后台同步至图谱)
await cognee.remember("User prefers detailed explanations.", session_id="chat_1")
# Query with auto-routing (picks best search strategy automatically)
# 使用自动路由进行查询(自动选择最佳搜索策略)
results = await cognee.recall("What does Cognee do?")
for result in results:
print(result)
# Query session memory first, fall through to graph if needed
# 先查询会话记忆,必要时回退到图谱查询
results = await cognee.recall("What does the user prefer?", session_id="chat_1")
for result in results:
print(result)
# Delete when done
# 完成后删除
await cognee.forget(dataset="main_dataset")
if __name__ == '__main__':
asyncio.run(main())
Use the Cognee CLI
使用 Cognee 命令行工具 (CLI)
cognee-cli remember "Cognee turns documents into AI memory."
cognee-cli recall "What does Cognee do?"
cognee-cli forget --all
To open the local UI, run: cognee-cli -ui
若要打开本地 UI,请运行:cognee-cli -ui
Note: The MCP server launched by cognee-cli -ui runs inside a Docker container. Docker Desktop, Colima, or any OCI-compatible runtime with a working docker CLI is required. See Docker & Colima Setup for details.
注意:由 cognee-cli -ui 启动的 MCP 服务器运行在 Docker 容器内。需要安装 Docker Desktop、Colima 或任何带有可用 docker CLI 的 OCI 兼容运行时。详情请参阅 Docker 与 Colima 设置。
Run with Docker
使用 Docker 运行
Prefer containers? Cognee publishes prebuilt images to Docker Hub on every push to main: cognee/cognee (the API server) and cognee/cognee-mcp (the MCP server).
更喜欢容器?Cognee 在每次推送到主分支时都会发布预构建镜像到 Docker Hub:cognee/cognee(API 服务器)和 cognee/cognee-mcp(MCP 服务器)。
Option A — Docker Compose (build from source) 选项 A — Docker Compose(从源码构建) Clone the repo, create a .env with at least LLM_API_KEY, then: 克隆仓库,创建一个至少包含 LLM_API_KEY 的 .env 文件,然后:
cp .env.template .env
# then edit .env and set LLM_API_KEY
# 然后编辑 .env 并设置 LLM_API_KEY
# Start the API server (http://localhost:8000)
# 启动 API 服务器 (http://localhost:8000)
docker compose up
# Optional profiles (combine as needed):
# 可选配置(按需组合):
docker compose --profile ui up # + frontend on http://localhost:3000
docker compose --profile mcp up # + MCP server on http://localhost:8001
docker compose --profile postgres up # + Postgres/PGVector
docker compose --profile neo4j up # + Neo4j
The cognee and cognee-mcp services publish different host ports (8000 vs 8001), so you can run both at once. cognee 和 cognee-mcp 服务发布在不同的主机端口(8000 和 8001),因此你可以同时运行它们。
Option B — Pull the prebuilt image (no clone required) 选项 B — 拉取预构建镜像(无需克隆)
# Create a minimal .env in the current directory
# 在当前目录创建一个最小化的 .env 文件
echo 'LLM_API_KEY="YOUR_OPENAI_API_KEY"' > .env
# API server
# API 服务器
docker run --env-file ./.env -p 8000:8000 --rm -it cognee/cognee:main
# MCP server (HTTP transport)
# MCP 服务器 (HTTP 传输)
docker pull cognee/cognee-mcp:main
docker run -e TRANSPORT_MODE=http --env-file ./.env -p 8000:8000 --rm -it cognee/cognee-mcp:main
See the MCP server README for SSE/stdio transports, optional extras, and MCP client configuration. 有关 SSE/stdio 传输、可选扩展及 MCP 客户端配置,请参阅 MCP 服务器的 README。
Use with AI Agents
与 AI Agent 配合使用
Claude Code Install the Cognee memory plugin to give Claude Code persistent memory across sessions. The plugin captures prompts, tool traces, and assistant responses into session memory, injects relevant context on every prompt, and syncs session memory into the permanent knowledge graph at session end. 安装 Cognee 记忆插件,为 Claude Code 提供跨会话的持久化记忆。该插件会将提示词、工具追踪记录和助手响应捕获到会话记忆中,在每次提示时注入相关上下文,并在会话结束时将会话记忆同步到永久知识图谱中。
Install from the Claude Code marketplace. The recommended way is from your shell, before launching Claude Code, so the first claude launch is a clean session that bootstraps memory automatically: 请从 Claude Code 市场安装。推荐的方式是在启动 Claude Code 之前通过 shell 进行安装,这样首次启动 claude 时就是一个自动引导记忆的干净会话:
# Add the marketplace and install the plugin (one-time, user-scoped)
# 添加市场并安装插件(一次性,用户级)
claude plugin marketplace add topoteretes/cognee-integrations
claude plugin install cognee-memory@cognee
# Set env vars for your mode (see below), then launch
# 设置模式所需的环境变量(见下文),然后启动
export LLM_API_KEY="sk-..." # local mode; or COGNEE_BASE_URL + COGNEE_API_KEY for cloud
Local mode (default) — the plugin bootstraps a local Cognee API at http://localhost:8011. 本地模式(默认)— 插件会在 http://localhost:8011 引导一个本地 Cognee API。