Graph-Powered Storyworlds
Using Neo4j To Keep 1M+ Word LitRPG Epics Coherent With AI
Prem Chandrasekaran
Market Tech Director, Thoughtworks
NODES AI 2026
Hi, I'm Prem. I've been building an AI-assisted authoring platform for LitRPG novels. LitRPG is a genre where characters live inside game-like worlds — they have stats, skills, inventories, quest logs, level-ups — all embedded right in the prose. Think "Ready Player One" meets Dungeons and Dragons. The author writes the story — but they need AI to help keep it consistent across a million words. That's the challenge. Let me show you.
The Promise
The prompt:
"Help me finish this chapter. Marcus Stone enters the tavern and meets Elena..."
Claude writes:
"Marcus rested his right hand on his sword hilt. Something feels wrong."
Chapter 1 established:
"He'd lost his right arm in the Battle of Ashford. He lifted his mug with his remaining left hand."
Marcus does not have a right hand.
You ask the LLM to help you finish a chapter. It writes something perfectly reasonable...
[CLICK]
...until you remember what happened 46 chapters ago.
[CLICK]
Marcus lost his right arm. The LLM forgot. This isn't hypothetical — it's from a test manuscript I built.
The Scale of LitRPG
"Your readers have a better knowledge graph of your world than your LLM does."
This is why it matters. LitRPG is a genre built on precision — readers track stats, levels, inventories across millions of words. They'll catch what your LLM won't.
[CLICK]
Your readers literally have a better knowledge graph of your world than your LLM does. So how do you fix that?
Context Windows ≠ Memory
50%
Coherence collapses fast
LLM memory coherence drops to ~50% after just 5 rounds of interaction
2/9
Worldview is fragile
Only 2 of 9 LLMs maintained a consistent fictional worldview
∞
Multi-book state
Series state spans beyond any context window
"Attention is not memory."
The obvious answer is: throw it all in the context window. But the research says otherwise.
[CLICK]
Coherence drops to 50% after just 5 interactions.
[CLICK]
Only 2 of 9 LLMs held a consistent worldview.
[CLICK]
Attention is not memory. So what about RAG?
Vector Search ≠ Consistency
"Elena has blue eyes"
"Elena has green eyes"
cosine similarity: 0.97
These facts are semantically similar . They are also contradictory .
On schema-heavy queries, vector RAG scores 0% .
"Similarity is not consistency."
Blue eyes and green eyes land in the same neighborhood in embedding space.
[CLICK]
Cosine similarity 0.97. Semantically similar — but contradictory. Vector search finds relevant context. It cannot find contradictions.
[CLICK]
And on structured queries like stat tracking, vector RAG scores literally zero.
[CLICK]
Similarity is not consistency. So we need something fundamentally different.
The Insight
What if we gave the LLM a memory that knows
what is true ,
when it became true ,
and what rules it must follow ?
The graph becomes the immune system that catches the failures LLMs inevitably produce.
What if the LLM had a memory that knows...
[CLICK]
...what's true...
[CLICK]
...when it became true...
[CLICK]
...and what rules apply?
[CLICK]
Not a context window. Not a vector index. A knowledge graph. An immune system for your narrative.
LitRPG: Structured Data in Disguise
Raw prose
> **LEVEL UP!**
> Level: 1 → 2
> **Skill Unlocked:** *Fireball*
> **Quest Accepted: *The Lost Caravan***
**[STATUS - USER: ELENA BLACKWOOD]**
| Stat | Value |
| HP | 45/45 |
| Mana | 30/30 |
| Strength | 8 |
Extracted data
[
{"type": "LEVEL_UP",
"from": 1, "to": 2},
{"type": "SKILL_ACQUIRED",
"name": "Fireball"},
{"type": "QUEST_ACCEPTED",
"name": "The Lost Caravan"},
{"type": "STAT_BLOCK",
"entity": "Elena Blackwood",
"stats": {"HP": 45, "Mana": 30,
"Strength": 8}}
]
"Every LitRPG novel is secretly a database changelog wrapped in a story."
Here's what makes LitRPG the perfect domain for this. The game mechanics are right there in the prose — level-ups, stat blocks, quest updates.
[CLICK]
Regex pulls them out at 100% confidence. No LLM needed. Free facts.
[CLICK]
Every LitRPG novel is secretly a database changelog wrapped in a story. Now let me show you the full architecture.
Architecture
📄
Manuscript
DOCX / Markdown
→
🔍
Extraction
Facts in
Query-Driven Ontology Multi-Pass Extraction
→
🕸
Knowledge Graph
Neo4j
Cypher as Quality Rules Causal Chains Keeping the Graph in Sync
→
🤖
Agents
Use the graph
Graph as Agent Memory
→
✅
Validation
Check output
The pipeline is simple. Manuscript goes in, knowledge graph comes out, agents use it, contradictions get caught.
[CLICK]
Each phase has patterns we needed to solve. Let me walk you through them. So — we had Neo4j. We had a manuscript. We just needed to... put the stuff in the graph. How hard could it be? Turns out, the first question isn't how to extract — it's what to extract.
Manuscript → Extraction → Knowledge Graph → Agents → Validation
Query-Driven Ontology
↓ SchemaFromTextExtractor
~18 entity types, ~30 relationships
↓ author prunes
Custom factions • stat names • skill trees • quest chains
"The machine proposes. The author disposes."
What nodes and relationships does the graph need? Or as the graph folks say — what's your ontology?
We worked with domain experts to define a genre-level schema — the stuff that's true for all LitRPG. Characters, locations, facts, events. One important decision here: facts are nodes, not properties. We'll see why in a minute.
We fed that plus a few sample chapters into Neo4j's SchemaFromTextExtractor.
[CLICK]
It came back with 18 entity types and 30 relationships. Thanks, but no thanks.
[CLICK]
So the author prunes. What survives is a book-specific schema — the custom factions, stat names, and skill trees that make their world unique.
[CLICK]
The machine proposes. The author disposes. Now — how do we actually get facts into those nodes?
Manuscript → Extraction → Knowledge Graph → Agents → Validation
Multi-Pass Extraction
"She grabbed her staff" — who is "she"?
Extract structured elements: stat blocks, level-ups, damage confidence: 1.0
Find all character names and mentions confidence: 0.7–1.0
"she" → Lyra, "the healer" → Siv, "him" → Kael confidence: 0.7–1.0
Extract facts using resolved entity names confidence: 0.7–1.0
Cheap deterministic passes seed expensive LLM passes.
"She grabbed her staff." Great. Who is "she"? That's the pronoun problem. You can't just throw the whole chapter at an LLM and pray. We solve it in four passes, each one feeding the next.
[CLICK]
Pass 0: regex. Remember those free facts from the LitRPG prose? We grab them here. Zero cost, 100% confidence. This gives the standard Neo4j GraphRAG pipeline a head start — entity names and structured data before the LLM even touches the text.
[CLICK]
Pass 1: entity discovery. This is roughly what LLMGraphTransformer gives you. Find all the names.
[CLICK]
Pass 2: coreference resolution. "She" becomes Lyra. "The healer" becomes Siv. "Him" becomes Kael. Now the LLM knows who everyone is.
[CLICK]
Pass 3: attribute extraction — but now with resolved names. Each extracted fact carries a confidence score. The LLM self-reports how sure it is.
[CLICK]
Cheap passes feed expensive passes. Okay — facts are in the graph. What can we do with them?
Manuscript → Extraction → Knowledge Graph → Agents → Validation
Cypher as Quality Rules
describes rule in English
Text2Cypher
↓
Saved Rules
↓
Run against graph → consistency results
Facts are in the graph. Now we need to check them. We let technical users — typically platform admins — write Cypher queries directly and save them as reusable rules. But authors aren't writing Cypher. So we let them describe rules in plain English — "flag me if a character's eye color changes" — and Neo4j's Text2Cypher translates that into Cypher.
[CLICK]
Either way, the rules get saved and run against the graph. Let me show you what some of these rules look like.
Has This Character's Eye Color Changed?
-- Cypher: detect_fact_conflicts()
MATCH (f1:Fact), (f2:Fact)
WHERE f1.entity_name = f2.entity_name
AND f1.fact_key = f2.fact_key
AND toLower(f1.fact_value) <> toLower(f2.fact_value)
AND f1.is_stale = false
AND f2.is_stale = false
AND id(f1) < id(f2)
RETURN f1.entity_name as entity,
f1.fact_key as fact_type,
collect(DISTINCT f1.fact_value)
+ collect(DISTINCT f2.fact_value) as values
entity fact_type values
elena blackwood eye_color ["blue", "green", "brown"]
elena blackwood staff_material ["oak", "maple", "pine"]
A continuity error detector in 12 lines of Cypher.
Here's what a rule looks like. Twelve lines of Cypher — find any two non-stale facts about the same entity and attribute with different values.
[CLICK]
Run it — Elena's eyes went from blue to green to brown. Staff went from oak to maple to pine. A continuity error detector you can write in minutes. What about temporal rules?
Is a Dead Character Acting?
# From validation/temporal.py
class LifeStateMachine:
VALID_TRANSITIONS = {
"alive": {"dead", "unknown"},
"unknown": {"alive", "dead"},
}
# "dead" -> anything = CRITICAL violation
# (unless explicit resurrection mechanic)
Chapter 2: Old Tom's body found in the forest
Chapter 3: Old Tom emerges from the shadows, eyes glowing red
System flags it. Author reviews. (It's a twin — intentional.)
We model life state as a state machine. Alive to dead — valid.
[CLICK]
Dead to alive — critical violation. Here's the code.
[CLICK]
In our test manuscript, Old Tom dies in chapter 2 and shows up in chapter 3. The system flags it. Turns out it's his twin — intentional. The graph flags. The human decides. What about subtler issues?
Stats Changed Without a Reason?
MATCH (c:Character)-[s1:HAS_STAT {name: 'strength'}]->(scene1:Scene),
(c)-[s2:HAS_STAT {name: 'strength'}]->(scene2:Scene)
WHERE scene2.sequence = scene1.sequence + 1
AND s1.value <> s2.value
AND NOT EXISTS {
MATCH (c)-[:PARTICIPATES_IN]->(e:Event)
-[:MODIFIES_STAT]->(c)
WHERE e.scene = scene2.id AND e.stat = 'strength'
}
RETURN c.name, s1.value, s2.value,
scene1.title, scene2.title
Strength went from 12 to 15 between scenes — but nothing happened to cause it.
This one's my favorite for the Neo4j crowd. The query checks consecutive scenes for stat changes that have no triggering event in the graph.
[CLICK]
Strength jumped from 12 to 15 — but nothing in the event chain explains why. Here's another example from our test data.
Using a Missing Limb?
Chapter 1 establishes:
"He'd lost his right arm in the Battle of Ashford."
Chapter 2 says:
"adjusting his horse's saddle with both hands "
"resting his right hand on his sword hilt"
Chapter 3 says:
"holding up his right arm to stop her"
"the blade raised in both hands "
4 violations caught automatically from a single established fact.
Chapter 1: Marcus lost his right arm.
[CLICK]
Chapter 2: adjusting his saddle with "both hands," resting "his right hand" on his sword.
[CLICK]
Chapter 3: holding up "his right arm," blade raised in "both hands." Four violations from a single established fact. The graph also tracks dynamic events.
Manuscript → Extraction → Knowledge Graph → Agents → Validation
Causal Chains
Facts are static
(elena)-[:HAS_FACT]->
(:Fact {key: "eye_color",
value: "blue"})
Events are dynamic
Kill Wolf
↓ triggers
XP Gain (+50)
↓ triggers
Level Up (2 → 3)
↓ triggers
Stat Increase (STR +2)
triggers
enables
requires
leads_to
simultaneous
"Causal chains are plot structure. If you can extract causality, you can detect plot holes."
Same idea, different Cypher queries. Events in LitRPG form causal chains — kill a wolf, gain XP, level up, stats increase.
[CLICK]
If a reward shows up without a quest completion, the chain is broken. Another plot hole caught by the same rule engine. But authors rewrite. How do we keep all of this current?
Manuscript → Extraction → Knowledge Graph → Agents → Validation
Keeping the Graph in Sync
→
→
🔄
Re-extract
incremental or full
→
Incremental
Re-extract edited chapter only. Fast, cheap. On every save.
Full
Re-extract entire book. Expensive, thorough. At milestones.
"The graph is a living document, not a one-time extraction."
So the graph has to keep up. We mark facts from the edited chapter as stale, re-extract, then clean up. But the re-extraction step is a trade-off.
[CLICK]
Incremental: just re-extract the chapter that changed. Fast, cheap, do it on every save. But you might miss cross-chapter impacts — an edit in chapter 5 could contradict something in chapter 2.
Full: re-extract the entire book. Expensive — remember, 3-4 LLM calls per chunk — but guaranteed consistency. You do this at milestones. Draft complete, structural rewrite, before sending to an editor.
[CLICK]
The graph is a living document. Now the graph is current — how do agents actually use it?
Manuscript → Extraction → Knowledge Graph → Agents → Validation
Graph as Agent Memory
↓
Static rules
Saved Cypher queries run automatically
eye color drift, dead characters, missing limbs
Dynamic queries
LLM reads new text + graph schema → generates ad-hoc Cypher via Text2Cypher
catches what you didn't think to write rules for
↓
Neo4j → contradictions flagged inline
When the author saves, a validation agent kicks off. It does two things.
First: the static rules we just saw — the saved Cypher queries — run automatically against the graph. Eye color drift, dead characters, missing limbs. The known problems.
[CLICK]
Second — and this is where it gets interesting — the LLM reads what the author just wrote, looks at the graph schema, and generates its own Cypher queries via Text2Cypher. It checks things you didn't think to write rules for. The unknown unknowns.
[CLICK]
Both layers hit Neo4j. Contradictions come back as inline comments. The graph turns 500K words of novel into about 2KB of targeted context for the LLM. And these patterns aren't limited to fiction.
Beyond Novels
The same pattern applies wherever content islong-lived, interconnected, and evolving :
Legal briefs
Medical records
Product documentation
Game design
Regulatory compliance
Screenplay writing
"If your system needs to remember, check, or stay consistent — you need a graph."
We built this for LitRPG novels. But anywhere content is long-lived, interconnected, and evolving — you hit the same problem.
[CLICK]
Legal briefs that reference prior rulings. Medical records that span decades. Product docs that 50 engineers are editing simultaneously. Same problem, same solution.
[CLICK]
If your system needs to remember, check, or stay consistent — you need a graph.
What's Hard (Honestly)
Entity resolution
"the healer" = "Lyra" = "she" = "her" — below 85% accuracy, the whole graph is unreliable
Extraction cost
3-4 LLM calls per chunk per chapter — not cheap at scale
False positives
The Tom twin scenario — intentional plot twists get flagged
Sync during rapid edits
Authors rewrite fast — incremental vs full re-extract is a real trade-off
"The graph doesn't replace human judgment. It amplifies it."
Now let me be honest about what's hard — because if I don't tell you, you'll find out the hard way. Entity resolution is the one that'll hurt you first. "The healer," "Lyra," "she," "her" — if you can't resolve those below 85% accuracy, the graph is full of orphan facts and everything downstream is wrong.
Extraction is expensive. False positives are annoying — the system will flag your clever plot twists. And keeping the graph current when an author is rewriting furiously? Still an unsolved UX problem.
[CLICK]
But here's the thing. The graph doesn't replace human judgment. It amplifies it. And that's enough.
Questions?
Thank you. I'd love to hear about your use cases — where else could this pattern apply? Questions?