The RAG Pipeline in Detail
Last updated: March 24, 2026
What RAG actually means
RAG -- Retrieval-Augmented Generation -- is the pattern that makes modern AI assistants factually grounded. Instead of asking the language model to recall rules from training data (it was never trained on your game rulebook), I retrieve the relevant text at query time and hand it to the model as context.
The critical benefit: the model can only cite what I give it. It cannot hallucinate rules that are not in the chunks.
Loading diagram...
Each node in this diagram is a real function call. There is no magic -- just a well-engineered sequence.
Query expansion
Before embedding the question, I run it through the corpus-analyzer service. This uses BERTopic topic models built on the actual content of BGG forums to expand the query with related terms. A question like "can I take back a move" gets expanded with related phrases from the game domain vocabulary, improving recall.
Context assembly
After retrieval, I rank the chunks by semantic similarity score and assemble them into a context window. I cap at roughly 3,000 tokens -- enough to include 5-8 substantial rulebook passages. If the question explicitly spans multiple rules sections, I use the multi-question synthesis template which handles longer context differently.
Tier 1 vs Tier 2 comparison
| Dimension | Tier 1 | Tier 2 |
|---|---|---|
| Source material | Official rulebook only | Rulebook + BGG community threads |
| Context size | ~3,000 tokens | ~6,000-10,000 tokens |
| Synthesis model | GPT-4o | GPT-4o (deeper reasoning prompt) |
| Latency | 5-7s | 7-35s |
| Use case | Clear rules questions | Edge cases, interpretation, exceptions |
| Citation types | [PDF] | [PDF] + [T] community threads |
The corpus analyzer
The corpus-analyzer service (port 3481) runs BERTopic and CADA to:
- Classify the question into one of 6 categories (YES_NO, RULE_EXPLANATION, PROCEDURAL, OVERVIEW, EDGE_CASE, MULTI_QUESTION)
- Expand the query with domain-specific synonyms
- Detect ambiguous terms that need disambiguation
The category drives which synthesis YAML template I use -- edge-case questions get a different prompt than yes/no questions.