Child of the chunk-size tradeoff

Routing a mixed corpus

A single chunking strategy rarely fits a mixed corpus, so match the strategy to the document. A report, a contract, and a FAQ do not want the same chunker, and one PDF often contains more than one of them.

Element first, genre secondLLM only for the ambiguous remainder

The practical problem One corpus, many shapes

Sentence-window and auto-merging are choices for a shape of text. A production corpus is a pile of shapes.

The parent page picks one pattern for a question that lives in one kind of document. The corpus you actually index is contracts, manuals, FAQs, tickets, and reports, and a single PDF mixes prose, tables, and headings. Label the whole file “report” and the table inside it still gets sentence-windowed: rows split away from their headers, and context relevance falls for a reason the prose pattern cannot see.

Architect's lens

The genre tells you what the document is for. The element tells you how to cut it. Those are two labels, and only the second one chooses the chunker.

The pipeline Cheap checks first

Deterministic signals run on every file. The model runs on the remainder, and on a sample of the file.

1. Extension2. Typed elementstext, table, heading, code3. HeuristicsLLM only if unclear4. Routeplus a fallback5. Tag and indexdocument, element, strategy6. Eval per routeagainst one baselinere-check the routes when the document mix changes
The order is the cost order. Parsing and heuristics are free relative to a classification call on every page.

Route each element After the parse

Keep paragraphs, tables, headings, and code blocks separate. The chunker follows the element, not the filename.

Document genre

  • Contract, manual, FAQ, report, ticket.
  • Comes from extension, heuristics, and, when those disagree, an LLM.
  • Useful for metadata, filters, and which section of the menu you expect to win.

Element type

  • Paragraph, table, heading, code block.
  • Comes from the parser, on every file, before any model call.
  • This is the label that selects the chunker.

A quarterly report can be genre “report” and still contain a prose finding, a results table, and a heading hierarchy. The prose finding can take a sentence window. The table keeps its header with its rows. The headings stay attached to the sections they name. One document-level label cannot make those three cuts.

Cheap signals first Then the model

An LLM call on every page, across thousands of documents, is a latency and cost decision. Spend it on the files the cheaper signals cannot place.

OrderSignalWhat it decidesWhat it costs
1Extension and parser outputA .csv is a table. A parser that already emitted a code block does not need a model to notice the code.Deterministic. No model call.
2HeuristicsPage count, heading density, table ratio, average paragraph length. A high heading density with numbered procedures is a manual. A file of short question-answer pairs is an FAQ.Still deterministic. Tune the thresholds on a labeled sample.
3LLM classificationThe genre, only when extension and heuristics disagree or sit near a threshold.One call on a sample of the file: the first page plus a few random pages, not the whole document.

The sample is enough to name the genre. The parser has already walked the whole file for element types, so the model is not being asked to re-read every table.

The fallback Misclassification will happen

Low confidence takes the general chunker, and the case is logged so the heuristic can be corrected.

Default when the route is unsure

Fixed-size chunks with overlap. It is the same baseline theevaluation loop already scores, so a timid router degrades to a system you have already measured. Log the document id, the signals that were close, and the strategy you refused, and review that log when you retune thresholds.

A confident wrong route is more expensive than a fallback. Sentence-windowing a table, or auto-merging a FAQ into its neighbors, spends the clever chunker on the wrong shape.

Metadata on every chunk The routing decision

Three fields, written at index time, so a later query and a later eval can both see which route produced the hit.

FieldExampleWhat you use it for
Document typecontract, manual, faq, reportFilter at query time when the question names a genre. Slice eval scores by genre.
Element typeparagraph, table, heading, codeSee whether a bad answer came from the table route inside an otherwise healthy report.
Chunking strategysentence-window, auto-merge, table, fixed-sizeThe route you are judging. This is the column the per-route triad groups on.

Without those fields, a drop in context relevance is a corpus-wide number. With them, the drop can be “table rows in reports,” which is a routing bug, or “sentence-window on manuals,” which is the chunk-size tradeoff you already know how to read.

Evaluate the router Separate from the triad

The triad tells you whether retrieval and the answer worked. It does not tell you whether the document was sent to the right chunker.

Routing accuracy

  • Label a sample of documents, and of elements inside them.
  • Score the router: did this element get the strategy you would have chosen by hand?
  • Read the low-confidence log first. That is where the thresholds are wrong.

Per-route triad

  • Break context relevance, groundedness, and answer relevance down by strategy.
  • Compare each route, and the routed system as a whole, with a single-strategy baseline on the same questions.
  • Keep the router when that comparison moves the failing leg. Otherwise the router is complexity without benefit.

This is the same refusal as the evaluation loop. A more complex retriever has to beat the baseline inside the latency and token budget. A router is that retriever: it adds a classification path, more than one index shape, and a metadata filter. If the single fixed-size baseline already clears the bar, ship the baseline and keep the labeled sample for the day the document mix changes.

What you must be able to do

  • Separate document genre from element type, and say which one selects the chunker.
  • Put extension and parser output ahead of heuristics, and heuristics ahead of an LLM call on a sample of the file.
  • Name the extra strategies a prose menu is missing: table, structure with the heading attached, code, and whole-item records.
  • Fall back to fixed-size with overlap, store the route on the chunk, and drop the router if it does not beat one strategy on the triad.

Key takeaways

  • Match the chunker to the element. A document-level genre label leaves the table on the prose path.
  • Call the LLM only for the ambiguous remainder, on a sample of the file. Extension, parser output, and heuristics go first.
  • Fixed-size with overlap is the fallback. Metadata makes the triad readable per route, and the router stays only when that split beats a single strategy.