When to use this
You want to persist cached conversation sessions into the knowledge graph so the Q&A history becomes part of the searchable graph. This is useful when you want session data to survive cache clearing or to be queryable alongside other graph data. Before you start:- Complete Quickstart to understand basic operations
- Ensure you have LLM Providers configured
- Have an existing knowledge graph (add → cognify completed)
- Caching must be enabled and at least one session must exist (created by prior
cognee.search()calls with asession_id)
Code in Action
What Just Happened
- Add + Cognify — builds a knowledge graph from your text.
- Search with
session_id— runs two searches that accumulate Q&A history in the session cache under"demo_session". get_default_user()— retrieves the authenticated user. This pipeline requires aUserobject with write access.persist_sessions_in_knowledge_graph_pipeline(user, session_ids, dataset)— reads the cached session data and writes it into the knowledge graph.
What Changed in Your Graph
- New nodes are created from the session Q&A history, grouped under the
user_sessions_from_cachenode set. - The session data is processed through
cognee.addandcognee.cognifyinternally, so entities and relationships from the session content become part of the graph.
Parameters
Parameters
user(User, required) — authenticated user with write access. Obtain viaawait get_default_user().session_ids(Optional[List[str]]) — list of session IDs to persist. IfNone, no sessions are extracted.dataset(str, default:"main_dataset") — the dataset to write session data into.run_in_background(bool, default:False) — run asynchronously and return immediately.
Under the hood
Under the hood
Two tasks run in sequence:
extract_user_sessions— reads Q&A data from theSessionManagerfor the specifiedsession_ids.cognify_session— callscognee.addandcognee.cognifyon the extracted session data, writing the results into the graph under theuser_sessions_from_cachenode set.
Troubleshooting
Troubleshooting
- No sessions found — caching must be enabled and searches with a
session_idmust have been run first. See Sessions and Caching. - Error: no graph data found — run
cognee.add()andcognee.cognify()before calling this pipeline. - LLM errors — verify that your LLM provider is configured. See LLM Providers.
- Permission errors — the user must have write access to the target dataset. See Permissions.
Memify Concept
Understand how memify pipelines work
Sessions Guide
Learn how sessions and caching work in Cognee
Search
Query the enriched graph with specialized search types