Skip to main content
Guidance a user states during a session — preferences, corrections, durable instructions — is short-term by default: it lives in the session cache and expires with it. Session distillation bridges that guidance into long-term memory by turning a session’s accepted, gated guidance into permanent lesson documents in the knowledge graph, tagged with the 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:

How to Distill a Session

Sessions can be bridged into the knowledge graph with improve(), which can persist cached Q&A, persist agent traces, and distill accepted session guidance into session_learnings:
If you only want to distill one finished session’s gated guidance, call cognee.session.distill_session() directly:
The direct result includes 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. Setting AUTO_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:
2. Ask before distillation. With no known preference, recall() (RAG_COMPLETION) makes an arbitrary pick:
3. State the opposite preference in the same session so the answer has to flip. Here the model picked Oreos first, so the user states a savory preference — the full example below detects the first pick and states the opposite preference for either case:
4. Distill the session into long-term memory. The curated preference lesson becomes a retrievable chunk in the graph:
5. Ask again in a fresh session. A brand-new session with no memory of the conversation still recalls the preference, so the recommendation now respects it:

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.

Going Further

Distilled session_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.

Sessions Guide

Learn how sessions and caching work in Cognee

Improve

Bridge sessions into the permanent graph with the improve pass