Strategies
Paragraph
One chunk per block, with each heading kept with the block after it.
paragraph gives one chunk per block: a paragraph, a list, a table, a code block, or a block quote. Each heading is joined to the block after it.
const { chunks } = await chunkDocument( { path: "faq.md" }, { strategy: "paragraph" },);When to use it
Section titled “When to use it”Use paragraph when each paragraph is a self-contained answer, such as FAQ entries, glossaries, or release notes where each paragraph describes one change.
Don’t use it for long-form prose, where a paragraph often depends on the ones around it. Chunks of one paragraph each can then lack the context needed to match a question. structure packs related paragraphs together instead.
How it works
Section titled “How it works”- Each block becomes one chunk. A whole list or a whole table counts as one block.
- A heading is joined to the block after it, so it isn’t a chunk of its own.
- With
size, consecutive blocks in the same section are packed together up tosize, and a block larger thansizeis split along its structure. - With
minSize, a chunk smaller thanminSizeis merged into its neighbor in the same section.
Example
Section titled “Example”# Returns policy
You can return most items within 30 days of delivery. Items must be unused and in their original packaging.
## Start a return
1. Sign in and open **Orders**.2. Choose the item you want to return.3. Print the prepaid shipping label.
## Refunds
We refund the original payment method within 5 business days of receiving the item. Shipping costs are not refunded.
| Item | Refund || --- | --- || Unused item | Full price || Opened item | 80% |Each heading is joined to its paragraph or list, and the table is a chunk of its own:
import { chunkDocument } from "docchunk";
const { chunks } = await chunkDocument( { path: "returns-policy.md" }, { strategy: "paragraph" },);
for (const chunk of chunks) { console.log(chunk.text); console.log("---");}# Returns policy
You can return most items within 30 days of delivery. Items must be unused and in their original packaging.---## Start a return
1. Sign in and open **Orders**.2. Choose the item you want to return.3. Print the prepaid shipping label.---## Refunds
We refund the original payment method within 5 business days of receiving the item. Shipping costs are not refunded.---| Item | Refund || --- | --- || Unused item | Full price || Opened item | 80% |---Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
size |
number |
No limit | Maximum characters per chunk. With a size, consecutive blocks are packed together. A positive integer. |
minSize |
number |
1 |
Chunks smaller than this are merged into a neighbor in the same section, when the result fits in size. The default merges nothing. A positive integer, at most size. |
overlapChars |
number |
0 |
Characters of whole sentences each chunk repeats from the end of the previous chunk in its section. An integer from 0, less than size. |
Good to know
Section titled “Good to know”- A long list or table is one chunk. Without
size, nothing is split. A chunk of more than 8,000 characters adds aLARGE_CHUNKwarning. Setsizeto split large blocks. minSizeworks withoutsize. With no size limit, every chunk smaller thanminSizeis merged into a neighbor in the same section. Use it to join very short paragraphs, such as one-line answers, to the paragraph next to them.- With
size,paragraphbehaves likestructure, except thatminSizedefaults to 1 instead of 200.