SPLIT_TEXT_RECURSIVE_CHARACTER

functionsupportedAI & ML

docs.snowflake.com ↗

String & binary functions

The SPLIT_TEXT_RECURSIVE_CHARACTER function splits a string into shorter stings, recursively, for preprocessing text to be used with text embedding or search indexing functions. The function returns an array of text chunks, where the chunks are derived from the original text based on the input parameters provided. The splitting algorithm attempts to split text on separators in the order they are provided, either implicitly as defaults based on the format, or explicitly in the separators argument. Splitting is then applied to each chunk that is longer than the specified chunk_size, recursively, until all chunks no longer than the specified chunk_size. For example, if format is set to 'none', the algorithm first splits on the “\n\n” sequences, which represent paragraph breaks in most formats. Within any resulting chunk that is still longer than chunk_size characters, the function splits on the “\n” characters, which represents line breaks. This process repeats until each of the chunks is less than chunk_size characters.

Syntax

supportedpartialnot supportednot scored

SNOWFLAKE.CORTEX.SPLIT_TEXT_RECURSIVE_CHARACTER (
  '<text_to_split>',
  '<format>',
  <chunk_size>,
  [ <overlap> ],
  [ <separators> ]
)

Parameters

NameRequiredDescription
'text_to_split'requiredThe text to split.
'format'requiredThe format of your input text, which determines the default separators in the splitting algorithm. Must be one of the following: none: No format-specific separators. Only the separators in the separators field are used for splitting. markdown: Separates on headers, code blocks, and tables, in addition to any separators in the separators field.
chunk_sizerequiredAn integer specifying the maximum number of characters in each chunk. The value must be greater than zero.
overlapoptionalAn integer that specifies the number of characters to overlap between consecutive chunks. By default, chunks have no overlap. If overlap is specified, it must be smaller than the chunk_size argument. Overlap is useful for ensuring that each chunk has some context about the previous chunk. This can help improve the quality of search results or other processing.
separatorsoptionalAn ordered list of character sequences to use as boundaries when determining where to split the text, in addition to any separators dictated by the format parameter. The last item in this list should be a general separator, such as an empty string (which allows a split to be made between any two characters), so that the algorithm is guaranteed to be able to split the text into chunks of the desired size. Default: [“\n\n”, “\n”, “ “, “”], meaning a paragraph break, a line break, a space, and between any two characters (the empty string).

Returns

Returns an array of strings that contains text chunks extracted from the input string.