How to Build a Lorebook for a Fantasy World From Scratch (Complete Step-by-Step Guide)

How to Build a Lorebook for a Fantasy World From Scratch (Complete Step-by-Step Guide)

Most fantasy AI characters start strong and fall apart after 20 messages.

Not because the writing is bad.

Because the world isn't built.

The character forgets the kingdom's history. They mix up the magic system. They answer questions about the war as if it never happened.

A Lorebook fixes this — without bloating your system prompt or burning tokens on lore that's not relevant yet.

This is how you build one from scratch, the right way.


What a Lorebook Actually Is

A Lorebook is a collection of context entries attached to a character.

Each entry has:

  • Trigger keywords — words or phrases that activate the entry
  • Content — the lore text injected into context when those keywords appear

When a user types "tell me about the war", the entry about the war activates.
When they mention "your sword", the weapon's lore loads.

The character knows — because the context was prepared exactly for that moment.

This is smarter than front-loading everything into the system prompt. Lorebooks inject only what's relevant right now, keeping context clean and the character consistent across hundreds of messages.


Step 1 — Define Your World's Three Pillars

Before opening the editor, answer three questions on paper:

1. What are the rules of this world?
Magic systems. Social hierarchies. Laws. Forbidden zones. What can and cannot exist.

2. What events shaped the present?
Wars. Disasters. Betrayals. Prophecies fulfilled or broken. The history that made the world what it is.

3. Who matters to your character?
Allies, enemies, mentors, rivals. Relationships and the weight they carry.

These become the skeleton of your Lorebook. Everything else is flesh on bone.


Step 2 — Open the Lorebook Editor in MegaNova Studio

Open your character in MegaNova Studio.

You'll see tabs at the top: Editor, Arena, Assets, Settings, Video, Lore, Versions.

Click Lore.

This is the Lorebook manager — every lorebook attached to your character lives here.

Click + Create New in the top right.

Give it a clear name:

[Character Name] — World Lore

Click Create. You now have an empty lorebook ready to fill.


Step 3 — Build the First Layer: World Rules

Click + Add Entry.

You'll see five fields:

Field What it does
Title Internal label. Only you see this.
Priority Number (default: 10). Higher = loads first when context is limited.
Keys Trigger words, comma-separated.
Content The lore text that gets injected.
Tags Optional. For organizing entries.

Start with your world's foundational rules. Here's an example for a dark fantasy world:

Title: Magic System — The Veil
Priority: 20
Keys: magic, spell, cast, veil, mana, power, arcane, sorcerer
Content:

Magic in this world draws from the Veil — a thin membrane between the living
world and the realm of the dead. Every spell tears the Veil slightly. Mages
who overuse their power risk becoming Hollow: bodies alive, souls partially
consumed. The Church of the Sealed Flame outlaws unsanctioned magic. Those
who practice it outside temple walls are hunted by Inquisitors.

Set Priority to 20 — this is foundational. It should load before less critical entries.

Click Save Entry.

Repeat for each core rule of your world. Aim for 3–5 rule entries to start.


Step 4 — Build the Second Layer: History and Events

These entries cover the events that shaped the world and your character's past.

Title: The Fall of Ironveil
Priority: 10
Keys: war, Ironveil, the fall, siege, king, betrayal, 300 years ago
Content:

Three hundred years ago, the kingdom of Ironveil fell not to an army — but to
its own king. Aldric the Pale made a pact with a Veil entity to extend his
reign. The entity took his soul, then his court, then the city. What remains
is the Ironveil Wastes: ruins where no bird flies and no plant grows. Scholars
debate whether the entity is still there, dormant, waiting.

Good history entries answer: What happened? Why does it still matter today?

Build 4–8 history entries covering the major events your character would reference in conversation.


Step 5 — Build the Third Layer: Personal Details

This is where your character becomes real.

Personal entries cover habits, relationships, preferences, and private knowledge — details only someone close would know.

