Entry Archetypes: Preferential Matching for Lorebook Entries
Status: Shipped — archetypes + per-entry custom weights. Reserved-atmosphere slots still planned.
Why This Feature Exists
Right now, every lorebook entry competes for the same 10-slot budget (MaxEntries) using the same scoring formula. This creates a fundamental tension: the system treats a character profile, a magic system's feel, and a historical event identically, even though they serve completely different purposes and get referenced in completely different ways during conversation.
The result is predictable:
- Entity entries dominate the budget. A character with strong keyword matches scores 2.5+ (keyword + FTS + vector). An atmospheric entry about how magic feels in this world scores 0.85 at best (vector only). The atmosphere entry loses every time.
- Users force keywords onto everything. To make atmospheric entries competitive, users add keywords like "magic" — which then fires on every mention of any spell, artifact, or enchantment. The entry triggers constantly and loses all precision.
- Users mark things as always-include. To guarantee injection, atmospheric or location entries get marked always-include, burning tokens every single message even when irrelevant.
- The budget gets spent on things the system already knows. You're in a tavern with Elara and Simon. The system wastes 3 of its 10 slots re-discovering "tavern", "Elara", and "Simon" through search — information that's already established context, not something that needs to be found.
Entry archetypes solve this by recognizing that different kinds of information need different matching strategies — and by working together with trackers and mode-specific injection to put each entry in the right layer of the injection system.
The Big Picture: Three Injection Layers
Before diving into archetypes themselves, it helps to understand the full injection system they're part of. Lorebook entries reach the LLM's prompt through three distinct layers, each solving a different problem:
Layer 1: Tracker-Linked Lorebooks (Deterministic)
What decides injection: Tracker state — the system knows what to inject because a tracker is tracking it.
How it works: A location tracker holds "The Rusty Tankard". A roster tracker holds ["Elara", "Simon"]. These values are searched against their linked lorebooks, and matching entries are injected automatically. No conversation search needed — the tracker already knows what's relevant.
What belongs here: Characters currently in the scene, the current location, equipped items, active quests — anything with a concrete, trackable state that should stay injected as long as that state holds.
Budget: Each tracker has its own entry budget (default: 3), separate from the main MaxEntries. This is the key insight: tracker-linked entries don't compete with search-matched entries.
See: Tracker-Aware Lorebook Search for full details.
Layer 2: Mode-Targeted Lorebooks (Structural)
What decides injection: The mode configuration — the mode creator decides which lorebook goes where in the prompt, with what framing.
How it works: A mode can include multiple lorebook sub-prompts, each targeting a specific lorebook with its own template, position, and entry budget. "World rules go here with this framing. NPC reference goes there with that framing."
What belongs here: Content that a mode creator wants to control precisely — investigation techniques in a detective mode, combat mechanics in an RPG mode, genre conventions in a genre-specific mode.
Budget: Per-sub-prompt, configured by the mode creator.
See: Mode-Specific Lorebook Injection for full details.
Layer 3: Generic Lorebook Search (Reactive)
What decides injection: Conversation content — the system searches based on what was recently said and finds relevant entries.
How it works: This is the current lorebook search system: vector, FTS, keyword, and regex matching against recent messages. Entries compete for the MaxEntries budget based on their combined score.
What belongs here: Everything that isn't handled by trackers or mode configuration. Background lore that surfaces when alluded to. Situational context that activates when the narrative enters certain territory. Atmospheric and tonal entries that enrich the writing when semantically relevant.
Budget: MaxEntries — but now this budget isn't being burned on things the other layers already handle.
Why This Matters for Archetypes
Here's the critical point: once trackers handle deterministic injection and modes handle structural injection, the generic search budget stops being wasted on things the system already knows.
Without trackers, your 10 MaxEntries slots are doing triple duty:
- ~3 slots: Character profiles (Elara, Simon, the innkeeper) because their names were mentioned
- ~2 slots: Location info (the tavern) because it was referenced recently
- ~1 slot: An item (Simon's sword) because it came up
- ~4 slots: Actual reactive content — maybe some lore, maybe a scene entry, probably not a vibe entry (it lost the scoring competition)
The LLM has the facts but not the creative direction. It knows who Elara is but not how the magic should feel. It knows the tavern's layout but not the social dynamics of this culture's drinking establishments.
With trackers carving out the deterministic layer, all 10 slots are available for reactive search — the things that should be found through matching: how magic feels in this world, the scene dynamics of a tavern gathering, the vibe of this kingdom's nightlife, the historical context someone just alluded to.
The LLM now has both the facts and the creative direction. The facts come from trackers. The creative direction comes from the search layer, which finally has room for it.
Archetypes optimize this reactive search layer. They tell the system how to match each entry in the generic search, so entries compete fairly based on what they actually are.
The Four Archetypes
Each entry gets an archetype that controls how it's discovered during generic lorebook search. The archetype shifts the weight of each search method, so different kinds of entries use the matching strategy that works best for them.
Lore (Default)
What it is: Background knowledge, history, rules, systems, cultural context, explanations — and the general-purpose default for any entry that doesn't clearly fit another archetype.
When it should fire: When someone references the topic by name OR alludes to it indirectly. "The War of Three Crowns reshaped everything" (keyword match) but also "back when the kingdoms were fighting over the throne" (FTS/vector territory).
Why it's the default: Lore uses balanced scoring across all search methods — keywords, FTS, and vector all contribute equally. This is the most forgiving configuration: it works whether an entry has strong keywords, good embeddings, rich content for FTS, or any combination. It's how the search system has always worked, so existing entries behave identically without any changes.
Primary match path: Keywords + FTS + Vector (balanced — all three contribute equally)
Scoring weights:
| Method | Weight |
|---|---|
| Keyword | 1.0 |
| FTS | 1.0 |
| Vector | 1.0 |
| Regex | 1.0 (always) |
Examples:
- Historical events ("The War of Three Crowns — a decade-long succession conflict")
- World rules ("How divine magic differs from arcane magic in this setting")
- Cultural practices ("Funeral rites of the Northern Clans")
- Timelines and background ("History of the Valdorian Empire — founding to fall")
- Anything you're not sure how to categorize
When to use: If you're not sure which archetype fits, leave it as Lore. It's the safe default — all search methods work at full weight, so the entry will be discoverable through whatever path fits best. You can always change the archetype later if a more specific one would work better.
Entity
What it is: A specific, nameable thing — a character, location, item, organization, creature. Something with a proper noun that people will say in conversation.
When it should fire: When someone says the name or a known alias. "Elara drew her blade." "They approached Shadowkeep." "The Moonblade hummed."
Why keywords work here: Entities have names. People refer to them by name. Keyword matching is precise, reliable, and deterministic for this — you know exactly when the entry should fire.
Primary match path: Keywords (prioritized) → FTS → Vector (as fallback)
Scoring weights:
| Method | Weight |
|---|---|
| Keyword | 1.3 |
| FTS | 1.0 |
| Vector | 0.7 |
| Regex | 1.0 (always) |
The keyword boost and vector reduction mean Entity entries win decisively when their name is mentioned, but don't crowd out other entries through vague semantic similarity.
Examples:
- Character profiles ("Elara Nightwhisper — exiled princess of Valdoria")
- Location descriptions ("The Shadowkeep — an ancient fortress on the northern border")
- Items ("The Moonblade — a sentient weapon forged during the First Age")
- Organizations ("The Order of Shadows — a secretive guild of assassins")
- Creatures ("Thornback Drake — a territorial predator native to the Ashlands")
When to use: If your entry has a proper noun or specific name that people will actually say in conversation, it's an Entity. Give it strong, distinctive keywords — the names and aliases people use to refer to it.
Relationship to trackers: Entity entries are often the best candidates for tracker-linked lorebooks. If you have a roster tracker pulling character entries or a location tracker pulling location entries, those Entity entries are being injected deterministically — they don't need to compete in the generic search at all. Entity entries in the generic search layer are for things that aren't being tracked: minor NPCs mentioned in passing, places referenced but not currently visited, items not in inventory.
Scene
What it is: Situational context — how things work when a particular type of situation arises. Not a specific entity, not a mood, but a kind of moment that has rules, dynamics, or conventions attached.
When it should fire: When the narrative enters a recognizable situation type. Combat starts. Characters are negotiating. A ritual is underway. Someone is dying. Characters are in a tavern. The conversation doesn't name the entry — it enters the territory the entry describes.
Why FTS + vector work here: Situations are described by clusters of related words. Combat involves "sword", "struck", "dodged", "blood", "fight" — FTS stemming catches morphological variants ("fighting" → "fight"), and vector search catches the conceptual cluster even with different vocabulary ("she lunged with the blade" has no combat keywords but is clearly a combat scene). Keywords are too narrow for this — you'd need dozens and still miss cases.
Primary match path: FTS + Vector (boosted) — keywords optional, only if there's a strong anchor term
Scoring weights:
| Method | Weight |
|---|---|
| Keyword | 0.5 |
| FTS | 1.2 |
| Vector | 1.3 |
| Regex | 1.0 (always) |
Examples:
- "Combat in this world — lethal, fast, no HP bars, consequences are permanent"
- "Tavern social dynamics — how strangers are received, what's rude, what starts fights"
- "Interrogation scenes — the power dynamics and cultural attitudes toward coercion"
- "Deathbed scenes — how people in this world face death, afterlife beliefs, last rites"
- "Romance beats between Elara and Kael — the tension points, unspoken rules, what they avoid"
- "Negotiation with the Merchant Guild — they always haggle, insults are expected, walking away is a power move"
When to use: If your entry describes how a type of situation should play out rather than a specific thing or place, it's a Scene. Write rich, descriptive content — the more semantic signal you give the embedding model, the better it will match to the right moments. You can add a few keywords if there's a strong anchor term (like "combat" or "tavern"), but don't force it.
Vibe
What it is: Pure tone, atmosphere, mood, creative direction. The feel of something rather than the facts. These entries don't tell the LLM what exists in the world — they tell it how to write when the narrative enters certain emotional or thematic territory.
When it should fire: When the narrative drifts into the entry's semantic territory. Nobody says "activate the creepy atmosphere." The conversation's meaning shifts — tension is building, something feels wrong, the setting is eerie, characters are being tender — and the vector search catches that the current conversation is semantically close to the entry's content.
Why vector search is the only reliable path: Vibes don't have keywords. There's no word you can put on "the magic system feels visceral and wrong" that won't either be too generic ("magic" fires on everything) or too specific (misses the moments when the entry should actually activate). The entry's semantic territory is its trigger, and only embedding similarity can match that.
Primary match path: Vector (boosted) — no keywords expected, no FTS reliance
Scoring weights:
| Method | Weight |
|---|---|
| Keyword | 0.0 |
| FTS | 0.5 |
| Vector | 1.5 |
| Regex | 1.0 (always) |
Examples:
- "The magic system feels wrong — visceral, body-horror-adjacent, the cost is physical and visible, nobody uses magic casually"
- "Nighttime in the Thornwood — oppressive silence, things watching from the dark, sound doesn't carry right"
- "The emotional texture of Elara and Kael's relationship — guilt, unspoken attraction, performative distance"
- "This faction's philosophy — pragmatic cruelty dressed as mercy, everything is justified by the greater good"
- "How the city feels at dawn — fragile, almost sacred, the only honest hour before the grime returns"
- "The tone when the Shadow King is near — reality thins, temperature drops, sentences in the narrative should get shorter"
When to use: If your entry is about how something feels rather than what something is, it's a Vibe. Don't add keywords — trying to keyword Vibe entries leads to either overly generic triggers that fire constantly or no good keywords at all. Instead, invest in the content: the richer and more evocative the writing, the stronger the semantic signal, and the more precisely vector search will match it to the right moments.
Why this archetype exists — the magic system example: "Magic" as a keyword is a perfect illustration of the problem. A magic system entry with "magic" as a keyword fires every time anyone mentions a spell, an artifact, an enchantment, a magical creature — anything. The entry is about the feel of magic (visceral, costly, wrong), but the keyword triggers it for every fact about magic (Elara cast a spell, the door was enchanted, the potion glowed). As a Vibe entry with no keywords, it only activates when the narrative actually moves into the territory of magic being used — when the semantic context matches the visceral, costly, wrongness described in the content. That's when the LLM needs the tonal direction. Not when someone mentions an enchanted door in passing.
How Archetypes Interact with the Injection Layers
This is where the full system comes together. Each archetype has a natural home in the injection stack, and understanding this helps you organize your lorebooks effectively.
Layer 1 (Trackers): Mostly Entity entries
Tracker-linked lorebooks are searched using the tracker's current value as the query. A roster tracker holding ["Elara", "Simon"] searches the NPC lorebook with those names. A location tracker holding "The Rusty Tankard" searches the location lorebook with that string.
This is keyword-driven search by nature — the tracker value is a name, and the lorebook entry has that name as a keyword. Entity entries are the natural fit here: specific, nameable things with strong keyword anchors.
Putting a Vibe entry in a tracker-linked lorebook would be a mistake — the tracker searches by value (a name or term), and Vibe entries have no keywords. The entry would never be found.
What this means for your workflow: When you set up a roster tracker linked to an NPC lorebook, the entries in that lorebook should be Entity-archetype character profiles. When you set up a location tracker linked to a world geography lorebook, those entries should be Entity-archetype location descriptions. The tracker handles the "when" (while the character is present, while you're at this location), and the Entity archetype handles the "how" (keyword matching against the tracker value).
Layer 2 (Mode-targeted): Any archetype, creator's choice
Mode-specific lorebook injection is controlled by the mode creator. They decide which lorebook goes where, with what framing and budget. Archetypes still affect how entries are found within the targeted lorebook (the search still runs), but the mode creator has explicit control over positioning and framing.
A mode creator might target a "Combat Rules" lorebook full of Scene entries, or a "Genre Conventions" lorebook full of Vibe entries. The archetype ensures the right search method is used even within the targeted scope.
Layer 3 (Generic search): Where archetypes matter most
This is the reactive search layer — the one that finds entries based on what's happening in the conversation. This is where archetypes have their biggest impact.
Once trackers have handled the deterministic stuff (who's here, where we are, what time it is) and mode configuration has handled the structural stuff (genre rules, investigation techniques), the generic search budget is fully available for reactive discovery:
- Lore entries surface when someone alludes to history, rules, or background knowledge
- Scene entries surface when the narrative enters a recognizable situation type
- Vibe entries surface when the conversation's tone or mood shifts into new territory
Without archetypes, Vibe entries scoring 0.85 on vector alone would lose to Entity entries scoring 2.5+ on keyword+FTS+vector. The Vibe entry's atmospheric guidance never reaches the LLM. With archetypes, the boosted vector weight (1.5) gives Vibe entries a fighting chance, and the budget reservation system (see below) guarantees atmospheric enrichment even when many Lore entries are competing.
The Budget Liberation Effect
This is the most important practical outcome of the three-layer system:
Before trackers + archetypes: Your 10 MaxEntries slots are doing everything:
- ~3 slots: Character profiles (Elara, Simon, the innkeeper) because their names were mentioned
- ~2 slots: Location info (the tavern) because it was referenced recently
- ~1 slot: An item (Simon's sword) because it came up
- ~4 slots: Actual reactive content — maybe some lore, maybe a scene entry, probably not a vibe entry (it lost the scoring competition)
The LLM has the facts but not the creative direction. It knows who Elara is but not how the magic should feel. It knows the tavern's layout but not the social dynamics of this culture's drinking establishments.
After trackers + archetypes:
- Tracker layer (separate budget): Elara, Simon, the tavern — injected deterministically, always current, drops out when they leave
- Generic search (full 10-slot budget): Freed up for lore someone alluded to, the scene dynamics of a tavern gathering, the vibe of this kingdom's nightlife, the tension between these two characters
The LLM now has both the facts and the creative direction. The facts come from trackers. The creative direction comes from the search layer, which finally has room for it.
Budget Reservation for Vibe and Scene Entries
Even with archetypes adjusting weights, there's a structural challenge: a Vibe entry with a boosted vector score of 1.5 × 0.85 = 1.275 still loses to a Lore entry scoring 2.0+ across keyword + FTS + vector. In a lorebook with many well-keyworded Lore entries, Vibe and Scene entries can still get crowded out.
Solution: Reserved slots.
A configurable number of the MaxEntries budget is reserved specifically for the highest-scoring Vibe or Scene entries that didn't make the main ranking:
| Setting | Default | Description |
|---|---|---|
| ReservedAtmosphereSlots | 0 | Number of MaxEntries slots reserved for the top-scoring Scene and Vibe entries. Set to 0 for backward compatibility. Recommended: 1–2. |
How it works:
- All entries are scored and ranked normally (with archetype weights applied)
- The top entries fill the main budget (MaxEntries - ReservedAtmosphereSlots)
- The reserved slots are filled by the highest-scoring Scene or Vibe entries that didn't already make the main cut
- If no Scene/Vibe entries are candidates, the reserved slots are filled from the main ranking (no slots wasted)
This guarantees that atmospheric and situational context has a path into the prompt even when many Lore and Entity entries are competing. The reserved slots are a floor, not a ceiling — Scene and Vibe entries can still win main-budget slots through high scores.
Lorebook Assistant Integration
The archetype system changes how the Lorebook Assistant analyzes and creates entries.
During Analysis
The analysis diagnostics become archetype-aware:
| Situation | Diagnostic |
|---|---|
| Entity without keywords | Warning — Entity entries need keywords to work. Without them, the entry can only be found through FTS and vector search, which defeats the purpose of the Entity archetype. |
| Lore without keywords | Mild suggestion — Keywords help Lore entries but aren't critical. FTS and vector search will handle indirect references. |
| Scene without keywords | Fine — Expected behavior. Scene entries are primarily found through FTS stemming and vector similarity. |
| Vibe with keywords | Suggestion to remove — Keywords on a Vibe entry are usually too generic to be useful. If the keyword is distinctive enough to be useful, the entry might actually be a Scene or Lore entry instead. |
| Vibe with generic keywords | Warning — e.g., "magic" on a magic-system-feel entry. This will fire on every mention of any spell, artifact, or enchantment, injecting atmospheric content when factual content was needed. |
| Entity in generic search that could be tracker-linked | Suggestion — "This character/location entry is competing in generic search. Consider using a roster/location tracker with a linked lorebook for deterministic injection." |
During Entry Creation
When the assistant helps create or import entries, it:
- Suggests an appropriate archetype based on the content. Character descriptions → Entity. "How X feels" content → Vibe. "What happens when Y" content → Scene.
- Adjusts keyword suggestions based on archetype. Strong distinctive keywords for Entity. Optional keywords for Lore. Discouraged for Vibe.
- Suggests content structure optimized for the archetype's primary match path. Vibe entries benefit from rich, evocative language that gives the embedding model strong semantic signal. Entity entries benefit from clear, factual descriptions with names and aliases prominent.
- Recommends lorebook placement when trackers are available. "This character entry would work well in a roster-linked lorebook rather than the generic search pool."
During Search Simulation
The simulate_search tool shows archetype-aware scoring: which weights were applied per entry, how the archetype affected the ranking, and whether an entry made it through the main budget or a reserved atmosphere slot.
Scoring Reference
Weight Table
| Archetype | Keyword | FTS | Vector | Regex | Effective Max |
|---|---|---|---|---|---|
| Lore (default) | 1.0 | 1.0 | 1.0 | 1.0 | 4.0 |
| Entity | 1.3 | 1.0 | 0.7 | 1.0 | 4.0 |
| Scene | 0.5 | 1.2 | 1.3 | 1.0 | 4.0 |
| Vibe | 0.0 | 0.5 | 1.5 | 1.0 | 3.0* |
*Vibe entries have a lower theoretical max because they don't use keywords. The ReservedAtmosphereSlots setting compensates for this structural disadvantage.
How Weighted Scoring Works
The existing scoring formula doesn't change — each method still produces a score from 0.0 to 1.0. The archetype applies a multiplier to each method's contribution before they're summed:
Combined Score = (keyword_score × keyword_weight)
+ (fts_score × fts_weight)
+ (vector_score × vector_weight)
+ (regex_score × regex_weight)
Example — the same entry content, different archetypes:
An entry about the Thornwood forest that scores: keyword=0.5, FTS=0.6, vector=0.8
| Archetype | Calculation | Combined Score |
|---|---|---|
| Lore | (0.5×1.0) + (0.6×1.0) + (0.8×1.0) | 1.90 |
| Entity | (0.5×1.3) + (0.6×1.0) + (0.8×0.7) | 1.81 |
| Scene | (0.5×0.5) + (0.6×1.2) + (0.8×1.3) | 2.01 |
| Vibe | (0.5×0.0) + (0.6×0.5) + (0.8×1.5) | 1.50 |
The same raw scores produce different combined scores depending on the archetype. A Scene entry ranks highest here because its strong vector and FTS scores are amplified, while its moderate keyword score is dampened.
Migration & Backward Compatibility
- Default archetype: Lore — balanced scoring across all methods, identical to the current system's behavior (1.0/1.0/1.0 weights). Existing entries behave exactly as they always have.
- Existing entries: All entries default to Lore. Zero behavioral change until a user explicitly sets a different archetype.
- New setting: ReservedAtmosphereSlots defaults to 0, preserving current budget behavior. Users opt in by setting it to 1–2.
- Lorebook Assistant: When analyzing existing lorebooks, the assistant can suggest archetype changes for entries that would benefit. "This character entry 'Elara Nightwhisper' has strong name-based keywords — consider marking it as Entity for keyword-prioritized matching." "This entry about 'How magic feels in this world' has no keywords and reads as atmospheric — consider marking it as Vibe."
Quick Decision Guide
Not sure which archetype to use? Ask yourself:
Does it have a name people will say? → Entity "Elara", "Shadowkeep", "The Moonblade", "Order of Shadows"
Does it explain something about the world that might be referenced by name or indirectly? → Lore "The War of Three Crowns", "Funeral rites of the Northern Clans", "How divine magic works"
Does it describe how a type of situation should play out? → Scene "How combat works here", "Tavern social dynamics", "Interrogation conventions"
Does it describe how something should feel or what tone to use? → Vibe "The wrongness of magic", "How the city feels at dawn", "The emotional texture of this relationship"
Still not sure? Leave it as Lore. All search methods work at full weight, and you can always change the archetype later as you see how the entry performs.
Is it a character, location, or item that should always be present while relevant? Consider whether it belongs in a tracker-linked lorebook (deterministic injection) rather than the generic search layer at all. Archetypes optimize search — but the best optimization for always-relevant content is to skip search entirely.