Lorebook System

Create dynamic, contextual world information that intelligently activates during conversations.

What is a Lorebook?

A lorebook is a dynamic knowledge system that injects relevant information into conversations based on keywords. Instead of putting everything in your character definition, lorebooks let you add context only when needed.

Example: If your character is a wizard, you might have lorebook entries for:
  • "magic" - Explains how magic works in your world
  • "Arcane Academy" - Details about the wizard school
  • "familiar" - Information about the character's magical pet

These entries only activate when those words appear in the conversation!

Why Use Lorebooks?

  • Context Efficiency: Don't waste tokens on information that isn't relevant yet
  • Deep World-Building: Add extensive lore without bloating your definition
  • Dynamic Responses: Characters respond with accurate details when topics come up
  • Better Long Conversations: Maintain consistency across extended chats

Creating Lorebook Entries

Basic Entry Structure

Keys: magic, spell, arcane
Content: Magic in this world requires both innate talent and years of study. Spells are cast through verbal incantations and hand gestures. The Arcane Order regulates all magical practice.

Key Components

  • Keys: Words/phrases that trigger the entry (comma-separated)
  • Content: Information to inject when triggered
  • Priority: Higher priority entries are included first (0-1000)
  • Enabled: Toggle entries on/off without deleting

Advanced Features

Secondary Keys & Selective Matching

Require multiple keywords to trigger an entry:

Primary Keys: dragon
Secondary Keys: mountain
Selective: Enabled
Result: Only triggers when both "dragon" AND "mountain" appear

Regex Matching

Use regex patterns for flexible matching:

Key: (sword|blade|weapon)s?
Use Regex: Enabled
Result: Matches "sword", "swords", "blade", "blades", "weapon", "weapons"

Constant Entries

Always active entries (no keyword required):

  • Good for core world rules that should always be present
  • Use sparingly to avoid token waste

Priority & Insertion Order

  • Priority (0-1000): Higher priority entries included first
  • Insertion Order: Determines order within same priority
  • Token Budget: System stops when budget is reached

Best Practices

✅ Do:

  • Use specific, unique keywords for each entry
  • Keep entries focused on one topic
  • Set higher priority for crucial information
  • Test your keywords in actual conversations
  • Use case-insensitive matching (default)

❌ Don't:

  • Put everything in one giant entry
  • Use overly common words as keys (e.g., "the", "and")
  • Create duplicate keys across entries
  • Exceed your token budget with too many entries

Example Lorebook Setup

Fantasy Wizard Character

Entry 1 - Magic System (Priority: 100)
Keys: magic, spell, arcane, enchantment
Content: Magic requires innate talent and rigorous training...
Entry 2 - Arcane Academy (Priority: 80)
Keys: academy, school, university
Content: The Arcane Academy is a prestigious institution...
Entry 3 - Character's Familiar (Priority: 90)
Keys: familiar, Whiskers, cat
Content: Whiskers is a magical black cat who serves as...

How It Works (Technical)

  1. System scans recent messages (configurable scan depth)
  2. Checks each message against all lorebook entry keys
  3. Activates matching entries
  4. Sorts by priority and insertion order
  5. Injects entries into context (respecting token budget)
  6. Generates response with enhanced context
💡 Pro Tip: Start with 3-5 high-quality entries focused on the most important aspects of your character's world. You can always add more later!