June 18, 2026•4 min read•...

RAG Architectures: Grounding Rulebooks for AI Game Arbiters

AIRAGFAISSNext.js

The Rulebook Hallucination Problem

Generative AI agents are exceptionally good at creative writing but struggle with rule precision. In tabletop roleplaying systems like Dungeons & Dragons 5th Edition, rules are dense, tabular, and highly contextual. An LLM querying its internal weights will frequently hallucinate spell ranges, damage dice, or skill check modifiers.

To solve this for D&D Knowledge, we designed a localized Retrieval-Augmented Generation (RAG) pipeline. This system retrieves official rule passages from local vector indexes and injects them into the LLM context, forcing the model to answer based strictly on official text.


Advanced Document Chunking Strategies

The first step in RAG is converting dense PDFs into searchable text chunks. Standard character-count splitters break tables and stat blocks in half, rendering them useless. We implemented a structural document parser:

  • Header-Based Chunking: Text is split at Markdown headers (#, ##, ###) to preserve the layout of specific rules (e.g., Grappling or Spellcasting).
  • Stat-Block Grouping: Character and monster statistics are isolated and parsed as JSON structures inside the text, allowing the retriever to capture the entire block as a cohesive unit.
  • Overlap Buffering: Chunks share a 15% sliding window overlap to maintain context across boundary limits.

Vector Databases and Similarity Searches via FAISS

Once chunked, the text is vectorized using Hugging Face's sentence-transformers and indexed using FAISS (Facebook AI Similarity Search). FAISS allows for high-speed, localized L2 distance search across thousands of high-dimensional embeddings.

# Local semantic rule retrieval
import faiss
import numpy as np

def retrieve_rules(query_vector: np.ndarray, index: faiss.IndexFlatL2, chunks: list[str], k=3):
    # Search the local vector index
    distances, indices = index.search(query_vector, k)
    retrieved_chunks = [chunks[idx] for idx in indices[0] if idx != -1]
    return retrieved_chunks

At runtime, when a user asks "How does cover affect Armor Class?", the query is vectorized, the closest three chunks from the D&D rulebook index are retrieved, and they are passed as context to our Gemini model.


System Prompts and Enforcing the Game Master Persona

The retrieved context is combined with a system prompt that mandates strict adherence to the retrieved rules:

You are a Game Master referee. Answer the user's question using ONLY the provided rules context. If the answer is not in the context, state that the official rules do not cover this case. Maintain an encouraging, immersive tone.

This combination of structured chunking, local FAISS indexing, and context-bound prompts eliminates rule hallucinations, providing players and Game Masters with reliable, lightning-fast rules arbitration.

Thanks for reading! Support our development efforts.
Support AIYoda on Ko-fi