Sub topic 1
How AI systems find, select and quote web content
Prerequisites
This chapter assumes you can read basic HTML (headings, paragraphs, lists, tables) and have written or edited web content such as documentation, blog posts or help articles. It also assumes you know how a search engine shows a list of results. You don't need to know machine learning. The one code example is a short Python script, and you can run it with any Python 3 interpreter.
The short answer
An AI answer system finds web content in three steps. It retrieves candidate pages or passages. It selects the few passages that best match the question. It writes an answer that quotes or paraphrases those passages, often with links. Your content can only be quoted if it survives all three steps.
The details differ between products and change often. The overall pattern is stable enough to write for. Everything in this tutorial raises your chances of being quoted. None of it guarantees a citation.
Two ways a model gets information
An assistant can produce an answer from two different sources.
- Training data. The model learned patterns from a large body of text before it was released. It can state facts from that text, but it usually cannot say where a fact came from. It also has a cutoff date, so it knows nothing newer.
- Retrieval at answer time. The system searches an index or the live web when you ask, reads what it finds, and writes the answer from that material. This is the setup behind most answers that show source links. It is often called retrieval-augmented generation (RAG).
This tutorial is about the second path. When an answer links to your page, retrieval put your text in front of the model. You can influence retrieval directly, through how your page is written and whether crawlers can reach it. You cannot meaningfully influence what a model memorized during training.
The pipeline
The diagram shows the stages from question to quoted answer. The next sections walk through them.
Stage 1: Crawling and indexing
Before any question arrives, a crawler (an automated program that fetches web pages) visits pages and stores a processed copy. Some systems run their own crawler. Others rely on an existing search engine's index or on a live search call made at question time.
Two consequences matter for you:
- If a crawler cannot fetch your page, nothing later in the pipeline can use it. Blocking by robots.txt, a login wall, or content that only appears after heavy JavaScript can all cause this. A later chapter covers crawler access in detail.
- The stored copy is usually text extracted from your HTML. Layout, color and visual emphasis mostly disappear. What remains is the order of the text, your headings, lists and tables, and links.
Stage 2: Splitting into passages
Systems rarely score a whole page as one unit. They cut pages into passages (also called chunks), often a few sentences up to a few paragraphs long, and often using headings as boundaries. Each passage is scored on its own. The next chapter treats this in depth. For now, the practical point is that a passage may be judged and quoted without the rest of the page.
Stage 3: Query rewriting and retrieval
The user's question is often rewritten before searching. A long conversational question can become several shorter queries, and a follow-up like "what about the cost?" gets expanded using the earlier conversation. Each query returns candidates through one or both of these methods:
- Keyword matching. The index finds passages that share words with the query. This rewards using the exact terms people search for.
- Semantic matching. Text is converted to numeric vectors (embeddings) so that passages with a similar meaning land near the question even if the wording differs.
Many systems combine both. That is why you want the plain terms in your text and also a clear, unambiguous meaning.
Stage 4: Reranking and selection
The first retrieval pass returns many candidates, perhaps dozens. A second step, the reranker, reads each candidate more carefully against the question and orders them. Only the top few go to the language model, because the model has a limited context window (the amount of text it can read at once) and extra noise lowers answer quality.
At this stage a passage competes with others on questions such as:
- Does it directly answer the question, or only discuss the topic?
- Is it understandable without surrounding text?
- Does it contain a specific, checkable claim?
- Does the page seem trustworthy and relevant for this subject?
The last point depends on signals outside a single passage, such as the reputation of the site. You can't fix that with formatting. You can improve the first three.
Stage 5: Generation and citation
The language model receives the question and the selected passages, and writes an answer. It may copy a sentence nearly word for word, paraphrase, or merge several passages. Citations are usually attached to the passages that supplied the material. The model can still make mistakes: it may attribute a claim to the wrong source, or blend two passages into a statement neither one made. You can't control that. You can make your passage easy to quote correctly by keeping each claim short and complete.
A toy retrieval example
The script below is a deliberately simplified version of stages 2 to 4. It scores passages by how many of the question's meaningful words they contain, then quotes the best one with its source. Real systems use embeddings and trained rerankers, so don't treat the scoring as realistic. The point is that each passage is scored in isolation, and that a passage which answers the question outright beats one that only introduces the topic.
import re
from collections import Counter
STOP = {"how", "should", "i", "the", "a", "is", "of", "to", "and", "it", "on", "your", "as"}
PASSAGES = [
("https://example.com/caching#how-long",
"Cache API responses for as long as the data can be stale without harming users. "
"For data that changes a few times a day, a TTL of 5 to 15 minutes is a common starting point."),
("https://example.com/caching#intro",
"Caching has been used in computing for decades, and teams approach it in many ways."),
("https://example.com/caching#setup",
"Your cache setup depends on traffic. It is covered below."),
]
def tokens(text):
return re.findall(r"[a-z0-9]+", text.lower())
def score(query, passage):
wanted = set(tokens(query)) - STOP
present = Counter(tokens(passage))
hits = sum(1 for word in wanted if present[word] > 0)
return hits / len(wanted) if wanted else 0.0
def answer(query):
ranked = sorted(PASSAGES, key=lambda p: score(query, p[1]), reverse=True)
for url, text in ranked:
print(f"{score(query, text):.2f} {url}")
best_url, best_text = ranked[0]
first_sentence = best_text.split(". ")[0].rstrip(".") + "."
print(f'\nAnswer: "{first_sentence}" (source: {best_url})')
answer("How long should I cache API responses?")Running it prints the three passages ranked 1.00, 0.25 and 0.00, then quotes the first sentence of the winner. Three things are worth noticing:
- The winning passage was written answer-first, so its first sentence works as the quote.
- The intro passage scored zero. It talks about "caching" generally, uses a different word form ("caching" rather than "cache"), and never answers the question. A semantic system would do better than this script, but it would still prefer the passage that states an answer.
- The script quotes only one sentence. Real systems also lift short spans, which is why the opening sentences of a passage matter so much.
What this means for how you write
Each stage suggests a habit that later chapters develop.
| Pipeline stage | What can go wrong | Habit that helps |
|---|---|---|
| Crawling | Crawler blocked or page content not in the HTML | Allow the right crawlers, serve text in the HTML |
| Splitting | A key claim is separated from the term it explains | Keep each section self-contained |
| Retrieval | Page uses vague or unusual wording | Use the terms people actually ask with, and define them |
| Reranking | Many passages discuss the topic, none answer it | State the answer in the first sentences |
| Generation | A vague claim gets distorted or skipped | Make specific claims with numbers and named sources |
Common errors
- Assuming the whole page is read. The model usually sees a few passages, not the page. A conclusion on the last screen and a definition three sections earlier may never reach the model together.
- Treating one assistant as all assistants. Products differ in crawlers, indexes, reranking and citation style. Advice that works across them is about clear passages and access. Advice that depends on one vendor's internals can expire quickly.
- Believing that markup forces citation. Structured data and clean HTML help systems read your page correctly. They don't make a system choose it.
- Writing for the model instead of the reader. Passages that read like keyword lists tend to be poor answers, and a passage must also satisfy the person who clicks through.
- Judging success from one query. Answers vary between runs and over time. Chapters later in this tutorial cover repeated testing.
Limits of what you can know
Most vendors publish only partial descriptions of how they select sources, and the behavior changes with model and product updates. Treat any claim about a precise ranking factor as a hypothesis. Rely on what is documented, such as crawler names and robots.txt behavior, and on your own tests of real questions.
Exercise
A page opens with three paragraphs of history about caching, and the practical advice ("use a TTL of 5 to 15 minutes for data that changes a few times a day") appears in paragraph four. Name two pipeline stages where this layout can cost the page a citation, and say why.
Show answer
Splitting and reranking. When the page is split into passages, the first passages contain only history, and they may be judged without the advice in paragraph four. During reranking, those history passages do not answer the question and score low, while a competitor's passage that states the answer directly scores higher. A third possible loss is at generation, where a long passage with the answer buried inside is harder to quote cleanly. The fix is to put the advice in the first sentences under a heading that names the question.
Exercise
Why does blocking a crawler in robots.txt stop a page from being quoted by a retrieval-based assistant that uses that crawler, no matter how well the page is written?
Show answer
Retrieval depends on content that was fetched and indexed. If the crawler cannot fetch the page, no passages from it enter the index, so none can be matched, reranked or passed to the language model. Writing quality only matters after access is allowed.