When a retrieval system gives bad answers, the instinct is to blame the model or the database. It is usually neither. It is that the document was cut into pieces badly, and no component downstream can recover information that was destroyed at the splitting step.
Chunking is the least glamorous part of building a RAG system and the one with the largest effect on answer quality. This post goes through the strategies in the order teams usually try them, and what each one breaks.
If you are still deciding whether retrieval is the right approach at all, fine-tuning or RAG comes first.
Why the split matters more than the store
Retrieval returns chunks. The model only sees what retrieval returned. So a chunk is the unit of knowledge in your system, and the question for every strategy is the same: does this piece make sense on its own?
Two failures bracket the problem. Chunks that are too small retrieve precisely and arrive without enough context to answer anything. Chunks that are too large match too many queries weakly, and bury the relevant sentence among three paragraphs of unrelated material where the model may not weight it properly.
Neither failure announces itself. Both look like the model being unreliable.
Fixed-size chunking
Split every document into pieces of a set length, usually with some overlap between consecutive pieces. It is two lines of code and it is where everybody starts.
It is also genuinely fine for a corpus of uniform prose. If you are indexing blog posts of similar length and structure, fixed-size splitting with modest overlap will get you a working system quickly, and you should not feel bad about it.
What it breaks: anything with structure. A table cut in half produces two chunks of meaningless numbers. A numbered procedure split at step four produces a chunk that begins mid-instruction. A sentence cut in the middle produces an embedding of half an idea. Overlap reduces how often this bites, at the cost of storing the same text several times and retrieving near-duplicates.
Recursive splitting
The sensible default. Instead of cutting blindly at a character count, try to split on paragraph breaks first, then on sentence boundaries, then on words, only cutting mid-sentence when nothing else fits the size limit.
This is strictly better than fixed-size for almost no extra cost, and if you are doing naive splitting today this is the cheapest upgrade available. It still has no idea what your document is about, but it stops producing chunks that begin mid-word.
Structural chunking, which most teams should try first
If your documents have headings, use them. Split on the heading hierarchy and keep each section as a chunk, splitting further only when a section is too long.
The important refinement is to carry the heading path into the chunk text. A chunk that begins with the document title and the heading trail it came from is dramatically more retrievable than the same paragraph alone, because the paragraph often does not repeat the subject it is about. A section under Returns and Refunds, then Damaged Items, may never use the word refund in its body, and without the heading path it will not match a question about refunds.
This is one of the highest-return changes we make to existing systems, and it costs almost nothing. It also means the way your content is structured directly determines how well it retrieves, which is the same argument we made for public content in content modelling for SEO and AI.
Semantic chunking
Embed each sentence, measure similarity between consecutive sentences, and split where the similarity drops sharply on the assumption that a drop marks a topic change.
It is appealing and it is sometimes worth it, particularly for long unstructured documents with no headings to work from. Transcripts, scanned reports, policy documents written as continuous prose.
Be clear about the cost. You are embedding every sentence before you can split, which makes ingestion considerably more expensive, and the threshold for what counts as a topic change is a parameter you now have to tune. In our experience the gain over structural chunking is small when the document has usable structure, and real when it does not. Reach for it as a targeted fix, not a default.
Hierarchical chunking, or small to retrieve, large to answer
This is the strategy that most often fixes a system that feels nearly right.
Index small, precise chunks so that matching is accurate. But when a small chunk is retrieved, return its parent section to the model rather than the chunk itself. You get the precision of small units and the context of large ones, which is the trade-off every other strategy is forced to make.
A variation worth knowing: generate a short summary of each section, embed and index the summaries, and return the full section on a hit. This works well for documents where the useful text is verbose and the subject is only stated at the start.
The cost is bookkeeping. You now maintain a relationship between chunks and parents, and the parent must still fit comfortably in the context you are willing to spend.
Giving every chunk its context
A technique worth applying regardless of which strategy you choose: before embedding a chunk, prepend a short line situating it. What document it came from, what section, and what the surrounding material is about.
The reason is pronouns and implicit subjects. Real documents are full of sentences like this applies only to orders placed before dispatch, where this refers to something three paragraphs earlier. Embedded alone, that sentence is almost meaningless. Embedded with a line of context, it becomes retrievable.
You can write that context line from the heading path, which is nearly free, or generate it with a language model at ingestion time, which costs more and handles unstructured documents better.
The things that need special handling
- Tables. Never split one. If a table is too large, split by rows and repeat the header row in each piece. A chunk of numbers with no column names is noise.
- Code. Split on function or class boundaries, not length. Half a function retrieves badly and reads worse.
- Lists and procedures. Keep a numbered procedure whole if you possibly can. Partial instructions are worse than no instructions, because the model will answer confidently from them.
- Short documents. A FAQ answer or a product description is already a chunk. Do not split it to hit a target size.
- Scanned PDFs. Fix extraction before you think about chunking. Most bad RAG on PDFs is an extraction problem wearing a chunking costume.
How to actually choose
You cannot choose without measuring, and this is the step teams skip.
Build an evaluation set of thirty to fifty real questions, each paired with the passage that should be retrieved. Real questions from your support inbox or sales calls, not questions you invented, because invented questions use your own vocabulary and real ones do not.
Then measure one thing first: in what proportion of cases does the correct passage appear anywhere in the retrieved set? If the right passage is not being retrieved, nothing the model does afterwards can fix the answer, and that single number tells you whether your chunking is the problem.
Change one variable at a time. Strategy, then size, then overlap. Re-run the same questions. Keep the results somewhere, because six weeks later nobody will remember why the chunk size is what it is.
What is a waste of effort
Copying a chunk size from a tutorial. It was chosen for a different corpus.
Large overlaps everywhere. Overlap is a patch for bad boundaries. Fix the boundaries and you need far less of it.
Reaching for semantic chunking before trying structural chunking with heading context. It is more expensive and usually less effective on documents that have headings.
Tuning chunking before fixing extraction. If your parser is producing run-together text and losing table structure, every strategy will perform badly and you will blame the wrong thing.
Store more than the text
A chunk is not just a string. What you store alongside it determines what you can do later, and teams routinely discover six months in that they cannot filter, cite or expire anything because they only kept the text and the vector.
Keep at least these with every chunk.
- Source document identity and a stable URL or path, so an answer can cite where it came from. Without this you cannot show the user a source, which for most business uses is the difference between a usable system and a demo.
- Position within the document, so you can reassemble neighbours or return the parent section.
- The heading path, both for retrieval and for display.
- Last modified date, so you can prefer recent material and spot stale content.
- Access scope, if different users may see different documents. Retrofitting permissions onto an index that was built without them is unpleasant.
- Document type or category, which is what your filters will eventually need.
The cost of storing these is trivial. The cost of not having them is a re-ingestion of the whole corpus at the moment you realise.
Updates and deletions are the part that rots
Most retrieval systems are built once against a snapshot and quietly decay from there, because nobody designed for documents changing.
Decide your update strategy before launch. When a source document changes, the simplest correct approach is to delete every chunk belonging to that document and re-chunk it from scratch. Attempting to update individual chunks in place sounds more efficient and goes wrong, because a text edit shifts every boundary after it.
That requires knowing which chunks belong to which document, which is why the identity field above matters.
Deletion is the one with consequences. If a document is withdrawn, a product discontinued or a policy superseded, its chunks must go. A system confidently answering from a withdrawn policy is worse than a system that says it does not know, and in regulated contexts it is a genuine liability.
Run a reconciliation job on a schedule. Compare the set of documents in your source against the set represented in your index, and report anything present in one and not the other. Orphaned chunks from deleted documents are the most common silent fault we find in systems that have been running for a year.
A sensible sequence
- Fix extraction. Confirm the text you are indexing is actually clean.
- Build the evaluation set from real questions.
- Start with recursive splitting and measure. This is your baseline.
- Move to structural chunking with the heading path prepended. Measure again. This is usually the big jump.
- Add hierarchical retrieval if answers are precise but thin on context.
- Only then consider semantic chunking, and only for the documents that lack structure.
- Add reranking before you spend more time on chunking, because it often recovers more than further tuning will.
The implementation side of this sits in building a RAG chatbot on your own content, and the storage question in hybrid search with PostgreSQL.
If your retrieval is nearly working and you cannot tell why it is not, that is usually a chunking problem and we are happy to look at it. Get in touch.