$ show topoteretes/cognee
Cognee is an open-source AI memory platform that enables agents and applications to build, store, and query persistent knowledge graphs from documents, code, and conversations. The system provides a Python SDK, a FastAPI REST API, a CLI, a Next.js frontend, and an MCP server for agent integration. Core operations include ingesting data (remember), extracting entities and relationships via LLMs or GLiNER (cognify), retrieving context (recall), and self-improvement loops (improve). The architecture is modular with adapter/registry patterns for graph databases (Ladybug, Neo4j, Turso), vector stores (LanceDB, PGVector), LLM providers (LiteLLM, OpenAI, Anthropic, Ollama), and integrations (Slack, GitHub, Google Drive). The frontend provides a dashboard for dataset management, knowledge graph visualization, and business analytics. The project also includes an evaluation framework for benchmarking retrieval strategies against standard datasets like HotpotQA and BEAM. While production-grade in many areas, some components are marked as demo-quality or have cloud-only stubs.
The LLM identified 4 files worth highlighting for reuse:
Implements a ProvenanceBuffer that captures graph mutations with hash-linked entries, threshold-based flush, and edge evidence sidecars. The buffer supports W3C PROV-O flavored provenance and can be extracted as a standalone audit log component for any system requiring tamper-evident change tracking. It uses SHA256 hashing and a monotonic counter for ordering.
A generic ClosingLRUCache class that wraps database adapters with LRU eviction and ensures async cleanup on eviction via an on_evict callback. It uses collections.OrderedDict for O(1) access and eviction, and schedules the close coroutine in the event loop. This is a reusable pattern for managing expensive connections or engines in async Python applications.
A standalone URL validation module that blocks Server-Side Request Forgery attacks by rejecting internal IP ranges, disallowed schemes, and performing DNS rebinding checks. It uses ipaddress module for IP validation and can be reused in any Python web scraper or proxy to safely restrict outbound requests.
Defines a layer composition pattern for a force-directed graph visualization. The useBusinessScene hook merges multiple named layers (governance, content) into a single scene by combining node/link arrays. The pattern is extensible via a registry with three mechanical edits (add layer implementation, register it, consume in hook). This is a clean frontend pattern for building modular, composable graph overlays.