Document Chunking
A retrieval system cannot hand a model a 400-page manual, and it should not want to. Document chunking is the decision about what unit of text gets stored, retrieved and pasted into the prompt — and that quiet decision sets the ceiling on how good the whole system can be.
Why size is the whole trade-offA short chunk embeds precisely: its vector represents one idea, so it matches a narrow question well. It also arrives stripped of its surroundings, which is how an assistant ends up answering from a sentence that began "this exemption does not apply when…" with the condition left behind on the previous chunk. A long chunk keeps that context but its embedding averages several topics, so it matches many questions weakly and consumes context window that the answer needed. Most production systems land between 200 and 800 tokens with a modest overlap.
How it is actually done- Fixed windows with overlap: cheap baseline, splits mid-sentence, repeats text at the seams to soften the damage.
- Structure-aware splitting: on headings, Markdown sections, or function boundaries in code, so each chunk is a unit the author already intended.
- Semantic splitting: cut where consecutive sentence embeddings diverge, letting the topic change choose the boundary.
- Parent-document retrieval: match on the small chunk, then feed the larger section it came from.
Bad chunking fails silently. Retrieval still returns something, the model still answers, and the error surfaces as an isolated wrong fact rather than an empty result. Changing the scheme means re-embedding and re-indexing the entire corpus, so chunking is settled before the first build. LangChain's text splitters and LlamaIndex's node parsers are where most teams make the choice concrete.
Document chunking splits source documents into passages small enough to embed, retrieve and fit into a prompt. Size is the trade-off: short chunks retrieve precisely but lose the surrounding qualifiers, long ones keep context while blurring the embedding and crowding the context window. Splitting on structure — headings, sections, functions — beats splitting on character count. Because changing the scheme forces a full re-embedding of the corpus, it is the retrieval decision hardest to reverse.
Think of cutting a thick reference book into index cards so you can find one fact fast. Cut too finely and a card reads "this is not recommended" without saying what "this" was. Cut too coarsely and every card covers five topics at once, so searching finds everything and nothing. Document chunking is choosing where to make those cuts, before an AI assistant is allowed to search your documents. Good cuts follow the document's own shape — a section, a heading, a single recipe — so each card still makes sense on its own. Most wrong answers from a document assistant start with a bad cut, not a bad assistant.