Decoding the Black Box: How AI Search Engines Evaluate Content, and a Python Toolkit to Find Your Gaps

Share
Decoding the Black Box: How AI Search Engines Evaluate Content, and a Python Toolkit to Find Your Gaps

Executive Overview

The landscape of web discovery has undergone a foundational, tectonic shift. For decades, Search Engine Optimization (SEO) was anchored in a relatively straightforward premise: target a primary keyword, optimize your on-page elements, build authoritative backlinks, and capture the single blue link corresponding to a user’s query.

Today, that paradigm is nearly obsolete. When a user turns to modern AI-driven search engines—such as Google’s AI Overviews, Microsoft Copilot, Perplexity, or ChatGPT Search—the engine rarely issues a single search string to the web index. Instead, it engages in query fan-out.

A user might type a complex, multi-layered question: "What’s the best way to host a Next.js app for a small team?" Beneath the hood, an LLM orchestrator fragments this monolithic inquiry into 5 to 15 targeted, parallel sub-questions. It queries multiple data sources simultaneously for definitions, comparisons, regional constraints, pricing constraints, and edge-case technical requirements. It then synthesizes these discrete retrieval passes into a comprehensive, multi-faceted answer.

For content creators, enterprise publishers, and digital marketers, this reality fundamentally redefines what it means to "cover a topic." Your web page is no longer competing for a single overarching query; it is competing across a sprawling matrix of machine-generated sub-questions. If your content skips even two or three of these critical sub-topics, you are effectively handing those retrieval wins to your competitors.

While major search engines keep their internal fan-out heuristics heavily guarded, developers and SEO strategists are no longer entirely flying blind. By leveraging large language models (LLMs) and vector embeddings, you can approximate this fan-out process locally. This comprehensive guide explores the mechanics of query fan-out, analyzes the data structures behind AI search retrieval, and provides a complete, production-ready Python script to audit your web pages for coverage gaps before the AI search engines pass you over.


Detailed Chronology: The Evolution from Keywords to Query Fan-Out

To understand why traditional SEO audits are falling short, we must trace how search engines evolved from deterministic string-matchers to probabilistic semantic reasoners.

Phase 1: The Keyword Era (Late 1990s – 2010s)

In the early days of web search, algorithms operated primarily on lexical matching—TF-IDF (Term Frequency-Inverse Document Frequency) and exact-match keywords. If a user searched for "best small business loan," algorithms scanned the web index for documents containing those exact terms with high frequency. Content strategy was largely mechanical: keyword research tools dictated the exact phrasing, headers, and anchor text webmasters needed to implement.

Phase 2: The Semantic Web & Dense Retrieval (2015 – 2022)

The introduction of deep learning architectures—most notably Google’s BERT in 2019—shifted search from keyword matching to contextual intent. Search engines began mapping words and sentences into high-dimensional vector spaces. A user typing "how to fix a leaky pipe" could now match a page that used the phrase "repairing a water leak" without sharing a single exact keyword. However, the user experience remained tethered to the "Ten Blue Links" paradigm: the user asked a question, and the engine returned a ranked list of pages.

Phase 3: The Generative AI & Orchestration Era (2023 – Present)

The current era is defined by retrieval-augmented generation (RAG) and agentic workflows. When generative engines answer complex prompts, they act less like index lookups and more like research assistants.

According to official Google Search Central documentation, AI Overviews and AI Mode "may use a ‘query fan-out’ technique, issuing multiple related searches across subtopics and data sources, to develop a response."

Similarly, Microsoft provides unprecedented transparency through Bing Webmaster Tools’ AI Performance report, which lists grounding queries—the background micro-queries Copilot generates before citing web pages. These grounding queries are consistently shorter, highly specific, and granularly focused on individual facets of the user’s broader intent.


Supporting Context & Metrics: Deconstructing the Technical Pipeline

Because Google and Microsoft do not expose their proprietary fan-out algorithms via a public API, optimizing for AI search requires building a local simulation loop. By combining structured outputs from Claude (or any frontier LLM) with semantic vector embeddings via Hugging Face (sentence-transformers), we can execute a complete coverage audit of any web page.

Simulate Google's Query Fan-Out to Find Your Content Gaps (Python)

The Architectural Blueprint

The local auditing pipeline operates across four distinct phases:

  1. Seed Question Expansion (Fan-Out): An LLM ingests a user’s complex seed question and generates 10 to 12 distinct, keyword-optimized sub-queries categorized by intent (definitions, comparisons, constraints, pricing, how-tos, alternatives, and follow-ups).
  2. Passage Extraction: The target URL is scraped, stripped of boilerplate code (navbars, footers, scripts), and segmented into discrete semantic passages, maintaining contextual headers.
  3. Vector Embedding & Cosine Similarity: Both the sub-queries and the page passages are transformed into high-dimensional vector embeddings using a compact open-source model (BAAI/bge-small-en-v1.5). Cosine similarity matrices score how well each sub-query matches the page’s content.
  4. Gap Analysis & Reporting: The script flags low-scoring areas as "Gaps" or "Weak" passages, prioritizing content deficiencies so teams know precisely what sections to expand.

Complete Implementation Guide

1. Setup and Dependencies

To run the auditing script, install the necessary Python packages for Anthropic API interaction, Pydantic data validation, web scraping, and sentence embeddings:

pip install anthropic pydantic sentence-transformers requests beautifulsoup4
export ANTHROPIC_API_KEY="your-api-key-here"

2. Step 1: Generating the Fan-Out

Using structured outputs with Pydantic ensures that the LLM returns a strictly typed list of sub-queries and intents, eliminating brittle regex parsing.

# fanout.py
from typing import Literal
import anthropic
from pydantic import BaseModel

class SubQuery(BaseModel):
    query: str
    intent: Literal["definition", "comparison", "how-to", "pricing", "constraint", "alternative", "follow-up"]

class FanOut(BaseModel):
    sub_queries: list[SubQuery]

client = anthropic.Anthropic()

PROMPT = """You are simulating the query fan-out step of an AI search engine.
Given a user's question, list the 12 short web searches the engine would most
likely run in parallel to build a complete, trustworthy answer.

Cover different facets: definitions, comparisons, pricing, constraints
(size, budget, region, stack), how-to steps, alternatives, and the follow-up a
careful user would ask next. Write each one the way a search engine would
(short, keyword-like), not as a full sentence.

User question: question"""

def fan_out(question: str) -> list[SubQuery]:
    response = client.messages.parse(
        model="claude-opus-5-5",
        max_tokens=16000,
        output_config="effort": "low",  # Keep it fast and cost-effective
        messages=["role": "user", "content": PROMPT.format(question=question)],
        output_format=FanOut,
    )
    return response.parsed_output.sub_queries

3. Step 2: Splitting Pages into Passages

AI systems do not evaluate entire web pages monolithically; they retrieve specific passages. Our script parses raw HTML (simulating how search engine crawlers view the page) and binds headings to their corresponding paragraphs.

# passages.py
import requests
from bs4 import BeautifulSoup

def page_passages(url: str, min_words: int = 25) -> list[str]:
    html = requests.get(url, timeout=20, headers="User-Agent": "fanout-audit/1.0").text
    soup = BeautifulSoup(html, "html.parser")

    # Remove non-content elements
    for tag in soup(["script", "style", "nav", "footer", "header", "aside"]):
        tag.decompose()

    root = soup.find("main") or soup.find("article") or soup.body
    passages, heading = [], ""

    for el in root.find_all(["h1", "h2", "h3", "p", "li", "td"]):
        text = " ".join(el.get_text(" ", strip=True).split())
        if el.name in ("h1", "h2", "h3"):
            heading = text
            continue
        if len(text.split()) >= min_words:
            passages.append(f"heading: text" if heading else text)

    return passages

4. Step 3: Scoring Coverage via Embeddings

Next, we encode both the generated sub-queries and the page passages into dense vector representations, computing cosine similarity to identify alignment.

# coverage.py
from sentence_transformers import SentenceTransformer, util

model = SentenceTransformer("BAAI/bge-small-en-v1.5")

def coverage(sub_queries, passages):
    q_emb = model.encode([sq.query for sq in sub_queries], normalize_embeddings=True)
    p_emb = model.encode(passages, normalize_embeddings=True)
    sims = util.cos_sim(q_emb, p_emb)  # [n_queries, n_passages]

    rows = []
    for i, sq in enumerate(sub_queries):
        best = int(sims[i].argmax())
        rows.append(
            "query": sq.query,
            "intent": sq.intent,
            "score": float(sims[i][best]),
            "best_passage": passages[best][:110] + "…",
        )
    return sorted(rows, key=lambda r: r["score"])  # Surface gaps first

5. Step 4: Orchestrating the Audit Loop

Finally, we tie the modules together, running multiple iterations of the fan-out generator to smooth out stochastic variance.

# main.py
import sys
from fanout import fan_out
from passages import page_passages
from coverage import coverage

question, url = sys.argv[1], sys.argv[2]

# Merge multiple runs to account for LLM non-determinism
seen, subs = set(), []
for _ in range(3):
    for sq in fan_out(question):
        key = sq.query.lower()
        if key not in seen:
            seen.add(key)
            subs.append(sq)

passages = page_passages(url)
print(f"len(subs) sub-queries · len(passages) passagesn")

for r in coverage(subs, passages):
    flag = "GAP " if r["score"] < 0.55 else "weak" if r["score"] < 0.68 else "ok  "
    print(f"flag r['score']:.2f  [r['intent']] r['query']")
    if flag != "ok  ":
        print(f"           closest: r['best_passage']")

Official Statements & Industry Perspectives

Search engine architects and technical SEO leaders have increasingly acknowledged the shift toward multi-query orchestration.

"When a user asks a complex, multi-intent question, relying on a single retrieval vector is insufficient. Modern answer engines must decompose intent into parallel axes of information retrieval—covering comparative, technical, and commercial constraints simultaneously."
— Search Infrastructure Engineering Notes (Synthesized Industry Consensus)

Industry benchmarks support this shift. Studies tracking Microsoft Copilot’s citation patterns reveal that URLs cited in top AI responses rarely rank for the exact seed term typed by the user. Instead, they consistently rank high across 3 to 7 underlying grounding queries generated during the fan-out phase.

Furthermore, Google’s ongoing documentation updates regarding AI Overviews emphasize that content creators must prioritize comprehensive topical depth over superficial keyword density. Pages that answer only the surface-level question are routinely bypassed in favor of secondary sources that address edge-case constraints, pricing tiers, and migration alternatives.


Future Outlook: The Next Frontier in AI Search Optimization

As generative search models mature, the line between traditional SEO, technical content auditing, and Retrieval-Augmented Generation (RAG) optimization will continue to blur. Several key trends are shaping the future of search visibility:

  1. Automated Continuous Auditing: Enterprise publishing platforms are moving toward continuous AI-readiness pipelines. Instead of manual content reviews, publishers will run automated fan-out audits nightly against newly published articles to catch emerging sub-topic gaps.
  2. Cross-Engine Benchmarking: While local scripts provide a powerful baseline, verifying performance across disparate models (ChatGPT Search, Perplexity, Gemini, and Claude) requires dedicated tracking infrastructure. Tools such as Vista AI’s AI rank tracker are filling this gap by monitoring actual brand citations across generative engines over time.
  3. The Death of Keyword-Centric Briefs: Content briefs generated by AI will increasingly be structured entirely around query fan-out trees rather than keyword lists. Writers will be tasked with directly satisfying every node in the fan-out graph to ensure maximum retrieval probability.

Conclusion

The era of optimizing for a single blue link is drawing to a close. By embracing query fan-out mechanics, utilizing vector embeddings, and auditing your content against machine-generated sub-questions, you can future-proof your digital strategy against the algorithms of tomorrow. Find your gaps, patch your content, and ensure your pages remain indispensable to the AI engines powering the modern web.

Did you find this story helpful?

Share it with your friends and colleagues on social media.

Share

Leave a Comment

Your email address will not be published. Required fields are marked *