Skip to content
AgenticAIWiki
  1. Learn
  2. Part 4
  3. 24. Agentic RAG
  4. 24.2

Lesson 24.2 · 2 of 3 · 4 min read · Reviewed 24 Nov 2026

Multi-hop questions

By the end, you can

  • Answer multi-hop questions with iterative retrieval.
  • Recognise when a question needs several hops.

What multi-hop looks like

Q: "Who manages the team that owns the billing service?"

hop 1: search "billing service owner"     -> "Billing is owned by Team Atlas" [svc-12]
hop 2: search "Team Atlas manager"        -> "Team Atlas is led by R. Mensah" [org-3]
answer: "R. Mensah leads Team Atlas, which owns billing [svc-12][org-3]."

A single retrieval on the original question might find neither passage, because no document mentions both billing and the manager.

The loop

This is the ReActReAct: An agent pattern that interleaves reasoning steps and actions (tool calls), using each observation to plan the next step. pattern (chapter 46): reason about what’s missing, act (search), observe, repeat.

Keeping it on track

  • Notes: keep a running list of facts found and their sources.
  • Stop rule: stop when the question is answered, or after N searches with a clear “couldn’t find” message.
  • Decomposition up front: for obviously compound questions, plan the sub-questions first (chapter 47).

Evaluation

Multi-hop accuracy needs test cases with known chains. Check each hop’s retrieval as well as the final answer (chapter 26).

Key points

  • Multi-hop questions need facts from several documents, where one fact tells you what to look up next.
  • An agent can search, read, then search again using what it learned.
  • Notes between hops keep the chain of facts clear and citable.
Hands-on labRuns in the Playground

Answer a two-hop question with notes

Answer a question that needs two lookups, where the first answer tells you what to search next, and cite both.

You will have: A hop loop with a stop rule, a notes list with source ids and a cited final answer.

Steps

  1. Read the documents: one says which service sends invoice emails, another lists each service's on-call rota.
  2. Search for the first fact and record it in notes with its id.
  3. Build the next query from what you found, search again and record the second fact.
  4. Stop when both facts are known or after 4 hops, and answer citing both ids.

Done when

  • A single search on the full question returns only one of the two passages the answer needs.
  • The loop finishes in 2 hops.
  • The answer cites [svc-7] and [rota-2].

Open in the Playground No API key needed.

Starter code (Python)
import re

DOCS = {
    "svc-7": "Invoice emails are sent by the Mailer service.",
    "svc-8": "The Ledger service stores invoices.",
    "rota-2": "Mailer is covered by the Platform on-call rota.",
    "rota-3": "Ledger is covered by the Finance on-call rota.",
}
QUESTION = "Which on-call rota covers the service that sends invoice emails?"

def search(query):
    qw = set(re.findall(r"[a-z]+", query.lower())) - {"the", "that", "which", "is", "by", "covers", "service"}
    scored = sorted(DOCS, key=lambda d: (-len(qw & set(re.findall(r"[a-z]+", DOCS[d].lower()))), d))
    return scored[0]

notes = []
# TODO: hop 1: search for who sends invoice emails; record (id, text)
# TODO: hop 2: pull the service name from the note (the word before "service") and search "<name> on-call rota"
# TODO: stop after both facts or 4 hops; print an answer citing both ids
print("single search on the question:", search(QUESTION))
print("notes:", notes)
Show a solution
import re

DOCS = {
    "svc-7": "Invoice emails are sent by the Mailer service.",
    "svc-8": "The Ledger service stores invoices.",
    "rota-2": "Mailer is covered by the Platform on-call rota.",
    "rota-3": "Ledger is covered by the Finance on-call rota.",
}
QUESTION = "Which on-call rota covers the service that sends invoice emails?"

def search(query):
    qw = set(re.findall(r"[a-z]+", query.lower())) - {"the", "that", "which", "is", "by", "covers", "service"}
    scored = sorted(DOCS, key=lambda d: (-len(qw & set(re.findall(r"[a-z]+", DOCS[d].lower()))), d))
    return scored[0]

single = search(QUESTION)
print("single search on the question:", single, "(one passage; the answer needs two)")

notes, query, service, rota = [], "who sends invoice emails", None, None
for hop in range(1, 5):
    doc = search(query)
    notes.append((doc, DOCS[doc]))
    if service is None:
        m = re.search(r"(\w+) service", DOCS[doc])
        service = m.group(1) if m else None
        query = f"{service} on-call rota"
    else:
        m = re.search(r"by the (\w+) on-call rota", DOCS[doc])
        rota = m.group(1) if m else None
    if service and rota:
        break
print("hops:", hop)
for n in notes:
    print("note:", n)
print(f"answer: The {rota} rota covers {service}, which sends invoice emails [{notes[0][0]}][{notes[1][0]}].")
Quick checkWhich question needs multi-hop retrieval?
How sure are you?
Pick an answer and how sure you are