SPLIT_TEXT_MARKDOWN_HEADER

functionsupportedAI & ML

docs.snowflake.com ↗

String & binary functions

The SPLIT_TEXT_MARKDOWN_HEADER function splits a Markdown-formatted document into structured text chunks based on header levels. The function returns an array of objects, where each object contains the text chunk and the associated headers under which that chunk falls. This function is useful for preserving document structure when chunking content for embedding, retrieval-augmented generation (RAG), or search indexing. The function first segments the input text using the specified Markdown headers, and then recursively splits each segment using default plain text separators (e.g., [“nn”, “n”, “ “, “”]) to produce chunks of the desired size.

Syntax

supportedpartialnot supportednot scored

SNOWFLAKE.CORTEX.SPLIT_TEXT_MARKDOWN_HEADER (
  '<text_to_split>',
  '<headers_to_split_on>',
  <chunk_size>,
  [ <overlap> ]
)

Parameters

NameRequiredDescription
'text_to_split'requiredA Markdown-formatted string to be split.
'headers_to_split_on'requiredA key-value map in which the keys are Markdown header syntax (e.g., #, ##) and the values are metadata field names (e.g., header_1, header_2) to label the chunks. For example:Copy code { "#": "header_1", "##": "header_2" } This configuration will split the document on # and ## headers. In the output, header_1 and header_2 fields will contain the corresponding header text values.
chunk_sizerequiredAn integer specifying the maximum number of characters in each chunk. The value must be greater than zero.
overlapoptionalAn integer specifying the number of characters to overlap between consecutive chunks. Defaults to 0 if not provided. Overlap is useful for maintaining context across chunks, which can improve performance in embedding and retrieval tasks.

Returns

Returns an array of objects. Each object has the following structure: - chunk: A string containing the extracted text. - headers: A dictionary containing the Markdown header values under which the chunk is nested. Keys match those provided in the headers_to_split_on map.