BuildMidData / MLAuto-graded
Chunk a document into overlapping retrieval passages
Split a document into overlapping chunks under a size cap, cutting at word boundaries and keeping the end of the text.chunk(text, max_chars, overlap) splits a document into pieces for a retrieval index. Each chunk must fit in max_chars, share about overlap characters with the one before it, and end on a word, sentence or paragraph break where it can. Together the chunks must cover the whole document. The current version gets this wrong. Fix it, including for short documents and for an overlap as big as the chunk size.30 min
Python
Goals
- A document shorter than the chunk size comes back as a single chunk with all of its text.
- An overlap as large as the chunk size, or larger, doesn't make the function loop forever.
- Consecutive chunks share about
overlapcharacters, so text that falls on a cut still appears whole in one chunk. - Every character of the document appears in at least one chunk.
- No chunk starts or ends in the middle of a word, unless a single word is longer than the chunk size.
What it measures
RAG and retrieval systemsKnowing why chunks overlap and what a badly placed cut costs at search time.
Data integration and ETLWriting an ingestion step that holds up on different documents and settings.
Edge casesHandling a short document and an oversized overlap without hanging or losing text.
Your environment
Terminal + editorA full shell in the browser
Coding agentAlready signed in, no API key to set up
Isolated workspaceOnly yours, wiped when you finish
Start this lab
30 min
Start labYou'll need to sign in to Anthropos first. The lab opens in a private cloud workspace with your coding agent ready to use.AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo