Cognee: How to Give Your AI Agents a Permanent Memory with Knowledge Graphs
Cognee is an open-source AI memory platform that gives agents persistent long-term memory using knowledge graphs, vector embeddings, and graph reasoning — and you can self-host it.
pip install cognee, self-host it, and use a simple API: remember(), recall(), forget(), and improve().
Why AI Agents Need Permanent Memory
If you've ever built an AI-powered application, you've hit the same wall: LLMs forget everything between sessions. Every conversation starts from scratch. Your agent can't remember user preferences, past decisions, or accumulated knowledge unless you bolt on a brittle RAG pipeline or stuff everything into a context window.
This is the exact problem Cognee solves — and it's trending on GitHub for good reason.
Cognee is not just another vector database wrapper. It's a full memory infrastructure for AI agents that combines three layers of intelligence:
- Vector embeddings for semantic similarity search
- Knowledge graphs for relationship-aware reasoning
- Cognitive-science-grounded ontologies that evolve as your knowledge grows
The result? Agents that actually learn over time — without you manually curating prompts or context.
How Cognee Works: The Four-Operation API
Cognee's API is refreshingly minimal. Everything revolves around four operations that mirror human memory:
1. Remember — Store Knowledge Permanently
The remember() function ingests text, documents, or structured data and builds a knowledge graph behind the scenes. It runs three steps internally: add (ingest raw data), cognify (build graph structure), and improve (refine ontology).
import cognee
import asyncio
async def main():
# Store permanently in the knowledge graph
await cognee.remember("Our API rate limit is 1000 requests per minute for enterprise plans.")
# Store in session memory (fast cache, syncs to graph in background)
await cognee.remember("User prefers TypeScript examples over Python.", session_id="chat_1")
asyncio.run(main())
2. Recall — Retrieve with Smart Routing
The recall() function uses auto-routing to pick the best search strategy. It can query session memory first (for speed) and fall through to the permanent graph when needed.
# Query with auto-routing (picks best search strategy)
results = await cognee.recall("What is our API rate limit?")
# Query session memory first, fall through to graph
results = await cognee.recall("What does the user prefer?", session_id="chat_1")
for result in results:
print(result)
3. Forget — Clean Up When Needed
# Delete an entire dataset
await cognee.forget(dataset="old_project_data")
4. Improve — Refine the Knowledge Graph
Cognee continuously improves its ontology as new information arrives. The improve() operation refines relationships and classifications based on accumulated knowledge.
Knowledge Graphs vs. Plain RAG: Why It Matters
Traditional RAG (Retrieval-Augmented Generation) treats every document as an isolated chunk. It finds text that's semantically similar to your query but has no understanding of how pieces of information relate to each other.
Cognee's knowledge graph approach is fundamentally different:
| Feature | Traditional RAG | Cognee (Knowledge Graph) |
|---|---|---|
| Relationship awareness | ❌ None | ✅ Full graph reasoning |
| Cross-document connections | ❌ Manual only | ✅ Automatic |
| Evolving knowledge | ❌ Static chunks | ✅ Ontology refinement |
| Multi-hop queries | ❌ Single-hop only | ✅ Built-in |
| Session + long-term memory | ❌ Separate systems | ✅ Unified API |
This means your agent can answer questions like "Who in our team has experience with both PostgreSQL and Kubernetes?" — a multi-hop query that would require chaining multiple RAG lookups manually.
Real-World Example: Building a Company Brain
Let's say you're building an internal AI assistant for your engineering team. Here's how Cognee transforms the experience:
import cognee
import asyncio
async def build_company_brain():
# Ingest onboarding docs
await cognee.remember(
"Alice is the lead backend engineer. She maintains the payment service "
"and has expertise in Python, Go, and distributed systems."
)
await cognee.remember(
"The payment service uses PostgreSQL, Redis for caching, "
"and deploys on Kubernetes via Helm charts."
)
await cognee.remember(
"Bob is a frontend engineer specializing in React and TypeScript. "
"He built the customer dashboard that connects to the payment service API."
)
# Now ask complex questions
results = await cognee.recall("Who can help debug a payment service issue on Kubernetes?")
# → Alice (knows payment service + distributed systems + Kubernetes)
results = await cognee.recall("What technologies connect the frontend to the payment backend?")
# → React/TypeScript dashboard → payment service API → PostgreSQL
asyncio.run(build_company_brain())
The knowledge graph automatically understands that Alice → maintains → payment service → uses → PostgreSQL → deployed on → Kubernetes, and can traverse these relationships to answer queries that pure text search would miss.
Self-Hosting and Deployment Options
Cognee is fully self-hostable with multiple deployment options:
Quick Start with Docker
# Clone and configure
git clone https://github.com/topoteretes/cognee.git
cd cognee
cp .env.template .env
# Set LLM_API_KEY in .env
# Start the API server
docker compose up
# With UI + MCP server + Postgres
docker compose --profile ui --profile mcp --profile postgres up
Python Package
# Install with pip, poetry, or uv
uv pip install cognee
CLI Usage
# Remember from the command line
cognee-cli remember "Cognee turns documents into AI memory."
# Recall
cognee-cli recall "What does Cognee do?"
# Open the local UI
cognee-cli -ui
Plugin Ecosystem: Claude Code, OpenClaw, and More
Cognee isn't just a standalone library — it's becoming the memory layer for the entire AI tooling ecosystem:
- Claude Code plugin — captures prompts, tool traces, and responses into session memory; syncs to permanent graph at session end
- OpenClaw plugin —
@cognee/cognee-openclawfor persistent agent memory - TypeScript client —
@cognee/cognee-tsfor Node.js applications - Rust client —
cognee-rsfor high-performance applications - MCP Server — expose Cognee as a Model Context Protocol server for any compatible agent
Key Benefits
- Persistent memory across sessions — agents remember everything from every conversation
- Knowledge graph reasoning — go beyond text similarity to relationship-aware answers
- Self-hosted and private — your data never leaves your infrastructure
- Multi-modal ingestion — text, documents, structured data all supported
- Session + long-term memory unified — one API for both fast cache and permanent storage
- Auto-routing search — Cognee picks the best retrieval strategy automatically
- Open source (Apache 2.0) — full control, no vendor lock-in
- Rich plugin ecosystem — works with Claude Code, OpenClaw, and any MCP-compatible agent
Getting Started in Under 5 Minutes
import os
os.environ["LLM_API_KEY"] = "your-openai-api-key"
import cognee
import asyncio
async def main():
# 1. Remember something
await cognee.remember("Cognee is an open-source AI memory platform.")
# 2. Recall it
results = await cognee.recall("What is Cognee?")
for result in results:
print(result)
asyncio.run(main())
That's it. Three lines of code and your agent has permanent memory.
Frequently Asked Questions
What is Cognee and how does it work?
Cognee is an open-source AI memory platform that gives AI agents persistent long-term memory using knowledge graphs, vector embeddings, and cognitive-science-grounded ontologies. It ingests data in any format and continuously builds a self-hosted knowledge graph that agents can query with a simple API: remember(), recall(), forget(), and improve().
How is Cognee different from RAG (Retrieval-Augmented Generation)?
Traditional RAG treats documents as isolated text chunks and finds semantically similar content. Cognee goes further by building a knowledge graph that understands relationships between pieces of information, enabling multi-hop queries, cross-document connections, and evolving knowledge that improves over time — capabilities that plain RAG cannot provide.
Can I self-host Cognee and keep my data private?
Yes. Cognee is fully self-hostable via Docker, pip install, or from source. All data stays on your infrastructure. It supports multiple backends including PostgreSQL with PGVector and Neo4j for the knowledge graph. There is also a cloud option for teams that prefer managed hosting.
Does Cognee work with Claude Code and other AI coding tools?
Yes. Cognee has official plugins for Claude Code (captures prompts, tool traces, and responses into session memory), OpenClaw, and any MCP-compatible agent. It also provides TypeScript, Python, and Rust client libraries for building custom integrations.
What LLM providers does Cognee support?
Cognee supports OpenAI by default but can be configured to work with other LLM providers including Anthropic, local models via Ollama, and any provider compatible with the OpenAI API format. Configuration is done through environment variables or the .env file.
Is Cognee free to use?
Yes. Cognee is open-source under the Apache 2.0 license. You can use it for free in personal and commercial projects. The only costs are for the LLM API calls (e.g., OpenAI) used during knowledge graph construction and querying.