Memory layer — vì sao AI quên plot và NovelKit xử lý thế nào
Memory layer giải thích vì sao AI hay quên plot — và cách NovelKit dùng 5 lớp memory trên Hermes để giữ tiểu thuyết AI dài kỳ.
“AI quên cốt truyện” là triệu chứng của kiến trúc sai, không phải model kém. Memory layer trong NovelKit tách nguồn sự thật (canon files) khỏi truy hồi (RAG, vector) và tóm tắt đã duyệt (Memory.md) — cô lập per-novel trên plugin novelkit_memory.
5 lớp memory NovelKit
- Canon Files — PROJECT_DNA, database, outlines: source of truth tuyệt đối.
- RAG SQLite — keyword retrieval, chunk theo canon.
- Vector DB — semantic search; context-engine RRF rerank.
- Episodic Memory — sự kiện theo chương, commit sau sync.
- Curated Memory.md — tóm tắt human/agent duyệt, giới hạn từ (MEMORY_ACTIVE_MAX_WORDS).
Memory chỉ cập nhật sau sync
Chương chưa PASS 85+ không được đưa vào memory stack — tránh ô nhiễm canon. sync commit chạy: review gate → cập nhật PLAN/GOAL → reindex → episodic → doctor → provenance.
Disk beats chat, canon beats index
Khi mâu thuẫn, file owner thắng. Index/memory không lật canon. Chi tiết: Canon file-first. So chatbot: vs ChatGPT.
Episodic vs curated — khi nào dùng lớp nào
Episodic ghi chi tiết sự kiện chương — phục vụ retrieval ngắn hạn. Curated Memory.md là distillation đã duyệt — phục vụ context dài hạn trong budget từ (3500 words active max). Agent không được nhồi toàn bộ episodic vào prompt — context-engine budget và RRF rerank.
Per-novel isolation
Hai novel trên cùng Studio không chia memory. Publisher chạy 10 pilot song song không lo trộn nhân vật title A vào title B — yêu cầu bắt buộc cho catalog đa thể loại.
rolling_seed sau sync
Hermes cron chạy rolling_seed sau mỗi sync thành công — giữ seed continuity cho generation tiếp theo mà không phụ thuộc chat history. Cấu hình trong schedule.json của NovelKit.
Memory layer: vì sao AI quên plot và cách NovelKit fix
Triệu chứng memory layer AI quên plot là hệ quả kiến trúc — chat nhồi context window, không có sync gate, index ghi đè canon. NovelKit plugin novelkit_memory model 5 lớp tách nguồn sự thật khỏi truy hồi: A canon files, B RAG FTS, C vector semantic, D episodic itemized facts, E curated Memory.md. Principle P5: derivative layers (B–E) không bao giờ override canon A.
Chương chưa PASS ≥85 không commit vào episodic hay reindex — tránh ô nhiễm stack. Sync commit chạy: gate → cập nhật PLAN/GOAL → reindex context-engine → episodic upsert → curate Memory.md trong MEMORY_ACTIVE_MAX_WORDS (~3500 active max) → doctor → provenance.
Episodic vs curated: khi nào agent đọc lớp nào
Layer D episodic: chi tiết sự kiện per chapter, commit sau sync — phục vụ retrieval ngắn hạn và fact lookup. Layer E Memory.md: distillation đã duyệt — phục vụ context dài hạn trong budget. Agent không dump toàn episodic vào prompt; novelkit-context budget + RRF rerank chọn chunk liên quan từ B/C/D/E.
Per-novel isolation (P7)
Mỗi novel một items.sqlite3 keyed by workspace path. Hai title trên Studio không chia store — 10 pilot song song không trộn nhân vật A vào B. Publisher catalog đa thể loại yêu cầu bắt buộc này.
rolling_seed và style_audit trên Hermes cron
Sau sync thành công, cron rolling_seed cập nhật seed continuity cho generation tiếp — không phụ thuộc chat history ephemeral. style_audit mỗi 10 chương bắt voice/plot drift trước reader churn. Cấu hình schedule.json NovelKit; Lãng Khách không cần manual trigger.
5 lớp memory: chi tiết kỹ thuật
Layer A — canon files: PROJECT_DNA, database/*, outlines, chapters, reviews. Layer B — RAG FTS trong novelkit-context. Layer C — vector semantic. Layer D — episodic itemized facts per chapter, commit sau sync PASS ≥85. Layer E — Memory.md curated distillation trong MEMORY_ACTIVE_MAX_WORDS (~3500 active max). Principle P5: B–E không override A; agent báo CANON_CONFLICT.
Sync commit sequence
- Gate PASS ≥85 xác nhận
- Cập nhật PLAN/GOAL trong workspace
- Reindex novelkit-context (RAG + vector)
- Episodic upsert layer D
- Curate Memory.md layer E trong budget
- Doctor health-check + provenance ghi log
Chương chưa PASS không commit episodic hay reindex — tránh ô nhiễm stack. Per-novel isolation P7: mỗi novel một items.sqlite3 keyed by workspace path. Publisher catalog đa thể loại — 10 pilot song song không trộn nhân vật title A vào B.
| Triệu chứng quên plot | Nguyên nhân chat | NovelKit fix |
|---|---|---|
| Nhân vật phụ biến mất | Context window đầy | character registry + episodic D |
| Timeline lệch | Không file owner | master timeline + gate continuity |
| Voice drift chương 40+ | Không audit | style_audit cron mỗi 10 chương |
Cluster: canon file-first, story bible, truyện dài, pipeline, quality gate.
FAQ memory layer
- RAG snippet sai canon thì sao?
- P5: file owner thắng — agent báo CANON_CONFLICT, không merge im lặng.
- Memory.md ai viết?
- Curate sau sync trong budget ~3500 từ — distillation đã duyệt, không raw dump.
- rolling_seed là gì?
- Cron sau sync cập nhật seed continuity — không phụ thuộc chat history.
Chương chưa PASS ≥85 không upsert episodic layer D hay reindex RAG — tránh ô nhiễm stack memory. Per-novel isolation P7: workspace path keyed items.sqlite3 cho catalog đa title trên Studio.
Memory layer fix triệu chứng AI quên plot bằng kiến trúc — không phải prompt dài hơn.
MEMORY_ACTIVE_MAX_WORDS và rotation
Curated Memory.md giới hạn ~3500 từ active — rotation giữ fact quan trọng, archive phần cũ vào episodic/RAG. Tránh prompt balloon khi truyện 200 chương. Canon files vẫn đầy đủ trên disk; memory chỉ là working set cho generation.
Per-novel isolation
Mỗi novel workspace có SQLite memory riêng — title A không leak nhân vật vào title B. Critical cho studio chạy 10+ catalog song song.