Skip to main content
A guide to the two halves of session memory in one script: while a session runs, its QA turns are indexed for vector recall and stated guidance is kept as active working memory; after it ends, distill_session() writes the surviving lessons into the graph. Use it when a conversation is long enough that a plain recency window drops relevant turns, and you want what was learned to outlive the session.

Before You Start

search_session_qa_ids and select_hybrid_qa_entries are internal helpers used here to show what hybrid history selection picks. Recall performs this selection for you; you do not normally call them yourself.

Code in Action

What Just Happened

Step 1: Turn On Guidance Capture

AUTO_FEEDBACK controls whether what the user states is captured as learned guidance — active working memory that distillation later gates. It is on by default; the script sets it explicitly so a local override can’t silently turn guidance capture off.

Step 2: Ingest the Facts the Session Talks About

Six facts about Aurora Robotics give the session something to answer from. self_improvement=False keeps ingestion plain, so anything the graph knows at the end about firmware flashing came from the session, not from this step.

Step 3: Replay an Eight-Message Session

Every message goes through one recall() on the same session_id, which is what indexes the turn and captures stated guidance. The messages are ordered on purpose: durable lessons come early, ordinary questions after them, so the lessons fall outside the recency window by the time the last message arrives.

Step 4: See Which Old Turns Vector Recall Brings Back

Hybrid history selection combines the last last_n turns with turns that vector search finds relevant to the query. With a recency window of two, the calibration lesson from early in the session should still be selected — by similarity, not position — while older off-topic turns are left out.

Step 5: Distill the Session and Ask a Fresh One

distill_session() gates the session’s learned guidance, curates it against the existing graph, and cognifies the surviving lessons into the dataset as long-term memory; result.status and result.documents report what was written. The final recall() runs in a brand-new session with no conversation history, so an answer that still knows calibration must be re-run could only have come from the graph.

Session Distillation

The minimal before/after distillation example this one builds on

Sessions

How sessions and conversation history work in Cognee

Improve

Bridge whole sessions — QA, traces, and guidance — in one pass