Practice: Chunk the Help Centre
All fourteen files.
Let's put it together, and chunk the whole help centre. We'll split by headings first, so every chunk knows its title and section, then split long sections by size.

- All fourteen pages
- Headings first
- Then by size
The full chunking step
For each page, the header splitter makes sections, with title and section metadata. We add the source file. Then the recursive splitter breaks any long section into pieces under three hundred characters. Run it. We get a few dozen chunks, and each one knows its file, title, and section.
from pathlib import Path
from langchain_text_splitters import MarkdownHeaderTextSplitter, RecursiveCharacterTextSplitter
by_heading = MarkdownHeaderTextSplitter([("#", "title"), ("##", "section")])
by_size = RecursiveCharacterTextSplitter(chunk_size=300, chunk_overlap=30)
chunks = []
for path in sorted(Path("data/rag/northwind").glob("*.md")):
sections = by_heading.split_text(path.read_text())
for s in sections:
s.metadata["source"] = path.name
chunks += by_size.split_documents(sections)
print(len(chunks), "chunks")
print(chunks[5].metadata)
print(chunks[5].page_content)35 chunks
{'title': 'E-bike display error codes', 'source': 'ebike_errors.md'}
E03: the speed sensor is not reading. Check the magnet on the rear wheel is lined up
with the sensor.
E05: the motor is overheating. Stop riding for 15 minutes, then continue in a lower
assist mode.What we have now
We now have a clean set of chunks, each small, complete, and labelled. This is the input to the next section, where we turn every chunk into an embedding, so we can search by meaning.
| key | value |
|---|---|
| Chunks | a few dozen |
| Each | one idea |
| Labels | file, title, section |
| Next | embeddings |
Summary
We chunked the whole help centre, by headings, then by size, with full metadata. Next, the chunking quiz.
Key takeaways- Headings first
- Then size
- Metadata everywhere