Skip to content

Episodic-to-semantic memory consolidation (experimental)#578

Draft
kimjune01 wants to merge 3 commits intoSoarGroup:developmentfrom
kimjune01:epmem-consolidation
Draft

Episodic-to-semantic memory consolidation (experimental)#578
kimjune01 wants to merge 3 commits intoSoarGroup:developmentfrom
kimjune01:epmem-consolidation

Conversation

@kimjune01
Copy link
Copy Markdown

@kimjune01 kimjune01 commented Mar 25, 2026

Summary

Experimental / demonstration only. This PR adds episodic-to-semantic consolidation and episodic eviction — steps 1 and 2 of the Prescription: Soar. Together they close the loop that Derbinsky & Laird (2013) left open: semantic memory learns from experience, and episodes that have been consolidated become safely evictable.

Consolidation (step 1)

Periodically scans episodic memory for stable WME structures and writes them to semantic memory as new LTIs via CLI_add. Implements the compose+test framework from Casteigts et al. (2019).

Eviction (step 2)

After consolidation, deletes old episode point and range entries and episode rows past the eviction age. Safe because the consolidated knowledge is in smem — no reconstruction debt. Retrieval of evicted episodes returns ^retrieved no-memory via the existing valid_episode check.

Off by default — zero behavior change until explicitly enabled.

Parameters

Parameter Type Default Description
consolidate on/off off Enable periodic consolidation
consolidate-interval integer 100 Episodes between consolidation runs
consolidate-threshold integer 10 Min continuous presence to consolidate
consolidate-evict-age integer 0 (off) Min episode age before eviction eligible

Algorithm

Step Operation
Compose Union of constant WMEs active in epmem's _now table
Test Continuous presence ≥ consolidate-threshold episodes
Write Create smem LTI with qualifying augmentations
Dedup epmem_consolidated tracking table prevents repeated writes
Evict Delete point, range, and episode rows older than evict-age
Trigger Every consolidate-interval episodes

The compose+test scan is O(n) in active WMEs per consolidation run. Casteigts et al. prove this is optimal for any parameter computable through their framework.

Motivation

Derbinsky & Laird (2013) proved forgetting is essential to Soar's scaling but only built it for working and procedural memory. Episodic and semantic memory have no eviction and no capacity bound. The root cause (Diagnosis: Soar): you can only safely forget what you can reconstruct (R4), and semantic memory — the reconstruction target — doesn't learn automatically.

This patch addresses both halves:

  1. Consolidation — semantic memory learns from episodic experience
  2. Eviction — episodes whose regularities have been consolidated are redundant and can be removed

With these in place:

  • R4's forgettable WME scope expands (newly perceived categories get merged into smem)
  • Episodic store stays bounded instead of growing at 72,000 episodes/hour
  • The 50ms decision-cycle threshold has more headroom

Changes

File Change
episodic_memory.h 4 params, 1 stat, 7 prepared statements, function declaration
episodic_memory.cpp Param/stat init, SQL statements, schema table + drop, epmem_consolidate() with eviction (~200 lines), hook in epmem_go()
EpMemFunctionalTests.hpp 3 new test declarations
EpMemFunctionalTests.cpp 3 test implementations
2 new .soar test agents Consolidation and eviction test agents

Tests

46/46 epmem tests pass (43 existing + 3 new), zero regressions:

  • testConsolidation — stable WMEs written to smem after consolidation fires
  • testConsolidationOff — smem stays empty when feature is disabled
  • testConsolidationEviction — old episodes evicted, recent episodes preserved, smem entries intact

Known limitations (deferred)

  • Constant WMEs only — identifier (graph-structured) WMEs are not consolidated; consolidated LTIs are flat
  • No back-invalidation — cross-tier cache coherence when smem entries become stale (prescription step 3)
  • _now intervals preserved — active WME intervals are never split; only completed ranges and points are evicted

Reference


See also: #577 — RL convergence gate for chunking (prescription step 4)

Periodically scan episodic memory for stable WME structures and write
them to semantic memory as new LTIs.  This implements the compose+test
framework (Casteigts et al., 2019) for automatic episodic-to-semantic
knowledge transfer — the operation Soar's long-term declarative stores
have been missing.

Algorithm:
  compose — union of constant WMEs currently active in epmem
  test    — continuous presence >= consolidate-threshold episodes
  write   — create smem LTI with qualifying augmentations via CLI_add

New parameters (all under epmem):
  consolidate            on/off  (default off)
  consolidate-interval   integer (default 100) — episodes between runs
  consolidate-threshold  integer (default 10)  — min episode persistence

Deduplication via epmem_consolidated tracking table prevents repeated
writes across consolidation runs.  Table is dropped on reinit alongside
other epmem graph tables.

Off by default — zero behavior change until explicitly enabled.

Limitations (deferred to follow-up):
  - Only consolidates constant-valued WMEs, not identifier edges
  - No back-invalidation across the WM/smem tier boundary
  - last-consolidation stat does not persist across agent reinit

Motivation: Derbinsky & Laird (2013) proved forgetting is essential to
Soar's scaling but only built it for working and procedural memory.
Episodic and semantic memory have no eviction and no capacity bound.
This patch addresses the first half: automatic semantic learning from
episodic experience.  With semantic entries derived from episodes,
episodic eviction becomes safe (merged episodes leave no reconstruction
debt), and R4's forgettable WME scope expands automatically.

Reference:
  Casteigts et al. (2019), "Computing Parameters of Sequence-Based
    Dynamic Graphs," Theory of Computing Systems.
  Derbinsky & Laird (2013), "Effective and efficient forgetting of
    learned knowledge in Soar's working and procedural memories,"
    Cognitive Systems Research.
  https://june.kim/prescription-soar — full prescription
After consolidation writes stable WMEs to smem, old episodes become
redundant.  Delete point entries and episode rows older than
consolidate-evict-age episodes.  This is safe: the consolidated
knowledge is in smem, so there is no reconstruction debt.

New parameter:
  consolidate-evict-age  integer (default 0 = off) — min age before
  an episode is eligible for eviction

Range and _now interval entries are preserved (they span multiple
episodes).  Only point entries and episode rows are removed.

Reference: Derbinsky & Laird (2013), §5 — "forgotten working-memory
knowledge may be recovered via deliberate reconstruction from semantic
memory."  Consolidation creates the semantic entries; eviction removes
the source episodes that are no longer needed for reconstruction.
- Delete _range entries whose intervals end before the eviction cutoff
  (previously only _point entries were evicted, leaving dead weight)
- Wrap all eviction DELETEs in BEGIN/COMMIT when lazy_commit is off
  for atomicity (when lazy_commit is on, already inside a transaction)

Retrieval of evicted episodes is already safe: epmem_install_memory
checks valid_episode and returns ^retrieved no-memory.
@scijones
Copy link
Copy Markdown
Contributor

Wow, this and the other pull request. I need to review these, but thanks! These look exciting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants