splitText
Split text into chunks using a recursive character splitting strategy. The splitter tries separators in order, splits on the first one found, merges small pieces back up tochunkSize, maintains chunkOverlap between consecutive chunks, and recurses with finer separators for pieces still too large.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
content | string | string[] | yes | Text or array of texts to split | |
chunkSize | number | yes | Maximum size of each chunk (in characters) | |
chunkOverlap | number | yes | Number of overlapping characters between consecutive chunks | |
separators | string[] | no | ["\n\n", "\n", " ", ""] | Ordered list of separators to try, from coarsest to finest |
keepSeparator | boolean | "start" | "end" | no | false | Attach the separator to the chunk. true or "end" appends it to the preceding chunk, "start" prepends it to the following chunk. Only visible with non-whitespace separators (whitespace is trimmed). |
{ content, size } objects: