Content Chunking for AI Search: How to Engineer Machine-Readable Content
Chunking for AI search decides which pieces of your article a retrieval system can find. Before an AI system can quote your content, it usually splits the page into passages. It then turns each passage into an index entry and retrieves only the best matches for a question. If the split cuts your answer in half, or buries it in an unrelated block, the passage may never be retrieved.
This guide explains how chunking works in information retrieval, compares fixed-size and semantic chunking, and shows a reproducible Python experiment. The experiment measures how each strategy performs on the same controlled dataset.
What does content chunking mean in information retrieval?
Short answer: Chunking is the process of splitting a long document into smaller passages before indexing. Each passage becomes a separate unit that a search or RAG system can score, retrieve and pass to a language model.
Retrieval systems work on chunks because whole pages are too long and too mixed. A 2,000-word guide may answer ten different questions. Splitting it lets the system match one question to the one passage that answers it. Our guide to RAG in AI search explains where chunking sits in the full pipeline.
What is the difference between fixed-size and semantic chunking?
Short answer: Fixed-size chunking cuts text every N words or tokens, regardless of meaning. Semantic chunking follows the document’s structure, such as headings, paragraphs or topic shifts, so each chunk covers one idea.
| Strategy | How it splits | Strength | Weakness |
|---|---|---|---|
| Fixed size | Every N words or tokens | Simple and predictable | Can cut answers in half |
| Fixed size with overlap | Every N words, repeating some words | Reduces lost context at edges | More chunks and repeated text |
| Sentence windows | Every few sentences | Never splits a sentence | Small chunks can lack context |
| Heading sections | One chunk per section | Keeps topic and label together | Long sections may exceed limits |
How do token limits and context windows shape chunking for AI search?
Short answer: Embedding models accept a limited number of tokens per input, and language models read a limited amount of retrieved text per answer. Chunks must fit both limits, so very long sections get split again.
In practice, many systems use chunks of a few hundred tokens. You cannot control the exact size an AI search engine uses. You can, however, write sections short enough that a typical chunk holds a complete answer. That is the core of chunking for AI search from a content point of view.
How do chunk overlap and contextual completeness work together?
Short answer: Overlap repeats a few words between neighboring chunks so ideas at the boundary are not lost. Contextual completeness means each chunk makes sense alone. Overlap is a technical patch; completeness is a writing habit.
A chunk that starts with “It also includes…” loses its subject once separated from the previous chunk. Overlap may carry the subject across, but only by chance. Naming the subject in each section’s first sentence works every time. Our guide to semantic HTML for AI search covers the markup side of the same idea.
What is passage-level relevance in chunking for AI search?
Short answer: Passage-level relevance means a retrieval system scores each chunk against the question, not the whole page. A page can be highly relevant overall and still lose if its best passage is weak.
This changes how you write. Every section should answer one question directly, with the specific terms a buyer would use. A strong page made of vague passages is harder to retrieve than a page with fewer, clearer ones.
Why do semantic coherence and information density matter?
Short answer: A coherent chunk stays on one topic, so its score reflects that topic. A dense chunk packs specific facts, such as prices, names and limits, which give retrieval systems clear terms to match.
Mixed chunks dilute relevance. A passage that covers pricing, integrations and support in one paragraph matches all three questions weakly. Separate sections for each topic match each question strongly.
How do you test chunking for AI search with Python?
Short answer: Build a small corpus with known answers, split it with several strategies, run the same retrieval method on each and measure how often the chunk holding the answer ranks first. The script below does this with BM25.
The dataset is controlled. Each test question has a “gold” sentence, and a chunk counts as relevant only if it contains that whole sentence. That rule rewards strategies that keep answers intact.
#!/usr/bin/env python3
"""Compare chunking strategies on a controlled retrieval dataset.
Each query has a "gold" sentence. A chunk counts as relevant only if it holds
the whole gold sentence, so a strategy that splits the answer is penalized.
Usage: python chunking_experiment.py corpus.md queries.json
queries.json: [{"q": "is there a free trial", "gold": "Both plans include a 14-day free trial"}, ...]
"""
import json
import math
import re
import sys
from collections import Counter
STOP = set("a an and are as at be by can do does for from has have how i in is it of on or "
"the to what when where which with".split())
def tokens(text):
return [t for t in re.findall(r"[a-z0-9]+", text.lower()) if t not in STOP]
def sentences(text):
return [s.strip() for s in re.split(r"(?<=[.!?])\s+", text) if s.strip()]
def body_text(md):
return " ".join(line for line in md.splitlines() if line.strip() and not line.startswith("#"))
# ---------- chunking strategies ----------
def fixed_size(md, size=40, overlap=0):
words = body_text(md).split()
step = size - overlap
return [" ".join(words[i:i + size]) for i in range(0, len(words), step) if words[i:i + size]]
def sentence_window(md, n=2):
sents = sentences(body_text(md))
return [" ".join(sents[i:i + n]) for i in range(0, len(sents), n)]
def by_heading(md):
# Semantic chunking: one chunk per section, with the heading kept as context.
chunks, heading, buf = [], "", []
for line in md.splitlines():
if line.startswith("## "):
if buf:
chunks.append(f"{heading}. " + " ".join(buf))
heading, buf = line[3:].strip(), []
elif line.strip() and not line.startswith("# "):
buf.append(line.strip())
if buf:
chunks.append(f"{heading}. " + " ".join(buf))
return chunks
STRATEGIES = {
"Fixed 40 words": lambda md: fixed_size(md, 40, 0),
"Fixed 40 + 10 overlap": lambda md: fixed_size(md, 40, 10),
"2-sentence windows": lambda md: sentence_window(md, 2),
"Heading sections": by_heading,
}
# ---------- BM25 retrieval ----------
def bm25_rank(chunks, query, k1=1.5, b=0.75):
docs = [tokens(c) for c in chunks]
avgdl = sum(len(d) for d in docs) / len(docs)
df = Counter(t for d in docs for t in set(d))
n = len(docs)
scores = []
for i, d in enumerate(docs):
tf = Counter(d)
s = 0.0
for t in tokens(query):
if t not in tf:
continue
idf = math.log(1 + (n - df[t] + 0.5) / (df[t] + 0.5))
s += idf * tf[t] * (k1 + 1) / (tf[t] + k1 * (1 - b + b * len(d) / avgdl))
scores.append((s, i))
return [i for s, i in sorted(scores, reverse=True)]
def evaluate(chunks, queries, k=3):
hit1 = hitk = rr = 0.0
for item in queries:
ranking = bm25_rank(chunks, item["q"])
relevant = {i for i, c in enumerate(chunks) if item["gold"].lower() in c.lower()}
ranks = [pos + 1 for pos, i in enumerate(ranking) if i in relevant]
first = ranks[0] if ranks else None
hit1 += first == 1
hitk += bool(first and first <= k)
rr += 1 / first if first else 0
n = len(queries)
return hit1 / n, hitk / n, rr / n
def main(corpus_path, queries_path):
md = open(corpus_path, encoding="utf-8").read()
queries = json.load(open(queries_path, encoding="utf-8"))
print(f"{'Strategy':<24}{'Chunks':>7}{'Avg words':>10}{'Hit@1':>7}{'Hit@3':>7}{'MRR':>7}{'Answer intact':>15}")
for name, fn in STRATEGIES.items():
chunks = fn(md)
intact = sum(any(q["gold"].lower() in c.lower() for c in chunks) for q in queries)
avg = sum(len(c.split()) for c in chunks) / len(chunks)
h1, h3, mrr = evaluate(chunks, queries)
print(f"{name:<24}{len(chunks):>7}{avg:>10.0f}{h1:>7.0%}{h3:>7.0%}{mrr:>7.2f}{intact:>10}/{len(queries)}")
if __name__ == "__main__":
main(sys.argv[1], sys.argv[2])
Run it with a Markdown file and a JSON list of questions. Our test used a 380-word product guide with seven sections and ten questions.
How do retrieval results compare across content structures?
Short answer: In our test, heading-based chunks performed best, with the highest MRR and every answer kept intact. Fixed-size chunks with overlap performed worst, because overlap created extra near-duplicate chunks that competed with each other.
Strategy Chunks Avg words Hit@1 Hit@3 MRR Answer intact
Fixed 40 words 9 39 80% 90% 0.85 9/10
Fixed 40 + 10 overlap 12 38 60% 70% 0.70 9/10
2-sentence windows 15 23 60% 100% 0.77 10/10
Heading sections 7 52 80% 100% 0.88 10/10
Three points stand out:
- Heading sections kept all ten answers intact and reached an MRR of 0.88. The heading text added useful terms to each chunk.
- Fixed 40 words split one answer across two chunks, so that question could never be answered from one passage.
- Overlap did not help here. It added near-duplicate chunks that pushed the best match down the ranking.
Treat these numbers as an illustration, not a benchmark. The dataset is small, and results change with corpus, query set and retrieval method. Run the script on your own content before drawing conclusions.
What are the limits of applying RAG experiments to commercial answer engines?
Short answer: Commercial answer engines use their own chunking, embedding models, rerankers and trust signals, and they do not publish them. A local experiment shows principles, not how ChatGPT or Google will treat your page.
The lessons that transfer are general. Clear sections with descriptive headings keep answers intact under most chunking methods. Specific terms help matching. Self-contained passages survive being separated from the page. These habits make chunking for AI search work in your favor, whatever splitter a system uses.
Frequently asked questions about chunking for AI search
Can I control how AI search engines chunk my pages?
No. You can only shape your content so that common chunking methods keep each answer intact, mainly through short, well-headed sections.
What chunk size should I write for?
There is no universal number. Sections of roughly 100 to 300 words, each answering one question, work well with most chunking approaches.
Is semantic chunking always better than fixed-size chunking?
Not always. It depends on the content and the retrieval method. In our controlled test, heading-based chunks performed best, but you should test with your own data.
Does chunking for AI search replace SEO?
No. Pages still need to be crawlable, indexed and trusted. Chunk-friendly writing helps once a page is already in the index.
Should every section start with a direct answer?
Yes, where possible. A direct first sentence makes the chunk useful on its own and gives retrieval systems clear terms to match.
Next step
Save one of your longest guides as Markdown, write ten buyer questions with their answer sentences and run the script. If heading sections lose answers, split or rewrite those sections.
Want more practical guides on chunking for AI search? Browse the latest articles on the Blippu blog.