Title: Relationship — Mira
Priority: 10
Keys: Mira, sister, family, home, village, before the academy
Content:

Mira is the character's younger sister. She stayed behind when the character
left for the Academy. They write letters, though the replies have grown shorter.
The character suspects Mira blames them for abandoning the family, but they've
never spoken it aloud. Mira has her mother's eyes and their father's stubbornness.

Personal entries make conversations feel like they're happening with a person, not a profile.

Add 5–10 personal entries for the characters and relationships that matter most.


Step 6 — Set Priorities for Budget Control

MegaNova's Lorebook system has a Context Budget — a percentage of the context window reserved for lorebook injection (default: 25%).

When multiple entries fire at once (the user mentions magic AND Ironveil AND Mira in one message), priority determines what loads first.

Use this structure:

Priority 20 — World rules and magic systems (always critical)
Priority 15 — Major historical events
Priority 10 — Relationships and personal history (standard)
Priority 5  — Minor flavor details, optional lore

You don't need to agonize over this. Start with 10 for everything, then adjust entries that are clearly more or less important than average.


Step 7 — Choose Keyword Mode or Semantic Mode

Inside the lorebook editor, you'll see a toggle: Keyword / Semantic.

Keyword mode — entry fires when the exact trigger words appear in the message. Precise and predictable.

Semantic mode — entry fires based on meaning, even without exact word matches. A user asking about "what happened to the old city" could trigger the Ironveil entry even without typing "Ironveil" or "war". Requires clicking Index All first to generate embeddings.

Recommended starting point:

  • Use Keyword while building and testing
  • Switch to Semantic once entries are stable and you want natural language coverage

The main risk with Semantic: entries fire too broadly. Keyword keeps things predictable while you're still refining.


Step 8 — Attach the Lorebook and Test It

Go back to the Lorebook list (click ← Back).

Click Attach on your lorebook. The card will show a green ATTACHED badge.

Now open the Editor tab. On the right side, find the Quick Test panel.

Type a message that includes one of your trigger keywords:

"Tell me about the magic system here"

If the character's response reflects the Veil lore you wrote — the lorebook is working.

If not, check your keywords:

  • Too specific → fires only on exact phrase
  • Too broad → fires on everything, dilutes context
  • Not matching → user isn't typing what you expected

Read actual user messages and adjust keywords to match how real people phrase things, not how you'd write documentation.


What to Put in the Lorebook vs. the System Prompt

System Prompt Lorebook
Core personality traits World events and history
Speech patterns and tone Location and setting details
Behavior rules Relationship context
Character's core identity Item and object lore

Rule of thumb:

If it's always true about who this character is → System Prompt.

If it's only relevant sometimes, depending on what the user asks → Lorebook.

A character's sarcastic wit belongs in the system prompt.
The lore about the haunted tower they visited at age twelve belongs in the Lorebook.


The 5-Entry Minimum Viable Lorebook

You don't need 50 entries to start. You need five strong ones:

  1. World Foundation — the core rule or law that defines the setting
  2. The Big Event — the war, disaster, or turning point that shaped everything
  3. Key Relationship — the most important person in the character's life
  4. The Wound — a past trauma or failure the character carries
  5. The Secret — something the character knows that most people don't

Five entries. Attach them. Test them. The character will feel ten times more grounded than any amount of system prompt padding.


Why This Works

Most AI characters are built wide — everything upfront, hope the model holds it.

Lorebooks let you build deep.

You layer detail precisely where it belongs.
You trigger it exactly when it's needed.
You stop burning context on lore that's irrelevant to the current conversation.

The best fantasy AI characters aren't the ones with the most information.

They're the ones where the right information appears at the right moment.

Build the layers. Set the keys. Let the context do the work.


Get started: studio.meganova.ai

Stay Connected

💻 Website: Meganova Studio

🎮 Discord: Join our Discord

👽 Reddit: r/MegaNovaAI

🐦 Twitter: @meganovaai