Cognee: Build Memory and Knowledge Graphs for Your AI Agents
Hey folks, in this tutorial I want to introduce you to a tool that I think is going to get more and more important as people build more AI agents. It is called Cognee. If you have ever built a chatbot or an agent with an LLM, you have surely run into the classic problem: the model is great at conversation but has terrible memory. Every new session starts from scratch, it does not remember previous conversations, and it forgets the documents you fed it. Usually we solve this with RAG (Retrieval Augmented Generation) backed by a vector database. But plain vector search has a limitation: it only finds things that are semantically similar, and it does not understand the relationships between pieces of information.
This is exactly where Cognee comes in. Cognee is an open-source framework that turns your documents and conversations into a combined knowledge graph plus vector store that you can query. So you do not just get chunks of text that look similar, you also get the structure of relationships between entities. Think of it as a second brain for your agent that can remember facts and also understand how those facts connect to each other.
What I love is that Cognee follows an approach they call ECL: Extract, Cognify, Load. You extract data from various sources, cognify it (turn it into a graph plus embeddings), then load it into a queryable store. Everything runs on top of asyncio, so it is designed for async Python from the ground up. In this tutorial I will walk through installation, configuring an LLM provider, the core loop of add, cognify, and search, plus the concepts of data points and ontology, using it for RAG, and visualizing the graph. Let us get started.
Introduction: What Cognee Is and Why You Need It
Before we jump into code, let me explain the core concept so you do not get lost during the hands-on part. Cognee is essentially a memory engine for AI agents. But unlike simply storing chat history in an array, Cognee builds a structured representation of your knowledge.
There are three mental components you need to understand. First, there is the vector store, where your text is stored as embeddings for semantic search. Second, there is the graph store, where entities and the relationships between them are stored as nodes and edges. Third, there is the relational store, for metadata and document tracking. Cognee manages all three automatically for you, so you do not need to worry about setting up Neo4j, Qdrant, or Postgres manually at the start. By default everything uses local embedded storage.
Why is the graph important? Let me give you a simple example. Say you ingest a document about a company. Vector search can find the paragraph that mentions "founder" if you ask about the founder. But if you ask "who works at the company founded by person A", vector search struggles because that requires connecting several facts. A graph can answer questions like that because the relationship is stored explicitly as an edge. It is the combination of both that makes Cognee retrieval more powerful than plain RAG.
Cognee fits great for cases like agents that need long-term memory, RAG systems that need multi-hop reasoning, internal company knowledge bases, or personal assistants that remember your preferences over time. Alright, let us install it first.
Installation
Installing Cognee is super easy, just one pip command. I recommend you create a virtual environment first to keep things tidy.
python -m venv venv
source venv/bin/activate # on Windows: venv\Scripts\activate
pip install cognee
Cognee needs Python 3.10 or higher, folks, so make sure your Python version is recent enough. You can check with:
python --version
After installation, the next most important step is configuring the LLM provider. Cognee needs an LLM for two main things: first to extract entities and relationships during the cognify process, and second to generate embeddings (if you use embeddings from the same provider). By default Cognee uses OpenAI, so the fastest way is to set the API key via an environment variable.
export LLMAPIKEY="sk-your-openai-api-key"
If you want to be more explicit or use a different provider, Cognee provides a config module you can call from Python. I prefer this approach because it is clearer and easier to track in your codebase.
import cognee
Configure the LLM provider
cognee.config.setllmprovider("openai")
cognee.config.setllmmodel("gpt-4o-mini")
cognee.config.setllmapikey("sk-your-openai-api-key")