Event-Sourced Memory

Append-only memory architecture with temporal queries and replay

advancedevent-sourcingtemporalauditreplay

Overview

Event-sourced memory treats every memory as an immutable event in a timeline. Rather than updating memories in place, new events are appended. This enables powerful capabilities: temporal queries, full audit trails, memory replay, and the ability to reconstruct state at any point in time.

Core Principles

Immutable Events

Memories are never modified:

  • Each interaction creates new events
  • Corrections are new events that supersede
  • Full history is preserved
  • No data loss from updates
  • Temporal Ordering

    Every event has a timestamp:

  • Query memories "as of" any time
  • Understand how knowledge evolved
  • Replay interactions chronologically
  • Track when beliefs changed
  • Event Types

    Categorize what happened:

  • Observation: Something was learned
  • Inference: Conclusion was drawn
  • Correction: Prior belief was updated
  • Deletion: Memory was invalidated
  • Interaction: Exchange occurred
  • Architecture

    ┌─────────────────────────────────────────────────────────────┐

    │ Event Stream │

    │ │

    │ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ │

    │ │ E001 │→│ E002 │→│ E003 │→│ E004 │→│ E005 │→│ E006 │→... │

    │ └──────┘ └──────┘ └──────┘ └──────┘ └──────┘ └──────┘ │

    │ │

    └──────────────────────────┬──────────────────────────────────┘

    ┌─────────────────────────────────────────────────────────────┐

    │ Materialized Views │

    │ │

    │ ┌─────────────────┐ ┌─────────────────┐ │

    │ │ Current State │ │ Temporal Index │ │

    │ │ (Latest facts) │ │ (By timestamp) │ │

    │ └─────────────────┘ └─────────────────┘ │

    │ │

    │ ┌─────────────────┐ ┌─────────────────┐ │

    │ │ Entity Index │ │ Topic Index │ │

    │ │ (By subject) │ │ (By theme) │ │

    │ └─────────────────┘ └─────────────────┘ │

    │ │

    └─────────────────────────────────────────────────────────────┘

    Event Schema

    Base Event Structure

    Event:

    ├── event_id: unique identifier

    ├── timestamp: when it occurred

    ├── event_type: observation | inference | correction | deletion

    ├── user_id: whose memory

    ├── session_id: which conversation

    ├── content: the actual memory

    ├── embedding: vector representation

    ├── metadata:

    │ ├── confidence: certainty level

    │ ├── source: where learned

    │ ├── supersedes: prior event_id (if correction)

    │ └── references: related event_ids

    Event Examples

    **Observation Event:**

    {

    event_type: "observation",

    content: "User prefers morning meetings",

    confidence: 0.8,

    source: "user_statement"

    }

    **Correction Event:**

    {

    event_type: "correction",

    content: "User actually prefers afternoon meetings",

    supersedes: "event_123",

    confidence: 0.95,

    source: "explicit_correction"

    }

    Query Patterns

    Current State Query

    "What do I know about this user now?"

  • Retrieve latest non-superseded events
  • Filter out deleted memories
  • Apply corrections in order
  • Return current belief state
  • Point-in-Time Query

    "What did I know on January 1st?"

  • Retrieve events up to timestamp
  • Apply supersession as of that time
  • Reconstruct historical belief state
  • Useful for auditing and debugging
  • Evolution Query

    "How has my understanding of X changed?"

  • Retrieve all events about topic X
  • Order chronologically
  • Show progression of beliefs
  • Highlight corrections and updates
  • Causation Query

    "Why do I believe X?"

  • Trace back to source events
  • Show inference chain
  • Identify original observations
  • Provide explainability
  • Handling Corrections

    Soft Supersession

    Old memory remains, marked as superseded:

    new_event = {

    event_type: "correction",

    content: "Updated belief",

    supersedes: old_event_id

    }

    Query filters out superseded events by default but can include them when needed.

    Hard Deletion

    For compliance (GDPR, etc.):

    deletion_event = {

    event_type: "deletion",

    deletes: event_id,

    reason: "user_request"

    }

    Can be logical (marker) or physical (actual removal) depending on requirements.

    Benefits

    Full Auditability

  • Know exactly what was learned when
  • Trace decisions to source events
  • Compliance and explainability
  • Debug unexpected behavior
  • Temporal Flexibility

  • Reconstruct any historical state
  • Understand belief evolution
  • Answer "when did this change?"
  • Support undo/rollback scenarios
  • Conflict Resolution

  • Detect conflicting beliefs
  • See which came first
  • Apply last-write-wins or custom logic
  • Preserve all perspectives
  • Implementation Considerations

    Storage Growth

    Events accumulate:

  • Implement compaction for old events
  • Snapshot current state periodically
  • Archive old events to cold storage
  • Monitor growth rate
  • Query Performance

    Multiple indexes needed:

  • Current state for fast retrieval
  • Temporal index for point-in-time
  • Semantic index for similarity search
  • Entity index for subject queries
  • Consistency

    In distributed systems:

  • Event ordering must be preserved
  • Eventual consistency acceptable for views
  • Strong consistency for event append
  • Handle out-of-order arrivals