Skip to main content

Module episodic_graph

Module episodic_graph 

Source
Expand description

EM-Graph: episodic event extraction and causal linking (issue #3713).

The Episodic Memory Graph stores conversation events (actions, decisions, discoveries, errors) as nodes connected by causal relationships. This is distinct from the entity-centric MAGMA graph stored in graph_edges — EM-Graph captures what happened and why, while MAGMA captures what is related to what.

§Storage

Events are stored in episodic_events and causal links in causal_links (both created by migration 086). Messages are never deleted (spec 001-6), so FK references from events to messages are always valid even after optical forgetting compresses the message content.

§Extraction

extract_events calls an LLM to identify events in a conversation turn. link_events detects causal relationships between the new events and recent events in the same session.

§Retrieval

recall_episodic_causal finds events relevant to a query and walks the causal graph to build a chain of causally-related events.

Structs§

CausalLink
A directed causal link between two episodic events.
EmGraphConfig
EM-Graph episodic event extraction and causal linking configuration.
EpisodicEvent
An episodic event extracted from a conversation turn.

Functions§

extract_events
Extract episodic events from a conversation turn via LLM.
fetch_recent_events
Retrieve recent events for a session (context for causal linking).
link_events
Detect causal links between new_events and recent_events via LLM.
recall_episodic_causal
Retrieve a causal chain of events starting from a seed event.
store_events
Persist extracted events to the episodic_events table.
store_links
Persist causal links to the causal_links table.