Reference
Options
Every option of every strategy, with its type, default, and rules.
Options are the second argument of chunkDocument and chunkDocuments. Every option is optional. An option that the chosen strategy doesn’t accept throws an INVALID_OPTIONS error, and so does a value that breaks the rules below.
All sizes are in characters.
Common options
Section titled “Common options”These work with every strategy.
| Option | Type | Default | Description |
|---|---|---|---|
strategy |
string |
"structure" |
The strategy to use. One of "structure", "heading", "paragraph", "sentence", "sentence-window", "parent-child", "hierarchical", "recursive", "fixed", "fixed-overlap", "sliding-window". |
metadata |
object |
{} |
Copied onto every chunk’s metadata. Doesn’t change chunk ids. Must be an object, not an array. |
documentId |
string |
Hash of the document | Used as document.id and in every chunk id. A non-empty string. |
headingPrefix |
boolean |
false |
Adds the heading path (A > B > C and a blank line) to the start of each chunk’s text. Counts toward the size limit. |
signal |
AbortSignal |
None | Stops chunking with an ABORTED error when aborted. |
Strategy options
Section titled “Strategy options”| Strategy | Option | Type | Default | Rules |
|---|---|---|---|---|
structure |
size |
number |
1500 |
Positive integer. |
minSize |
number |
200, or size if smaller |
Positive integer, at most size. |
|
overlapChars |
number |
0 |
Integer from 0, less than size. |
|
headingLevel |
number |
3 |
Integer from 1 to 6. | |
heading |
size |
number |
No limit | Positive integer. |
headingLevel |
number |
3 |
Integer from 1 to 6. | |
paragraph |
size |
number |
No limit | Positive integer. |
minSize |
number |
1 |
Positive integer, at most size. |
|
overlapChars |
number |
0 |
Integer from 0, less than size. |
|
sentence |
size |
number |
No limit | Positive integer. |
minSize |
number |
1 |
Positive integer, at most size. |
|
overlapChars |
number |
0 |
Integer from 0, less than size. |
|
sentence-window |
windowSize |
number |
3 |
Integer from 0. |
parent-child |
parentSize |
number |
4000 |
Positive integer. |
childSize |
number |
800 |
Positive integer, less than parentSize. |
|
hierarchical |
by |
"size" or "heading" |
"size" |
One of the two values. |
levels |
number[] |
[6000, 1500, 400] |
Non-empty array of positive integers, each smaller than the one before. | |
headingLevel |
number |
3 |
Integer from 1 to 6. | |
leafSize |
number |
1500 |
Positive integer. | |
recursive |
size |
number |
1500 |
Positive integer. |
overlapChars |
number |
0 |
Integer from 0, less than size. |
|
separators |
string[] |
["\n# ", "\n## ", "\n### ", "\n#### ", "\n\n", "\n"] |
Array of non-empty strings. | |
fixed |
size |
number |
1500 |
Positive integer. |
boundary |
"word" or "char" |
"word" |
One of the two values. | |
fixed-overlap |
size |
number |
1500 |
Positive integer. |
overlapChars |
number |
200 |
Integer from 0, less than size. |
|
boundary |
"word" or "char" |
"word" |
One of the two values. | |
sliding-window |
size |
number |
1500 |
Positive integer. |
step |
number |
750 |
Positive integer, at most size. |
|
boundary |
"word" or "char" |
"word" |
One of the two values. |
Each strategy page explains what its options do.
Options that depend on each other
Section titled “Options that depend on each other”minSizeandsize.minSizecan’t be larger thansize. Forstructure, when you set asizebelow 200 and nominSize, the defaultminSizebecomes equal tosize.overlapCharsandsize.overlapCharsmust be less thansize.childSizeandparentSize.childSizemust be less thanparentSize.stepandsize.stepcan’t be larger thansize.headingPrefixand the sizes. WithheadingPrefix, each size option is reduced by the length of the longest heading path in the document, so that prefixed chunks still fit. If that leaves no room, chunking fails withINVALID_OPTIONSafter the document is read.
Batch options
Section titled “Batch options”chunkDocuments accepts every option above, plus:
| Option | Type | Default | Description |
|---|---|---|---|
concurrency |
number |
4 |
Documents chunked at the same time. A positive integer. |