Chunking Decides What Is Findable
An embedding model reads a limited amount of text. Anything past that limit is not ranked lower. It is not in the embedding at all, so no query can find it, however good the rest of the pipeline is.
Nothing reports this, so it is easy to miss. In one 65,000-message mail archive, PDF attachment text was appended to each message body and the first 3,000 characters were embedded. That left 14 million characters of extracted text outside every embedding. The text had been parsed correctly, but search could not find it.
Four Strategies
| Strategy | Where a chunk ends | Best for |
|---|---|---|
Auto |
Chosen from what the document contains | The default when you do not want to choose |
FixedSize |
At a token limit, with an overlap you set | Plain prose with no headings |
ByStructure |
A new chunk at each heading | Contracts, reports, specs: anything with headings |
BySection |
One chunk per slide, sheet, or attachment | PPTX, XLSX, and emails with attachments |
Auto looks at what the document contains, not at its file extension. Spreadsheets and slide decks use BySection, documents with headings use ByStructure, and everything else uses FixedSize.
Why there is no BySimilarity
There is no semantic (embedding-based) chunking. It would need an AI call for every document, and that costs money. Chunking here is free and repeatable: the same input gives the same chunks, with no API key and no charge per document.
What It Guarantees
Blocks Are Never Split
A paragraph or a table is never cut in two. A table stays whole even when it is larger than the token limit, because half a payment schedule is misleading.
Tables Keep Their Contents
A chunk that contains a table includes the text of every cell, not a placeholder such as [table]. A chunk that covers a payment schedule contains the payment schedule.
Deterministic
No AI model is involved. The same document gives the same chunks on every run, so you can rebuild your index and compare it with the last one.
Free
Chunking adds no cost to a parse. It works on the blocks the parse already returned.
tables.docx is 61 estimated tokens with its cell contents. With only a [table] placeholder it would be 10, and would contain none of the table.Citing the Source
A retrieved passage is far less useful when the reader cannot see which clause it came from. Every chunk carries what you need to cite it:
{
"id": 3,
"text": "The Seller shall indemnify the Buyer against all claims...",
"tokenCount": 184,
"startBlockIndex": 12,
"endBlockIndex": 15,
"headingContext": "7. Indemnities",
"sectionKind": "",
"hasTable": false
}
headingContext is the nearest heading above the chunk, so a passage from a contract can be shown with its clause heading. startBlockIndex and endBlockIndex say which blocks of the parsed document the chunk covers. hasTable tells your application the chunk contains a table, so it can show it as a grid and not as running text.
Token Counts Are Estimates
Token counts are calculated as words × 1.3. No tokenizer and no model is used, which keeps chunking free and repeatable. The estimate is accurate enough to size chunks.
It is not exact. If your chunks must fit under a hard model limit, leave some headroom and do not treat tokenCount as exact.
Try It
Chunking works on a parsed document, so it works for every format AILANG Parse reads. The same call chunks a DOCX contract, a PPTX deck or an email with a PDF attachment.
import docparse/services/chunker (chunkDocument, Auto, ByStructure, Chunk)
-- Let the document decide
let chunks = chunkDocument(doc, Auto({maxTokens: 512, overlap: 64}))
-- Or pin a strategy for a known corpus
let chunks = chunkDocument(doc, ByStructure({maxTokens: 512, groupUnderHeadings: true}))
FAQ
How do I chunk documents for a RAG pipeline?
Parse the document, then call chunkDocument with one of four strategies: Auto, FixedSize, ByStructure or BySection. Chunks are built from the parsed blocks, not raw text, so they end at real boundaries such as headings. Chunking is free and needs no AI call.
Does chunking split tables in half?
No. A table stays whole even when it is larger than the token limit, because a whole table is more useful than two halves of one.
Are chunk token counts exact?
No. They are estimates, calculated as words × 1.3, with no tokenizer and no model call. Leave headroom if chunks must fit under a hard model limit.
Can I cite the source of a retrieved chunk?
Yes. Every chunk carries headingContext (the nearest heading above it), sectionKind, a start and end block index, and a hasTable flag, so a passage can be shown with the clause it came from.
Why is there no semantic (embedding-based) chunking?
It would need an AI call for every document, and that costs money. Chunking here is free, and the same input always gives the same chunks.
Format Guides
Chunking works on any parsed document. The format guides show what each parse returns: