[KongchangAI]
· 2 min read· 1,089 words

Notion + Cognee: Building Long-Term Memory for AI Agents

Notion + Cognee: Building Long-Term Memory for AI Agents

Notion + Cognee integration turns workspace documents into knowledge graphs, building long-term memory for AI Agents.

This article explains how integrating Notion with Cognee solves the issue of AI Agents losing context across sessions. The author developed NotionLoader based on the official notion-client SDK to extract text from Notion pages and databases. The integration has two steps: batch-loading text via cognee.add(), then calling cognee.cognify() to build a knowledge graph. The graph preserves entity relationships, enabling relational reasoning instead of simple text matching. Re-running the loading process syncs incremental content to keep memory consistent with the team knowledge base. The article also notes that engineering details like performance in large workspaces, permission boundaries, and incremental updates remain to be validated.

AI Agents often lose context across sessions, starting every conversation from scratch. Integrating Notion with Cognee allows agents to automatically ingest workspace documents and transform them into interconnected knowledge graphs, enabling true long-term memory. This article breaks down the implementation and design rationale behind this integration.

Notion and Cognee integration diagram

Why AI Agents Need Long-Term Memory

Currently, most AI agents' memory mechanisms are limited to the context window of a single session. Once the conversation ends, previously accumulated information ceases to exist. For scenarios requiring continuous processing of project documents and team knowledge bases, this "amnesia" characteristic severely limits the agent's practicality.

Cognee's approach is to build a knowledge graph as the agent's external memory layer. Unlike simple vector retrieval, knowledge graphs preserve the associations between entities, enabling the agent to understand structured information such as "the relationship between a person mentioned in document A and project B." Notion, as the core knowledge carrier for team collaboration, naturally becomes the primary data source for memory ingestion.

Knowledge Graph is a technology that organizes data in a graph structure, where nodes represent entities (such as people, projects, documents) and edges represent relationships between entities (such as "participates in," "references," "belongs to"). Unlike vector retrieval, which compresses text into high-dimensional vectors and can only compute semantic similarity, knowledge graphs explicitly preserve the topological associations between entities and support multi-hop reasoning. For example, an agent can start from "Zhang San," follow the "responsible for" edge to find "Project X," and then follow the "produces" edge to find related meeting records, thereby answering questions that require connecting multiple information sources. Cognee leverages this characteristic to transform scattered documents into a reasoning-capable memory network.

How NotionLoader Works

According to the original technical sharing, the author developed NotionLoader based on the official notion-client Python SDK. This loader is responsible for fetching page and database content from the Notion workspace, extracting the text information, and then handing it over to Cognee's ingestion pipeline for processing.

The entire process is divided into three steps: loading, transformation, and graph construction. NotionLoader traverses pages and databases within a specified scope, concatenating each page's title and body content into structured text. This format preserves the semantic boundaries of the documents, facilitating subsequent graph construction.

You might not have noticed that this solution directly calls the official SDK rather than relying on third-party wrappers, which means better version compatibility and more fine-grained access control capabilities.

notion-client is the officially maintained Python SDK for Notion, encapsulating the underlying details of the Notion API such as authentication, pagination, and error handling. Developers can use it to directly manipulate resources like pages, databases, and blocks. Compared to third-party wrapper libraries, the official SDK typically follows API changes more quickly and provides more fine-grained request control (such as filtering by block type and custom retry strategies). NotionLoader is built on it, meaning the loader can flexibly traverse the page tree and database entries in the workspace without being constrained by the abstraction layers of third-party libraries.

Integration Code and Workflow

The core integration code is very concise. Developers only need to import the NotionLoader and cognee modules, initialize the loader and iterate through the page data, inject each page's title and content one by one via cognee.add(), and finally call cognee.cognify() to trigger knowledge graph construction.

from notion_loader import NotionLoader
import cognee

loader = NotionLoader()
pages = loader.load_data()

for page in pages:
    cognee.add(f"Title: {page['title']}\n\n{page['content']}")

cognee.cognify()

cognee.add() is responsible for adding raw text to the processing queue, while cognify() is the step that actually performs graph processing—parsing entities, establishing associations, and writing to graph storage. This two-stage design allows developers to batch-load first and then build uniformly, avoiding repeatedly triggering expensive graph computation.

cognee.cognify() is the core method in the Cognee framework that triggers knowledge graph construction. It receives the raw text previously added via cognee.add() and performs a series of processing steps including entity recognition, relationship extraction, and graph writing. This process typically involves calling large language models for information extraction, so it is computationally expensive. The two-stage design that separates add() from cognify() allows developers to first batch-collect all documents and then trigger graph processing once, avoiding repeatedly executing expensive graph computation for each piece of added text, thereby improving overall efficiency.

The Practical Value of Knowledge Graph Memory

After transforming Notion documents into a knowledge graph, the Cognee Agent no longer merely performs text similarity matching when answering questions; it can reason along entity relationships. For example, when a user asks about the decision background of a project, the agent can associate relevant meeting records, owner pages, and requirements documents to form a contextualized answer.

Another advantage of this memory mechanism is updatability. Notion workspace content changes continuously; re-running the loading process can synchronize incremental information into the graph, keeping the agent's memory in sync with the team knowledge base.

Practical Considerations

This solution is still in an early exploratory stage. The original sharing did not mention performance under large-scale workspaces, how permission boundaries are handled, or incremental strategies for graph updates. For teams with a large number of pages, full loading may incur considerable API call overhead and time costs.

Additionally, Notion content may contain non-plain-text elements such as tables and embedded blocks, and the completeness of text extraction directly affects graph quality. These engineering details need further validation in real-world scenarios.

From a directional perspective, enabling agents to "remember" team knowledge in the form of knowledge graphs rather than flat text is a key step toward improving their long-term usability. The combination of Notion and Cognee provides a lightweight, reproducible starting point suitable for developers who want to give agents persistent memory.

One-line Summary

Integrating Notion with Cognee transforms workspace documents into knowledge graphs, building long-term memory for AI Agents.

Paragraph Summary

This article explains how to solve the problem of AI Agents losing context across sessions through the integration of Notion and Cognee. The author developed NotionLoader based on the official notion-client SDK to extract text content from Notion pages and databases. The integration process has two steps: batch-loading text via cognee.add(), then calling cognee.cognify() to build a knowledge graph. The knowledge graph preserves associations between entities, enabling the Agent to perform relational reasoning rather than simple text matching. Re-running the loading process can synchronize incremental content to keep memory consistent with the team knowledge base. The article also points out that engineering details such as performance in large-scale workspaces, permission boundaries, and incremental update strategies remain to be validated.

#Notion#Cognee#AI Agent#knowledge graph#long-term memory
Share:

Related articles