Sub topic 10
Passages and Chunking: What Actually Gets Retrieved
This chapter assumes you know the basics from earlier chapters: retrieval-augmented generation (RAG), the difference between lexical and semantic retrieval, and the idea that an AI search system may split one prompt into several sub-queries. Here we look at the unit that retrieval returns. In most RAG-style systems that unit is a passage, not a whole page.
Why pages are not the unit of retrieval
Classic search ranks whole URLs. A RAG pipeline usually works differently, for two practical reasons.
- A language model can only read a limited amount of text at once. This limit is called the context window. Feeding it ten full pages for every sub-query would be slow and expensive, and it would bury the useful sentences in noise.
- An embedding (a list of numbers that represents the meaning of a piece of text) works best when the text is about one thing. One vector for a 4,000-word page blurs many topics together.
So before any search happens, documents are split into smaller pieces. Each piece is called a chunk or passage. Each chunk is indexed on its own, with its own embedding and, in hybrid systems, its own keyword statistics. When a sub-query arrives, the system searches chunks, not pages.
Which systems do this, and exactly how, is mostly not public. Chunking is a widely documented engineering practice in open RAG tooling. Whether a specific AI search product chunks your page in a specific way is an inference, not a fact you can check.
How chunking works
A chunker is the code that cuts a document into passages. Common strategies are listed below.
| Strategy | How it cuts | Strength | Weakness |
|---|---|---|---|
| Fixed size | Every N tokens or characters | Simple and predictable | Cuts mid-sentence or mid-idea |
| Fixed size with overlap | Fixed size, but neighbouring chunks share some text | Keeps ideas that straddle a boundary | Duplicates text in the index |
| Sentence or paragraph based | Splits on natural boundaries | Chunks read cleanly | Uneven chunk sizes |
| Structure aware | Splits on headings, lists, tables | Chunks follow your outline | Depends on clean HTML or Markdown |
| Semantic | Starts a new chunk where the topic shifts | Chunks match ideas | Costs more to compute, less predictable |
A token is a small unit of text, roughly three-quarters of an English word. Chunk sizes in public RAG guides often fall in the range of a few hundred tokens, but this varies a lot and no single value applies to all AI search products.
Here is a simplified structure-aware chunker. It is a teaching sketch, not a model of any real search system. It splits Markdown on headings and keeps the heading with its text.
import re
def chunk_by_heading(markdown_text, max_words=120):
"""Split Markdown into chunks at headings, then cap each chunk's length."""
sections = re.split(r"(?m)^(?=#{1,3} )", markdown_text)
chunks = []
for section in sections:
section = section.strip()
if not section:
continue
lines = section.splitlines()
heading = lines[0] if lines[0].startswith("#") else ""
body_words = " ".join(lines[1:] if heading else lines).split()
for start in range(0, max(len(body_words), 1), max_words):
piece = " ".join(body_words[start:start + max_words])
chunks.append((heading + "\n" + piece).strip())
return chunks
page = """# Running shoes for flat feet
Flat feet often go with overpronation, where the ankle rolls inward.
## Stability vs motion control
Stability shoes add support for mild overpronation. Motion control shoes are stiffer and suit heavier runners or severe overpronation.
## Price
Good options start around 100 dollars.
"""
for i, chunk in enumerate(chunk_by_heading(page), start=1):
print(f"--- chunk {i} ---")
print(chunk)Running this produces three chunks, one per heading. Each chunk carries its heading, so it still makes sense when read alone.
A chunk is read alone
The most important consequence for content is that a retrieved chunk arrives without the rest of the page. The model that writes the answer sees the chunk, perhaps the page title and URL, and little else. Anything the chunk depends on from elsewhere on the page is lost.
Compare two versions of the same fact.
- Dependent: "It is also available in a wider fit, which costs more." The reader does not know what "it" is.
- Self-contained: "The Brooks Adrenaline GTS is also available in a wide fit, which costs about 10 dollars more." (The shoe is an example here, not a recommendation or verified price.)
The second version can be retrieved for a sub-query about wide fits and still be understood by the model. The first cannot.
The path from page to answer
The diagram shows where chunking sits in the flow. Chunking and indexing happen ahead of time. Everything after the sub-queries happens at question time.
Edge cases and common errors
- Boundary splits. A definition in one chunk and its qualification in the next may be retrieved separately. The model then states the definition without the caveat. Overlap reduces this but does not remove it.
- Tables and lists. A table cut in half loses its header row, so the numbers in the second half have no labels. Repeat key labels in cell text or in a sentence near the table. Clean HTML tables and real list markup are easier for a structure-aware chunker to keep together than images of tables or layouts built from div elements.
- Content that needs scripts. If text appears only after JavaScript runs, a crawler that does not run scripts never sees it, so it is never chunked. Whether a given crawler renders JavaScript differs by system and should be tested, not assumed.
- Boilerplate chunks. Navigation, cookie notices and footers can become chunks too. They are rarely useful, but they dilute nothing in your own passages. They only waste index space. Do not worry about them more than about your main text.
- Very long sections. A section of 1,500 words under one heading will be cut at an arbitrary point by a fixed-size chunker. Subheadings give a structure-aware chunker better cut points.
- Weak headings. A heading like "More information" tells a chunk nothing. A heading like "Stability vs motion control shoes for overpronation" adds matching words and meaning to every chunk beneath it.
What is known and what is inferred
- Documented: open RAG frameworks and vector database documentation describe chunking, overlap and structure-aware splitting as standard steps.
- Documented in general terms: AI search products retrieve and cite web sources.
- Inferred: that a given product uses passage-level retrieval with chunk sizes and boundaries similar to those in open tooling.
- Unknown from outside: exact chunk size, overlap, whether heading text is added to each chunk, and whether the chunker changes between updates.
Because the exact rules are hidden, aim for writing that survives many chunkers. Make each section stand alone and stay on one topic. Put the direct answer near the top of the section, and keep the key terms and labels inside the section text.
A practical checklist
- Give each major sub-question its own heading, written the way a person would ask or name it.
- Open each section with a sentence that answers the question without needing earlier context.
- Repeat the subject by name instead of using "it" or "this" across paragraph starts.
- Keep one topic per section, and keep sections to a few short paragraphs.
- Put units, dates, prices and conditions in the same passage as the claim they qualify.
- Use real HTML headings, lists and tables, and make sure the text is in the HTML the crawler receives.
- Read each section aloud with the rest of the page covered. If it confuses you, it will confuse a chunk reader.
Exercise
A product page says: "Our top model is the Trail 300. It weighs 280 g. This makes it ideal for racing, though as noted earlier it runs narrow." Rewrite this so that a single chunk containing only these sentences still answers a sub-query about the weight and fit of the Trail 300.
Show answer
One acceptable rewrite: "The Trail 300 is our top trail running shoe. The Trail 300 weighs 280 g, which suits racing. The Trail 300 runs narrow, so runners with wide feet may prefer a different model." It names the subject in every sentence, removes "it", "this" and "as noted earlier", and keeps the weight and the fit caveat in the same passage.
Exercise
Why can a page with strong overall content still lose a citation to a shorter page for a specific sub-query?
Show answer
Retrieval usually compares the sub-query with individual chunks, not whole pages. The shorter page may contain one self-contained passage that matches the sub-query closely, while the strong page spreads the same answer across several sections or hides it behind pronouns and references to other parts of the page. This is an inference from how RAG systems are documented, not a confirmed rule for any one product.