Text Chunking

Updated at:

The text chunking operator splits long text into smaller, semantically or structurally complete segments based on specified rules. This topic describes how to configure this operator.

Prerequisites

  • To use the workflow feature, you must first purchase the unstructured data feature for your instance.

  • You have created a workflow. For detailed instructions, see Create and manage workflows.

Permissions

In a Basic project, project administrators, developers, analysts, and custom project roles with the Dataset-Use permission can use any dataset in the project as the operator's input or output.

Supported file formats

The text chunking operator supports files in the following formats: md, txt, html, csv, and json.

Procedure

  1. In the top navigation bar of the Dataphin homepage, choose Development > Data Development.

  2. On the Development page, select a Project from the top navigation bar.

  3. In the left-side navigation pane, choose Data Processing > Workflows. In the Workflows list, click your target workflow to open the canvas. From the Operator Library on the left, drag the Text Chunking operator to the canvas. In the Text Chunking panel on the right, configure the following parameters.

    Parameter

    Description

    Step name

    The name of the operator step. It can contain up to 256 characters.

    Input configuration

    Dataset

    Select the dataset to process. You can choose a hybrid dataset or a table dataset. After selecting a dataset, you must also select its version. The earliest version is selected by default.

    When this operator is downstream from another, this dataset is typically the output of the upstream operator.

    Input field

    The field containing the storage URL of the source text. The operator supports reading files in md, txt, html, csv, and json formats. You must select a source field from the input dataset. You can only select fields for which the Is URL parameter is set to Yes.

    Filter condition (Optional)

    Enter only the condition that follows the WHERE clause. System global variables, such as the business date ${bizdate}, are supported.

    Operator parameter configuration

    Splitting mode

    Select Split by text structure or Split by fixed length. The default mode is Split by text structure. If you select this mode, you must also specify the Text Type, which can be Plain Text, Markdown, or HTML.

    • Split by text structure: If the text to be processed is plain text, it is split in the order of paragraphs > line breaks > sentences. If the text is in Markdown or HTML format, it is split based on document-specific structures, such as headings in a Markdown document or tags in an HTML document.

    • Split by fixed length: Splits the text into chunks of a specified character length.

    Chunk size

    The target length of each text chunk. The default is 1024 characters.

    Chunk overlap

    The maximum allowed overlap between adjacent text chunks. This value cannot exceed the chunk size. The default is 128 characters.

    Output configuration

    Dataset

    Select a hybrid dataset or a table dataset and its version as the output dataset. The earliest version is selected by default. You can also select other versions of the output dataset.

    Load policy

    The default load policy is update upon primary key conflict if the output dataset has a primary key. Otherwise, the default is append data.

    • Append data: Appends new data to the target table. This action fails if a primary key or constraint conflict occurs.

    • Update upon primary key conflict: If a new row's primary key conflicts with an existing row, the operator deletes the existing row before inserting the new one.

    • Overwrite: Deletes all existing data from the target table before writing the new data.

    Field mapping

    The text chunking operator always outputs the following fields:

    • source_file_url: The storage URL of the original text.

    • chunk_sequence: The sequence number of the chunk.

    • chunk_content: The content of the text chunk.

    • chunk_id: The unique ID of the chunk, used for unique identification by downstream operators.

    In real-time and online workflows, the text chunking operator produces multiple output chunks from a single input event (a 1:N pattern). These chunks are returned in a chunks array. This array can be used as the iteration source for a ForEach loop operator to process each chunk individually. The default iteration variable for the loop is chunk.

    By default, output fields are mapped to same-named fields in the output dataset. You can also manually create custom mappings or map pass-through fields from the source dataset. Manage field mappings with the following options:

    • Add Output Field: Adds a new, empty field mapping row.

    • Batch Mapping: Provides options to map fields in batches by name or by row.

    • Delete Mapping: Click the Delete icon to remove the corresponding field mapping row. Mappings for the operator's default output fields cannot be deleted.

  4. After configuring the operator, click Save in the canvas's top menu bar.

    After configuring an operator, you can continue to build the complete workflow by connecting it to upstream or downstream operators.