Skip to content

feat(memory): Rearchitect episodic tier for native chat conversation storage #518

Description

@novaspectrayan

Summary

Rearchitect the EPISODIC memory tier to natively store chat conversations as log-structured, variable-length experience records with a reinterpreted 64B header and inline CBOR document bodies — replacing the current anti-pattern of routing raw chat turns through the full cognitive ingestion pipeline (SEMANTIC tier + embedding + HNSW + BM25 + SPLADE + Hebbian + entity extraction).

ADR: ADR-0006 (Episodic Conversation Architecture)

User Story

As a Spector agent, I want my chat conversations to be stored efficiently with sub-millisecond append latency and O(1) paginated retrieval, so that I can maintain rich conversation history without polluting my semantic knowledge base or paying unnecessary cognitive pipeline overhead.

Acceptance Criteria

  • EPISODIC tier uses reinterpreted 64B header: session_id (8B), role, sequence_id, body_length, timestamp — no Bloom filter, no importance, no emotional encoding
  • Chat turns stored as 64B header + inline CBOR body (variable-length, log-structured)
  • EpisodicLogMemory replaces fixed-stride EpisodicRecordMemory with append-only variable-length store
  • EpisodicSessionIndex provides O(1) pagination (by session, cursor-based, tail-N for LLM context)
  • Session index rebuilt on startup via single sequential mmap scan (sub-second for 100K records)
  • Lightweight ingestion path: bypasses embedding, HNSW, BM25, SPLADE, Hebbian, entity extraction
  • Chat text NOT indexed in shared text.dat (no BM25/SPLADE pollution)
  • SpectorChatMemoryRepository.findByConversationId() fixed: uses browse (not vector recall)
  • SpectorMemoryChatAdapter routes chat through storeEpisodic() instead of store()
  • Circadian reflection trigger still fires after N episodic writes
  • ConversationReflector reads from new episodic store and marks consolidated turns
  • Full Maven build passes: mvn clean verify -T1C

Scope

IN scope (MVP):

  • EpisodicFieldAccessor (header reinterpretation)
  • ConversationRole enum
  • EpisodicLogMemory (log-structured mmap store)
  • EpisodicSessionIndex (pagination index)
  • PartitionBundle EPISODIC region → variable-length
  • Synapse integration (MemoryService, ChatAdapter, ChatMemoryRepository)
  • ConversationReflector update

OUT of scope (future):

  • Session manifest persistence (optimization for fast session listing)
  • CBOR body compression
  • Cross-partition episodic queries
  • Episodic region compaction/GC

Getting Started

  1. Build: cd /home/bharat/git/spector && mvn clean verify -T1C
  2. Key files (memory module):
    • memory/spector-memory/.../kernel/layout/SynapticHeaderConstants.java
    • memory/spector-memory/.../cortex/EpisodicRecordMemory.java (to be replaced)
    • memory/spector-memory/.../kernel/bundle/PartitionBundle.java
    • memory/spector-memory/.../DefaultSpectorMemory.java
  3. Key files (synapse module):
    • synapse/spector-synapse/.../agent/chat/infrastructure/SpectorMemoryChatAdapter.java
    • synapse/spector-synapse/.../memory/MemoryService.java
    • synapse/spector-synapse/.../agent/memory/SpectorChatMemoryRepository.java

RICE-C Score

Factor Score Rationale
Reach 5/5 Every Spector agent with chat uses this
Impact 3x Sub-ms writes vs 30-80ms, eliminates SEMANTIC pollution
Confidence 90% Architecture validated through code audit with CEO
Effort L 5 phases, ~15 files, 2-3 weeks
Cognitive Fit 5/5 Core to Spector's neuroscience-inspired memory model

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions