Sub topic 1
How AI answer systems find and quote your content
Prerequisites
This chapter assumes you can read basic HTML (headings, paragraphs, lists, tables) and have edited web content before. You should know roughly how a search engine shows a list of results. The code example uses Python 3 and only the standard library. You don't need any machine learning background. The chapter explains the few concepts it uses.
Why this chapter comes first
Every later chapter in this tutorial gives advice about headings, lists, and tables. That advice only makes sense if you know what happens to your page after you publish it. This chapter describes that process and shows where page structure changes the outcome.
Two warnings apply throughout. First, vendors don't publish the exact details of their systems, so this chapter describes the common pattern, not any one product. Second, no structure guarantees that your page will be retrieved or cited. Structure removes obstacles. It doesn't force a result.
The pipeline from page to cited answer
Most AI search and answer systems are built on retrieval. The system doesn't answer only from what the model memorized in training. It looks up documents at question time, then writes an answer based on what it found. This approach is often called retrieval-augmented generation (RAG).
A typical flow has six stages:
- Crawl. A crawler fetches your page by URL.
- Parse. The fetched HTML is turned into text and structure.
- Split. The text is cut into passages, also called chunks.
- Index. Each passage is stored so it can be searched, usually by keywords, by embeddings, or by both.
- Retrieve and rank. When a user asks a question, the system finds the best-matching passages and reorders them.
- Generate and cite. A language model writes an answer from the top passages and links to their sources.
Your structure matters most at stages 2, 3, and 5. Parsing reads your HTML elements. Splitting often uses your headings as cut points. Ranking compares the question to individual passages, not to your whole page.
Passages are the unit of retrieval
A model can't read a whole site for every question. Systems have limited space for the text they hand to the model, and long documents contain a lot of material that is irrelevant to any one question. So the system retrieves passages, not pages.
A passage is usually a few sentences to a few paragraphs, often somewhere between 100 and 500 words. Each passage is scored on its own. Your page can be excellent overall and still lose to a competitor's page because one of their passages matches the question better.
This has three consequences for how you write:
- A passage can be shown without its neighbors. The model may see only one section of your page. If that section says "it" or "the above setting" without naming the thing, the reader of the answer can't tell what it refers to.
- The best passage wins, not the best page. A strong opening sentence in a section helps that section's passage, even if the rest of the page is average.
- Where the cut falls matters. If a splitter cuts through the middle of a step-by-step procedure, neither half answers the question.
How systems decide where to cut
Splitters range from crude to structure-aware. Knowing the common types shows why your markup matters.
| Splitting method | How it cuts | Effect of your structure |
|---|---|---|
| Fixed size | Every N characters or tokens, often with some overlap | Little. Cuts can land mid-sentence or mid-list. |
| Sentence or paragraph | At sentence or paragraph boundaries | Short, focused paragraphs produce cleaner passages. |
| Heading-based | At h1 to h6 boundaries, keeping the heading path with the text | Large. Headings define the passages and label them. |
| Layout-based | Using rendered page blocks such as lists and tables | Large. Real lists and tables stay together as units. |
You can't know which method a given system uses, and many combine several. Heading-based and layout-based splitting reward the same habits: one clear heading per topic, and real list and table elements. Fixed-size splitting rewards short, self-contained sections, because any cut then costs you less. Writing for all of them costs nothing, since the habits don't conflict.
Retrieval: matching a question to a passage
Retrieval usually combines two kinds of matching.
Lexical matching compares words. Classic keyword scoring such as BM25 rewards passages that contain the question's terms, especially rare ones. If the user asks about a "factory reset" and your passage says "restore defaults" without ever using that phrase, lexical matching may miss it.
Semantic matching compares meaning. An embedding model converts text into a list of numbers (a vector), so passages with similar meaning end up close together. A question and a passage that use different words can still match. This helps with paraphrases, but vectors are fuzzy. A passage that mixes several topics gets a blurred vector that matches none of them well.
Many systems run both and merge the results, then apply a reranker, a model that reads the question and each candidate passage together and rescores them. Rerankers favor passages that directly answer the question, which is why answer-first writing, covered in a later chapter, pays off.
What you can do with this knowledge:
- Use the words your audience uses, including the exact names of products, settings, and error messages.
- Keep each passage about one topic so its meaning is not blurred.
- Put the answer in the passage itself, not in a link to somewhere else.
What headings contribute
Many pipelines attach the heading path to each passage. A passage under "How to Reset a Router > What does a factory reset do?" carries those two headings as context. That context can be embedded together with the text and shown to the reranker and the model.
This is why a heading like "Overview" or "More info" wastes an opportunity. It adds no information to the passage. A heading that states the topic or asks the question adds words that match what users search for.
The next script shows the idea. It splits HTML at headings and keeps the heading path with each passage. Real systems are more sophisticated, but the mechanism is the same.
from html.parser import HTMLParser
class Chunker(HTMLParser):
"""Split HTML into passages at headings, keeping the heading path."""
def __init__(self):
super().__init__()
self.path = [] # list of (level, heading text)
self.heading_level = None
self.heading_buf = []
self.text_buf = []
self.chunks = []
def flush(self):
text = " ".join(" ".join(self.text_buf).split())
if text:
path = " > ".join(title for _, title in self.path)
self.chunks.append({"path": path, "text": text})
self.text_buf = []
def handle_starttag(self, tag, attrs):
if len(tag) == 2 and tag[0] == "h" and tag[1] in "123456":
self.flush()
self.heading_level = int(tag[1])
self.heading_buf = []
def handle_data(self, data):
if self.heading_level:
self.heading_buf.append(data)
else:
self.text_buf.append(data)
def handle_endtag(self, tag):
if self.heading_level and tag == "h" + str(self.heading_level):
title = " ".join("".join(self.heading_buf).split())
while self.path and self.path[-1][0] >= self.heading_level:
self.path.pop()
self.path.append((self.heading_level, title))
self.heading_level = None
def chunk(html):
parser = Chunker()
parser.feed(html)
parser.close()
parser.flush()
return parser.chunks
page = """
<h1>How to Reset a Router</h1>
<p>This guide covers two kinds of reset.</p>
<h2>What does a factory reset do?</h2>
<p>A factory reset erases all saved settings and restores the router
to its default configuration.</p>
<h2>How do I restart without erasing settings?</h2>
<p>Unplug the router for 30 seconds, then plug it back in.</p>
"""
for passage in chunk(page):
print(passage["path"], "=>", passage["text"])Running it prints three passages. The second is:
How to Reset a Router > What does a factory reset do? => A factory reset erases all saved settings and restores the router to its default configuration.Read that passage by itself. It names its subject, and its heading path tells you which guide it belongs to. Now imagine the paragraph had said "It erases everything" under a heading of "Details". Both the passage and its path would be nearly useless as a quoted answer.
How the answer is built and attributed
After ranking, the top few passages are placed into the model's prompt along with the question. The model writes an answer and, in many products, attaches citations that point to the source pages.
Several behaviors follow from this:
- Quoting versus paraphrasing. The model may copy a sentence nearly word for word or rewrite it. Sentences that are accurate and complete on their own survive both treatments.
- Extraction of lists and tables. When a question asks for steps or a comparison, a system can often lift an ordered list or a table intact. Structure that exists only through styling, such as bold text and line breaks, is harder to extract correctly.
- Citation is not guaranteed. A system may use your passage and not link to you, or link to a page whose passage it only partly used. Citation depends on the product's policies as well as on your page.
- Stale or conflicting passages. If your site has two pages that answer the same question differently, either may be retrieved. Keep one authoritative answer per question.
Edge cases that block retrieval before structure matters
Good structure can't help a page that never reaches the index. Check these first:
- Blocked crawling. A robots.txt rule or a meta robots tag can keep crawlers out. Different systems use different crawler names, so check each one you care about.
- Content rendered only by JavaScript. Some crawlers don't run scripts. If your answer text appears only after client-side rendering, it may be missing from the parsed HTML. Server-rendered or static HTML is the safest source of text.
- Content behind interaction. Text inside tabs, accordions, or "read more" controls is sometimes missed, depending on how it's implemented. Content that is present in the HTML but visually collapsed is usually fine. Content fetched only after a click usually isn't.
- Login walls and paywalls. Crawlers generally can't pass them.
- Text inside images. A table or step list saved as an image has no extractable text. Use real HTML, and add the image only as an extra.
- Duplicate or near-duplicate pages. Competing copies split signals between URLs and can cause the wrong version to be quoted.
What to take into the next chapters
The pipeline gives each later chapter a concrete purpose:
| Later topic | Pipeline stage it helps |
|---|---|
| Semantic HTML and heading hierarchy | Parsing and splitting |
| Descriptive headings | Retrieval, because the heading path becomes part of the passage |
| Self-contained sections and answer-first paragraphs | Reranking and quoting, because a passage must stand alone |
| Lists and tables | Extraction of steps and comparisons as intact units |
| Structured data | Optional extra signals that must match the visible text |
| Auditing | Checking that your page behaves as these stages assume |
Exercises
Exercise
A page has the heading "Details" followed by a paragraph that begins "It can be changed in the menu above." Give two reasons why this passage is a poor candidate for being quoted in an AI answer, and say how you would fix each.
Show answer
First, the heading "Details" adds no topic words, so lexical and semantic matching get no help from the heading path. Fix it by renaming the heading to state the topic or ask the question, such as "How do I change the display language?". Second, "It" and "the menu above" depend on neighboring text that may not travel with the passage. Fix it by naming the subject and the exact menu in the paragraph itself, for example "You can change the display language in Settings > Language."
Exercise
A site publishes its full pricing comparison as a PNG image, and the answer text for each plan appears only after the user clicks a tab that loads content with JavaScript. Which stages of the pipeline are most likely to fail, and what would you change?
Show answer
The parse stage is most likely to fail, because neither the image nor the click-loaded text appears as extractable text in the fetched HTML. As a result the splitter has nothing to cut and the index has nothing to match. Replace the image with a real HTML table with a caption and header cells, and put the plan text in the server-rendered HTML so it exists before any script runs.