Retrieval and Boundaries for Agent Runs
Lesson 2 of 4
Chunk Size Decides What Can Be Found
Estimated time: 10 minutes
Chunk Size Decides What Can Be Found
How a document is split decides what a retriever can ever return. A chunk that is too large buries the answer in nearby text; a chunk that is too small splits the answer and the halves may never be retrieved together.
Size from the shape of the documents
Test a few sizes against real questions and keep the one that retrieves the answers, rather than copying a constant from elsewhere.
def windows(text, size, overlap):
step = max(1, size - overlap)
return [text[i:i + size] for i in range(0, len(text), step)]
Overlap and cite
A small overlap keeps a sentence that spans a boundary whole in at least one chunk, and a source pointer on every chunk lets a hit be cited back.