RAGEngineering Hub
Chapter 12 · concept 4 of 4 · show all
  1. 1What RAG is, and why
    1. 1.1Why models need outside knowledge, and what hallucination means
    2. 1.2What RAG is: anatomy of a request
    3. 1.3RAG vs fine tuning vs long context and prompt caching
    4. 1.4Use cases and the quality, latency and cost triangle
    5. Chapter overview
  2. 2Tokens, cost and your first RAG
    1. 2.1Tokens and context windows for RAG
    2. 2.2The RAG lifecycle and your first RAG in miniature
    3. Chapter overview
  3. 3Getting documents in
    1. 3.1Content sources and file formats
    2. 3.2Parsing, layout and OCR
    3. 3.3Tables, images and mixed content
    4. 3.4Cleaning, normalization and quality gates
    5. 3.5Metadata, document identity and versioning
    6. 3.6Updates, deletes, reindexing and ingestion pipelines
    7. Chapter overview
  4. 4Chunking
    1. 4.1Why we chunk, and the main chunking strategies
    2. 4.2Structure aware chunking and tables
    3. 4.3Chunk size, overlap and token based sizing
    4. 4.4Contextual chunking and late chunking
    5. 4.5Parent child and multi representation indexing
    6. 4.6Chunk metadata, provenance and the chunking debugging playbook
    7. Chapter overview
  5. 5Embeddings
    1. 5.1Embeddings and similarity from first principles
    2. 5.2What embeddings cannot do
    3. 5.3Choosing an embedding model: size, cost, language
    4. 5.4Embedding model migration and index rebuilds
    5. Chapter overview
  6. 6Vector stores and scores
    1. 6.1Vector databases, ANN indexes and choosing a store
    2. 6.2Score calibration and thresholds
    3. 6.3Late interaction and multivector retrieval
    4. Chapter overview
  7. 7Finding the right chunks
    1. 7.1Query understanding, rewriting and expansion
    2. 7.2Dense retrieval and keyword search with BM25
    3. 7.3Hybrid retrieval and rank fusion
    4. 7.4topK, no good match, and metadata filtering
    5. 7.5Routing, diversity, deduplication and caching
    6. 7.6Reranking: two stage, cross encoder and LLM rerankers
    7. Chapter overview
  8. 8When retrieval fails
    1. 8.1Retrieval failure analysis playbook
    2. Chapter overview
  9. 9Building the answer
    1. 9.1Context selection, packing and citations
    2. 9.2Grounding prompts and abstention
    3. 9.3Lost in the middle and context management
    4. 9.4Conflicts, staleness and freshness rules
    5. 9.5Hallucination checks and answer verification
    6. 9.6Conversational RAG, answer UX and RAG APIs
    7. Chapter overview
  10. 10Measuring
    1. 10.1Why measure, and what to measure
    2. 10.2Building a golden dataset
    3. 10.3Retrieval metrics: precision, recall, MRR, nDCG
    4. 10.4Faithfulness and answer correctness
    5. 10.5LLM as judge, and judging the judge
    6. 10.6Offline and online evals, regression tests and slices
    7. Chapter overview
  11. 11Safety and operations
    1. 11.1Prompt injection and poisoned documents
    2. 11.2Access control, privacy and governance
    3. 11.3Index lifecycle operations
    4. 11.4Observability and tracing
    5. 11.5Latency, cost, caching and model routing
    6. 11.6Reliability, degraded modes and launch readiness
    7. Chapter overview
  12. 12Scale and advanced RAG
    1. 12.1Scaling, multi tenancy and enterprise architecture
    2. 12.2Choosing an architecture: naive, advanced, agentic, graph
    3. 12.3Agentic RAG and RAG as an MCP tool
    4. 12.4GraphRAG, structured data and multimodal RAG
    5. Chapter overview

GraphRAG, structured data and multimodal RAG

Not all knowledge is plain text. Relationships across documents, exact data in tables and databases, and images each need their own structure. When to use a graph, when to query data directly, and when chunks are enough.

A real question

Some answers live in links between documents, in database tables or in images. Do chunks still work?

Sometimes yes, sometimes no. Small tables kept whole work as chunks. Exact current data is better queried directly. Questions about relationships across many documents may need a graph. Pick the structure the question needs.

The problem

Why this matters

The belief

Every serious RAG system needs a knowledge graph.

What really happens

All 8 of our table questions found their answer in the top 3 with plain 512 token chunks. Graphs help with questions about relationships and themes across many documents, and cost an extraction step over the whole corpus.

Why not the simpler way

Text chunks are a good default, and this course showed how far they go. Some questions break them: "summarise all incidents this year", "which suppliers are linked to this contract", "what is the balance right now", "what does this diagram show". Each needs a different kind of retrieval.

The idea

The idea in plain words

GraphRAG (Edge et al., "From Local to Global: A Graph RAG Approach to Query-Focused Summarization", arXiv 2404.16130) uses a model to extract entities and relations from the corpus, builds a graph, groups it into communities and summarises them, so questions about the whole corpus can be answered. Structured RAG retrieves from databases and APIs. Multimodal RAG retrieves images, scans and diagrams alongside text.

A detective's board with photos and string: useful for connecting people and events, unnecessary for looking up one phone number.

How it works

Step by step

  1. 1

    Entities and dates as metadata

    Incident ids, product codes and dates on each chunk let you filter and order, a light form of structure (RAG-18).

  2. 2

    Query exact data

    Prices, balances and stock levels live in databases. Let the model call a query tool (text-to-SQL or a fixed API) instead of embedding them.

  3. 3

    Images and scans

    Caption images or extract their text at ingestion, or use a model that embeds images; keep the link to the original.

In detail

Graph options. Light: entity and date metadata on chunks, filtered and grouped at query time. Full: model-extracted entities and relations, community summaries, graph traversal. Full graphs cost a model pass over the corpus and need rebuilding as it changes.

Structured data. A query tool with a fixed schema, called by the model (RAG-53). Prefer parameterised queries over free text-to-SQL; validate and restrict to read-only.

Multimodal. At ingestion: OCR for scans (RAG-08), captions or descriptions for images, or a joint image-text embedding model. Store the image link so the answer can show it.

The code

Try it in Python

import sqlite3
from datetime import date

PRICE_TOOL = {
    "name": "plan_price",
    "description": "Monthly price of a plan code on a date. Use for exact prices.",
    "input_schema": {"type": "object",
                     "properties": {"plan": {"type": "string"}, "on": {"type": "string", "format": "date"}},
                     "required": ["plan"]},
}

def plan_price(db: sqlite3.Connection, plan: str, on: str | None = None):
    on = on or date.today().isoformat()
    row = db.execute(
        "SELECT price_eur, source_doc FROM prices WHERE plan = ? AND valid_from <= ? "
        "AND (valid_to IS NULL OR valid_to > ?) ORDER BY valid_from DESC LIMIT 1",
        (plan, on, on)).fetchone()                       # parameterised, read-only
    return {"plan": plan, "on": on, "price_eur": row[0], "source": row[1]} if row else None

See it

What we measured

Measured · question types on our corpus

Polder corpus, 34 recursive 512 token chunks, 47 golden questions, vector search (bge-small).

Table questions in the top 38 of 8
Multi-document questions in the golden set1
Price similarity, EUR 20.00 against 21.000.942
Images in the corpus0
GraphRAG on this corpusnot measured

Measured 2026-11-04 with corpus/scripts/measure-parts-4-7.mts. Our corpus is text with tables and has no images, so multimodal retrieval is described, not measured.

Try it on a real example

Three kinds of question, and the structure each needs

Question

“What was the cost to income ratio in 2024?”

The bank's key figures table, kept whole in one 512 token chunk.

Plain chunks work: table questions were 8 of 8 in the top 3. Keep tables whole (RAG-09, RAG-14).

Choosing

Use it when, avoid it when

Use it when
  • Plain chunks with whole tables as the default
  • Query tools for exact, live data
  • A graph for relationship and corpus-wide questions the golden set shows failing
Avoid it when
  • Embedding live numbers that change daily
  • Building a full knowledge graph before measuring the need

What it costs · Metadata: cheap. Query tools: a schema and a tool. Full GraphRAG: a model pass over the corpus and regular rebuilds.

In production

Add question types to the golden set before adding structure: relationship questions, corpus-wide summaries, live data, images. Measure plain chunks on them first. If you build a graph, budget its extraction cost and refresh cycle, and test that answers cite documents, not only graph nodes.

Watch out

Common mistakes

  • Tables need special RAG. Kept whole, ours worked as plain text.
  • Graphs replace chunks. Most graph systems still retrieve text chunks to answer.
  • Multimodal means sending every image to the model. Index captions and text; fetch images when needed.

Check yourself

Remember this

Remember these

  • Small tables kept whole work as chunks: 8 of 8 here.
  • Query exact, current data instead of embedding it.
  • Graphs help with relationship and corpus-wide questions.
  • Images need captions, extracted text or an image embedding model.

Say it in an interview

  1. 01I match the retrieval structure to the question: chunks, a database query or a graph.
  2. 02On my corpus all 8 table questions worked with plain 512 token chunks kept whole.
  3. 03Exact live values like prices come from a query tool, not from embeddings.
  4. 04I would add a graph for relationship and corpus-wide questions, after measuring that chunks fail.
  5. 05For images I index captions or extracted text and keep a link to the original.

Quick quiz

Three questions

Question 1

Q1

Our 8 table questions with 512 token chunks found how many answers in the top 3?

Question 2

Q2

"What does PT-MOB-25GB cost today?" is best answered from where, if the data exists in a database?

Question 3

Q3 · from RAG-09

Why can a table split across chunks give wrong numbers?

Saved on this device. No account needed.