← Talks

Graph-Powered Storyworlds

Using Neo4j To Keep 1M+ Word
LitRPG Epics Coherent With AI

Prem Chandrasekaran

Market Tech Director, Thoughtworks

NODES AI 2026

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.

The Scale of LitRPG

300-500K
words per book
5-15
books per series
40+
named characters
200+
locations & items

"Your readers have a better knowledge graph of your world than your LLM does."

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."

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."

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.

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."

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
Manuscript→Extraction→Knowledge Graph→Agents→Validation

Query-Driven Ontology

Genre Ontology stable
Character • Location • Fact • Event • Scene • Skill
curated with domain experts
+
Sample chapters
↓ SchemaFromTextExtractor
~18 entity types, ~30 relationships
↓ author prunes
Book Ontology evolves per book
Custom factions • stat names • skill trees • quest chains

"The machine proposes. The author disposes."

Manuscript→Extraction→Knowledge Graph→Agents→Validation

Multi-Pass Extraction

"She grabbed her staff" — who is "she"?

Pass 0 Regex ~0ms
Extract structured elements: stat blocks, level-ups, damageconfidence: 1.0
Pass 1 Entity Discovery LLM ≈ LLMGraphTransformer
Find all character names and mentionsconfidence: 0.7–1.0
Pass 2 Coreference Resolution LLM
"she" → Lyra, "the healer" → Siv, "him" → Kaelconfidence: 0.7–1.0
Pass 3 Attribute Extraction LLM
Extract facts using resolved entity namesconfidence: 0.7–1.0

Cheap deterministic passes seed expensive LLM passes.

Manuscript→Extraction→Knowledge Graph→Agents→Validation

Cypher as Quality Rules

Technical user
writes Cypher directly
Non-technical user
describes rule in English
Text2Cypher
↓
Saved Rules
↓
Run against graph → consistency results

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
entityfact_typevalues
elena blackwoodeye_color["blue", "green", "brown"]
elena blackwoodstaff_material["oak", "maple", "pine"]

A continuity error detector in 12 lines of Cypher.

Is a Dead Character Acting?

alive
→
dead
↩ INVALID
# 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.)

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.

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.

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."

Manuscript→Extraction→Knowledge Graph→Agents→Validation

Keeping the Graph in Sync

✏

Chapter edited

→
🚩

Mark facts stale

→
🔄

Re-extract

incremental or full

→
🗑

Delete stale

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."

Manuscript→Extraction→Knowledge Graph→Agents→Validation

Graph as Agent Memory

Author saves chapter
↓
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

Beyond Novels

The same pattern applies wherever content is
long-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."

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."

Questions?