Cognee — Memory Engine for AI Agents
Cognee adds persistent structured memory to any AI agent in 6 lines of code. 14.8K+ stars. Knowledge graphs, vector stores, LLM integration. Apache 2.0.
What it is
Cognee is an open-source memory and knowledge management engine built for AI agents. While most AI tools lose context between sessions, Cognee provides persistent structured memory that grows over time. It processes text, documents, URLs, and databases into knowledge graphs with entity extraction, relationship mapping, and vector embeddings.
Cognee is designed for developers building AI agents that need to remember previous interactions, accumulate domain knowledge, or reason over structured data. It works with any LLM provider and integrates in as few as six lines of Python.
How it saves time or tokens
Without a memory engine, AI agents must re-ingest context every session, consuming tokens and adding latency. Cognee processes data once into a persistent knowledge graph, so subsequent queries retrieve only relevant facts rather than re-processing entire documents. This reduces token consumption for repeated queries and enables agents to build cumulative understanding across sessions.
The structured approach also means agents get sourced answers rather than hallucinated ones -- Cognee traces every answer back to the original data that informed it.
How to use
- Install Cognee:
pip install cognee. - Add data with
await cognee.add('your text or document path')-- Cognee accepts text strings, file paths, and URLs. - Process data into the knowledge graph with
await cognee.cognify(), then query withresults = await cognee.search('your question').
Example
import cognee
# Add knowledge from different sources
await cognee.add('The quarterly revenue was $4.2M, up 23% YoY.')
await cognee.add('Customer churn decreased to 2.1% in Q3.')
# Process into knowledge graph
await cognee.cognify()
# Query with natural language
results = await cognee.search('What was the revenue growth?')
# Returns structured, sourced answers
Related on TokRepo
- AI memory tools -- memory solutions for AI agents compared
- AI agent tools -- frameworks for building capable AI agents
Common pitfalls
- Cognee requires an async runtime; ensure your application uses
asyncioor an async-compatible framework when callingcognee.add()andcognee.cognify(). - Large document batches should be processed incrementally rather than all at once to avoid memory pressure during the knowledge graph construction phase.
- The default vector store works for development but should be replaced with a production-grade store (PostgreSQL with pgvector, Weaviate, or similar) for deployment.
Frequently Asked Questions
Cognee goes beyond vector similarity search by building a knowledge graph with entity extraction and relationship mapping. This means it understands connections between concepts, not just semantic similarity. Answers are traced back to source data.
Cognee works with any LLM provider including OpenAI, Anthropic, and local models. The LLM is used during the cognify step for entity extraction and during search for natural language query processing.
Yes. Cognee can ingest data from databases, CSV files, and other structured sources in addition to unstructured text and documents. The knowledge graph unifies all data types into a queryable structure.
Cognee is Apache 2.0 licensed and designed for production. For production deployments, configure a persistent storage backend and a production-grade vector store rather than relying on the default in-memory options.
Cognee stores the knowledge graph and vector embeddings in a persistent backend. When your agent restarts or a new session begins, all previously processed knowledge is immediately available without re-ingestion.
Citations (3)
- Cognee GitHub— Cognee adds persistent structured memory to AI agents
- Cognee Documentation— Knowledge graph with entity extraction and relationship mapping
- Stanford AI Lab— Knowledge graphs for AI applications
Related on TokRepo
Source & Thanks
- GitHub: https://github.com/topoteretes/cognee (14.8K+ stars)
- License: Apache 2.0
- Docs: https://docs.cognee.ai
- Maintainer: Topoteretes
Discussion
Related Assets
Claude-Flow — Multi-Agent Orchestration for Claude Code
Layers swarm and hive-mind multi-agent orchestration on top of Claude Code with 64 specialized agents, SQLite memory, and parallel execution.
ccusage — Real-Time Token Cost Tracker for Claude Code
CLI that reads ~/.claude logs and breaks down Claude Code token spend by day, session, and project — pluggable into your statusline.
SuperClaude — Workflow Framework for Claude Code
Adds 16+ slash commands, 9 cognitive personas, and a smart flag system to Claude Code in one pipx install.