Skip to main content

Chunk Node

Overview

The Chunk node is used to split a string into an array of strings based on a token count.

Chunking a string is useful to avoid hitting token count limited in LLMs. You can split a string into multiple chunks and then feed each chunk into a separate Chat node, then combine the outputs of the chat nodes back together to effectively answer questions about strings of text longer than the LLM can handle.

The Chunk node can also be used to truncate a string to a certain token count, from the beginning or the end, by using the first or last outputs.

If an overlap percentage is specified, then the chunks will overlap by the specified percentage (relative to the max token count). For example, if the max token count is 100 and the overlap is 50%, then the chunks will overlap by 50 tokens. This can be useful so that context is not lost between chunks, but it may result in more total chunks.

Chunk Node Screenshot

Inputs

TitleData TypeDescriptionDefault ValueNotes
InputstringThe string that should be chunked.(Required)None

Example 1: Chunk a string into multiple chunks

  1. Create a text node with some long data, such as lorem ipsum.
  2. Create a Chunk node and connect the text node to the input. Set the max tokens to something small like 100.
  3. Run the graph. Note how the output of the chunk node has split the text (visually as new lines) into multiple chunks.

Error Handling

The chunk node has no notable error handling behavior. If the input is not a string, then it will be coerced into a string.

FAQ

See Also