Memory layer — why AI forgets the plot and how NovelKit handles it
Memory layer explains why AI often forgets the plot — and how NovelKit uses 5 memory layers on Hermes to sustain long-running AI fiction.
"AI forgets the plot" is a symptom of the wrong architecture, not a weak model. The Memory layer in NovelKit separates the source of truth (canon files) from retrieval (RAG, vector) and reviewed summaries (Memory.md) — isolated per-novel on the novelkit_memory plugin.
NovelKit's 5 memory layers
- Canon Files — PROJECT_DNA, database, outlines: the absolute source of truth.
- RAG SQLite — keyword retrieval, chunked to canon.
- Vector DB — semantic search; context-engine RRF rerank.
- Episodic Memory — per-chapter events, committed after sync.
- Curated Memory.md — a human/agent-reviewed summary, word-limited (MEMORY_ACTIVE_MAX_WORDS).
Memory only updates after sync
A chapter that has not yet reached PASS 85+ is not admitted into the memory stack — avoiding canon pollution. sync commit runs: review gate → update PLAN/GOAL → reindex → episodic → doctor → provenance.
Disk beats chat, canon beats index
On conflict, the file owner wins. Index/memory does not override canon. Details: Canon file-first. Versus a chatbot: vs ChatGPT.
Episodic vs curated — when to use which layer
Episodic records the details of chapter events — serving short-term retrieval. Curated Memory.md is a reviewed distillation — serving long-term context within a word budget (3500 words active max). The agent cannot cram all episodic memory into the prompt — context-engine budget and RRF rerank.
Per-novel isolation
Two novels on the same Studio do not share memory. A Publisher running 10 pilots in parallel need not worry about mixing characters from title A into title B — a mandatory requirement for a multi-genre catalog.
rolling_seed after sync
Hermes cron runs rolling_seed after every successful sync — keeping seed continuity for the next generation without depending on chat history. Configured in NovelKit's schedule.json.
Memory layer: why AI forgets the plot and how NovelKit fixes it
The memory layer AI forgets the plot symptom is a consequence of architecture — chat crams the context window, has no sync gate, and the index overwrites canon. The NovelKit novelkit_memory plugin models 5 layers that separate the source of truth from retrieval: A canon files, B RAG FTS, C vector semantic, D episodic itemized facts, E curated Memory.md. Principle P5: derivative layers (B–E) never override canon A.
A chapter that has not reached PASS ≥85 is not committed to episodic or reindexed — avoiding stack pollution. Sync commit runs: gate → update PLAN/GOAL → reindex context-engine → episodic upsert → curate Memory.md within MEMORY_ACTIVE_MAX_WORDS (~3500 active max) → doctor → provenance.
Episodic vs curated: when the agent reads which layer
Layer D episodic: per-chapter event details, committed after sync — serving short-term retrieval and fact lookup. Layer E Memory.md: a reviewed distillation — serving long-term context within budget. The agent does not dump all of episodic into the prompt; novelkit-context budget + RRF rerank select the relevant chunks from B/C/D/E.
Per-novel isolation (P7)
Each novel gets one items.sqlite3 keyed by workspace path. Two titles on Studio do not share a store — 10 parallel pilots do not mix characters from A into B. A multi-genre Publisher catalog requires this.
rolling_seed and style_audit on Hermes cron
After a successful sync, cron rolling_seed updates seed continuity for the next generation — not depending on ephemeral chat history. style_audit every 10 chapters catches voice/plot drift before reader churn. Configured in NovelKit's schedule.json; Lãng Khách needs no manual trigger.
5 memory layers: technical detail
Layer A — canon files: PROJECT_DNA, database/*, outlines, chapters, reviews. Layer B — RAG FTS in novelkit-context. Layer C — vector semantic. Layer D — episodic itemized facts per chapter, committed after PASS ≥85 sync. Layer E — Memory.md curated distillation within MEMORY_ACTIVE_MAX_WORDS (~3500 active max). Principle P5: B–E do not override A; the agent reports CANON_CONFLICT.
Sync commit sequence
- Gate PASS ≥85 confirmed
- Update PLAN/GOAL in the workspace
- Reindex novelkit-context (RAG + vector)
- Episodic upsert layer D
- Curate Memory.md layer E within budget
- Doctor health-check + provenance logging
A chapter that has not reached PASS is not committed to episodic or reindexed — avoiding stack pollution. Per-novel isolation P7: each novel gets one items.sqlite3 keyed by workspace path. Multi-genre Publisher catalog — 10 parallel pilots do not mix characters from title A into B.
| Forgotten-plot symptom | Chat cause | NovelKit fix |
|---|---|---|
| Side character disappears | Context window full | character registry + episodic D |
| Timeline drifts | No file owner | master timeline + gate continuity |
| Voice drift at chapter 40+ | No audit | style_audit cron every 10 chapters |
Cluster: canon file-first, story bible, long-form fiction, pipeline, quality gate.
Memory layer FAQ
- What if a RAG snippet contradicts canon?
- P5: the file owner wins — the agent reports CANON_CONFLICT, no silent merge.
- Who writes Memory.md?
- Curated after sync within a ~3500-word budget — a reviewed distillation, not a raw dump.
- What is rolling_seed?
- A cron after sync that updates seed continuity — not depending on chat history.
A chapter that has not reached PASS ≥85 does not upsert episodic layer D or reindex RAG — avoiding memory stack pollution. Per-novel isolation P7: workspace-path-keyed items.sqlite3 for a multi-title catalog on Studio.
The memory layer fixes the AI-forgets-the-plot symptom through architecture — not a longer prompt.
MEMORY_ACTIVE_MAX_WORDS and rotation
Curated Memory.md is limited to ~3500 active words — rotation keeps important facts and archives the old parts into episodic/RAG. This avoids prompt balloon in a 200-chapter story. Canon files remain complete on disk; memory is only the working set for generation.
Per-novel isolation
Each novel workspace has its own SQLite memory — title A does not leak characters into title B. Critical for a studio running 10+ catalogs in parallel.