---
title: "Query Fan-Out Explained: How AI Search Splits Queries (+ Code)"
description: "What query fan-out is, how Google AI Mode and research agents use it, what 163 logged ChatGPT-style answers show (one query each), and a Python fan-out with parallel search and reciprocal rank fusion."
category: "guides"
url: https://keirolabs.cloud/blog/query-fan-out
published: 2026-11-24
updated: 2026-11-24
---

# Query fan-out: how AI search splits one question into many searches

## The 60-second version

**Query fan-out is when a search system turns one question into several searches, runs them in parallel, and merges the results before answering.** "Best laptop for video editing under $1,500" becomes searches for GPU benchmarks, current prices, reviews from this year and battery life. One query fans out into many.

| | Single query | Query fan-out |
|---|---|---|
| Searches per question | 1 | Usually 3 to 10; deep research modes run far more |
| Good at | Simple lookups | Comparisons, multi-part questions, research |
| Main risk | Misses whatever the one query didn't match | Cost, latency, duplicate results |
| Who does it | Most chat models calling a search tool | Google AI Mode, deep research agents, well-built RAG systems |

**Google has described AI Mode as using a query fan-out technique.** You can build the same thing into your own agent in about 40 lines: generate sub-queries, search them in parallel, deduplicate, and merge with reciprocal rank fusion.

## How does query fan-out work?

**Four steps:**

1. **Decompose.** A model rewrites the question into sub-queries, each aimed at one piece of the answer.
2. **Search in parallel.** Every sub-query runs at the same time, so five searches take about as long as one.
3. **Merge.** Results are deduplicated by URL and combined into one ranked list. Pages that show up for several sub-queries rise to the top.
4. **Answer.** The model reads the best pages from the merged list and writes a cited answer.

**What kinds of sub-queries does a fan-out generate?**

| Type | Question | Sub-queries |
|---|---|---|
| Entity split | "Postgres vs MongoDB for analytics" | `postgres analytics performance`, `mongodb analytics performance` |
| Aspects | "Is Next.js good for a SaaS?" | `next.js auth`, `next.js hosting cost`, `next.js seo` |
| Time anchor | "Best search API" | `best search API 2026`, `search API pricing 2026` |
| Rephrasing | "Why is my agent slow" | `llm agent latency`, `reduce tool call latency` |
| Implied follow-ups | "How to cancel a Netflix trial" | `netflix trial cancel steps`, `netflix trial charge after cancel` |

## Do ChatGPT and other chat models fan out?

**Not when they search through the API, in our logs.** We recorded 163 answers from three OpenAI models (gpt-4.1, gpt-4.1-mini and gpt-4o-mini) with web search turned on, between November 16 and 24, 2026.

| What we measured | Result |
|---|---|
| Search queries per answer | **Exactly 1 in all 163 answers** |
| Results retrieved per answer | 13.2 on average |
| Results cited per answer | 7.2 on average |
| Median rank of a cited result | 8th |
| Queries where the model added an old year | 16 of 163 (10%) |

**So the models made up for a single query by reading deep into one result list.** 43% of citations came from results ranked below 10th. A real fan-out would have reached those pages through their own sub-queries instead, and would have caught pages that never appeared in the one list at all.

**One rewrite even made things worse:** "What is the cheapest web search API for AI agents?" became `cheapest web search API for AI agents 2024`, asked in November 2026. A fan-out with a date-anchored sub-query would have balanced that out. More on stale queries in [when an agent should search the web](/blog/when-should-ai-agent-search-the-web).

## How do I add query fan-out to my agent?

**Generate sub-queries with a model, search them in parallel, then merge.** The merge step is plain Python and runs as is:

```python
from collections import defaultdict

def rrf_merge(result_lists: list[list[dict]], k: int = 60, top_n: int = 10) -> list[dict]:
    """Reciprocal rank fusion: a URL scores 1/(k + rank) in every list it appears in."""
    scores, best = defaultdict(float), {}
    for results in result_lists:
        for rank, r in enumerate(results, start=1):
            scores[r["url"]] += 1 / (k + rank)
            best.setdefault(r["url"], r)
    ranked = sorted(scores, key=scores.get, reverse=True)[:top_n]
    return [{**best[u], "fused_score": round(scores[u], 5)} for u in ranked]

a = [{"url": "https://x.com/a"}, {"url": "https://x.com/b"}, {"url": "https://x.com/c"}]
b = [{"url": "https://x.com/b"}, {"url": "https://x.com/d"}]
print([r["url"] for r in rrf_merge([a, b])])
# ['https://x.com/b', 'https://x.com/a', 'https://x.com/d', 'https://x.com/c']
```

**Page `b` wins** because it appears in both lists, even though it was first in only one. That is the behavior you want: pages relevant to several parts of the question rise.

**The full fan-out**, with Claude writing the sub-queries and Keirolabs (ours) running the searches:

```python
import json, os, datetime, requests
from concurrent.futures import ThreadPoolExecutor
import anthropic

client = anthropic.Anthropic()

def search(q: str) -> list[dict]:
    r = requests.post("https://api.keirolabs.cloud/api/v2/search/lite",
                      headers={"Authorization": f"Bearer {os.environ['KEIRO_API_KEY']}"},
                      json={"query": q, "count": 10}, timeout=30)
    r.raise_for_status()
    return r.json()["results"]

def fan_out(question: str, max_queries: int = 5) -> list[dict]:
    msg = client.messages.create(
        model="claude-opus-5-5", max_tokens=1000,
        messages=[{"role": "user", "content":
            f"Today is {datetime.date.today()}. Write up to {max_queries} short web search queries "
            f"that together cover everything needed to answer the question. One per entity or aspect; "
            f'add the year only to time-sensitive queries. Reply as JSON: {{"queries": [...]}}\n'
            f"Question: {question}"}],
    )
    text = next(b.text for b in msg.content if b.type == "text")
    queries = json.loads(text[text.find("{"): text.rfind("}") + 1])["queries"][:max_queries]
    queries.append(question)                       # always keep the original question too
    with ThreadPoolExecutor(len(queries)) as pool:
        lists = list(pool.map(search, queries))
    return rrf_merge(lists, top_n=10)
```

**Three choices in that code matter:**

- **Keep the original question as one of the queries.** Sub-queries sometimes drift; the original anchors the merged list.
- **Cap the sub-queries in code.** Five is plenty for interactive answers. Deep research can go higher, inside a loop with a budget; see [agentic search](/blog/agentic-search).
- **Merge by rank, not by score.** Different queries return scores on different scales. Rank fusion ignores the scales, which is why it is the standard way to merge lists. [BM25, hybrid search and reciprocal rank fusion](/blog/bm25-hybrid-search-reciprocal-rank-fusion) goes into why.

## What does query fan-out cost?

**More searches, the same wall-clock time, and usually a better answer.** For five sub-queries plus the original question on Keirolabs `/search/lite`:

| | Single query | Fan-out (6 queries) |
|---|---|---|
| Searches | 1 | 6 |
| Search cost on plans | $0.00003 to $0.0001 | $0.0002 to $0.0006 |
| Added latency | none | One model call to plan the queries, plus the slowest search |
| Results to merge | 10 | Up to 60, deduplicated to the top 10 |

**The real cost is the planning call and the extra context, not the searches.** Keep the merged list to the top 10 before the model reads it, and fetch full pages only for the few it picks. [Context engineering for search agents](/blog/context-engineering-web-search-agents) has the numbers on why that matters.

## When should I not fan out?

- **Simple lookups:** "What's the capital of Peru" gains nothing from five queries.
- **Navigational queries:** "Stripe API docs" wants one link.
- **Tight latency budgets:** if you can't afford the planning call, use rules instead. Split on "vs", "and" and "compare", and add the year to time-sensitive questions.

A good default: fan out when the question names two or more things, asks to compare, or asks for "best", "top" or "options".

## What does query fan-out mean for SEO?

**Pages now compete for the sub-queries, not just the question a person typed.** If AI Mode splits "best search API for agents" into pricing, latency and accuracy sub-queries, a page that answers each of those clearly can be retrieved several times over. In our ChatGPT logs, cited pages had a median rank of 8, so ranking first matters less than being retrieved at all.

**What helps:**

- Answer the sub-questions explicitly, each under its own heading.
- Put specific numbers, dates and comparisons in the text, not only in images.
- Keep pages current, because fan-outs often add the year.

## Query fan-out checklist

- **Fan out on comparisons and multi-part questions, not simple lookups.**
- **Put today's date in the planning prompt, and add the year only to time-sensitive sub-queries.**
- **Keep the original question as one of the queries.**
- **Run sub-queries in parallel.**
- **Merge with reciprocal rank fusion, deduplicating by URL.**
- **Cap sub-queries and results in code.**

Keirolabs `/search/lite` costs $0.03 to $0.10 per 1,000 searches on plans, so a six-query fan-out costs less than a tenth of a cent. New accounts get up to 2,000 free credits with no card ([get a key](https://platform.keirolabs.cloud/register)).
