King Klown Logo
King Klown& KOA

RAG Memory System

Architectural Lineage (Credits):
SwarmCraft is an architectural fork and deep rewrite of the multi-agent swarm engine created by Mojomast in mojomast/swarmussy.
SwarmCraft’s deterministic “Architect-style” layering is also derived from the meta-structure of Abstract Wiki Architect (AWA).
Full details: Credits & Lineage

POWERED BY GROK

SwarmCraft uses Retrieval Augmented Generation (RAG) as an explicit long-term memory layer to maintain continuity across large stories.

RAG is not the Story Bible (intent).
RAG is not the Matrix (runtime state).
RAG is evidence: previously written text and relevant notes that can be retrieved and injected into the current Part’s prompt.


1) Why RAG Exists

LLMs have limited context windows. Without memory, long projects drift:

RAG solves this by:


2) What RAG Stores

Recommended indexed sources:

RAG SHOULD store per-chunk metadata:

RAG MUST NOT be treated as canonical intent. If RAG conflicts with Story Bible, Story Bible wins.

See: Story Bible


3) Storage Location (Per Project)

Recommended location:

This ensures multi-project isolation and avoids cross-story contamination.

See: Multi-Project Management


4) Ingestion (Write Path)

Ingestion typically occurs during SCAN.

Flow:

  1. Scanner detects changed manuscript files.
  2. File is chunked into semantic segments (paragraphs or sections).
  3. Each chunk is embedded (vectorized).
  4. Vectors + metadata are stored in the project’s vector database.

Deterministic pipeline: Deterministic Pipeline

4.1 Chunking recommendations

4.2 Deduplication recommendations


5) Retrieval (Read Path)

Retrieval occurs during prompt hydration for a Part.

Flow:

  1. Orchestrator builds a query set from:
    • the Part contract fields (goal/obstacle/turn/outcome)
    • high-signal beats (Plot/Conflict)
    • explicit continuity questions (if present)
  2. Vector search returns top-k relevant chunks.
  3. Orchestrator formats them as “evidence” and injects them into the prompt.

Prompt hydration: Orchestration Slice-by-Slice Prompt Hydration

5.1 Bounded retrieval (required)

To prevent prompt bloat:

Format each retrieved chunk with:

Example:

[RAG] Source: P014.md (CH05 / P014)
- "Mara always keeps her left hand gloved..."

6) RAG in Drafting vs Reviewing

6.1 Narrator (Draft/Revise)

Use RAG to:

6.2 Editor (Review)

Use RAG to:

Editor should treat RAG as evidence, not instructions.


Expose RAG through a small tool surface, e.g.:

Recommended role rules:


8) Failure Modes and Guards