session_learnings node set. A brand-new session with no memory of the original conversation will then recall and respect what was learned.
Before you start:
- Complete Quickstart or have Cognee installed and configured
- Ensure you have LLM Providers configured
- Be familiar with Sessions and the
remember()/recall()workflow - Caching must be enabled so session Q&A history is retained
How to Distill a Session
Sessions can be bridged into the knowledge graph withimprove(), which can persist cached Q&A, persist agent traces, and distill accepted session guidance into session_learnings:
cognee.session.distill_session() directly:
status and documents. A completed run writes accepted lesson documents back into the dataset; statuses such as no_gated_entries or no_accepted_lessons mean there was nothing durable enough to persist.
Example: Learning a Snack Preference
A minimal end-to-end demo of session distillation: state a preference in one session, distill that session into the knowledge graph, then confirm that a fresh session’s recall now reflects the learned preference. SettingAUTO_FEEDBACK=true lets the session capture the user’s stated preference as learned guidance during distillation.
How It Works
1. Remember two neutral snack facts. The graph starts with one sweet and one savory snack — and no preference:recall() (RAG_COMPLETION) makes an arbitrary pick:
Full Example
The complete runnable script is on GitHub:examples/guides/session_distillation.py. It picks the opposite of the model’s first pick as the stated preference and then asserts the recommendation flips — a self-checking way to prove distillation changed the outcome.
Full example script
Full example script
Going Further
Distilledsession_learnings are the foundation for other self-improvement features: improve() bridges whole sessions (Q&A, traces, and guidance) in one pass, and truth-subspace reranking builds retrieval anchors from distilled lessons.
An advanced companion script is on GitHub: examples/advanced_guides/session_distillation_demo.py. It replays an eight-message session so Q&A history accumulates, then shows which of those older turns hybrid vector recall brings back once a plain recency window would have dropped them, and distills only afterwards — covering the retrieval half of session memory that the before/after example above leaves out.
Sessions Guide
Learn how sessions and caching work in Cognee
Improve
Bridge sessions into the permanent graph with the improve pass