AIKernel.NET
version: 0.0.2 / status: Refactor / edition: Draft / published: 2026-05-16 / updated: 2026-05-16

Semantic Memory Management Spec

Defines how AIKernel manages and optimizes semantic memory under finite token resources and attention constraints while preserving three-layer isolation (Orchestration / Material / Expression).

1. Concept: Context as Managed Memory

Traditional LLM implementations often treat context windows as a single FIFO queue, causing critical information to be pushed out. AIKernel redefines context as segmented memory space and manages resource allocation and purge priority by semantic role.

2. Memory Units and Architecture

2.1 ContextFragment

Smallest managed unit of semantic memory. Key fields:

  • Payload: text or structured content
  • Priority: purge resistance score (0.0..1.0)
  • Category: Orchestration / Material / Expression
  • Tokens: actual token footprint

2.2 Three-Layer Buffer Roles

  • Orchestration (O-Layer): task intent, constraints, signed rules. Highest protection priority.
  • Material (M-Layer): quarantined facts and RAG evidence. Functions as reasoning evidence.
  • Expression (E-Layer): generated intermediate text and prior outputs. Most purgeable layer.

3. Token Budget Policy

TotalBudget (model max window) is allocated with explicit reservation classes.

Area Reservation Type Characteristics
Orchestration Reserved (Hard) Minimum required intent/control budget; effectively non-purgeable.
System/Meta Safe Reserve Signature/hash/boundary overhead for verification and control.
Material Elastic Expands/contracts by task demand; can be swapped or summarized.
Expression Volatile Working generation space; oldest items are discarded first.

4. Priority Under Pressure (Eviction Strategy)

When UsedTokens > TotalBudget, release capacity using LIFO + semantic priority:

  1. Expression Purge: discard oldest Expression fragments first.
  2. Material Summarization: replace low-priority Material with summaries while preserving SourceInfo hash pointers.
  3. Orchestration Compaction: structurally compact command history, while protecting latest verifier-approved signed constraints.
  4. Halt: abort when compaction cannot preserve integrity.

5. Swap and Snapshot Policy

Overflow context is swapped out to snapshot storage.

  • Checkpoint Store: persist per-phase memory state for deterministic replay.
  • Lazy Swap-in: reload from snapshot only when modules (for example IVectorMatcher) require historical material.

6. Summarization and Integrity Rules

Compression must preserve semantic integrity:

  • Provenance Persistence: summaries must keep reference to original source hash.
  • Claim Boundary: multiple facts must not be collapsed into distorted single claims.
  • No Promotion: summaries are indexes, not equivalent to original evidence trust.

7. Fail-Closed Conditions (Safety)

AIKernel aborts and emits audit logs when:

  • Constraint Loss: required Orchestration constraints cannot be retained.
  • Provenance Gap: compression leaves evidence without provenance.
  • Verification Failure: reconstructed buffers break hash consistency against signed prompt artifacts.

Changelog

  • v0.0.0 / v0.0.0.0: Initial draft
  • v0.0.1 (2026-05-06): Version upgrade aligned with documentation guidelines
Source: architecture/12.SEMANTIC_MEMORY_MANAGEMENT_SPEC.md