GeneralChunker Delimiter Semantics#
GeneralChunker is RAGFlow's built-in chunking component for the general/naive pipeline. It accepts two delimiter lists โ delimiters (primary) and children_delimiters โ each of which can carry two distinct kinds of entries with fundamentally different runtime effects:
| Entry form | Example | Semantics |
|---|---|---|
| Bare (no backticks) | "\n", "::", "ใ" | Merge-hint โ splits the text at that character sequence so adjacent pieces can be merged up to the token budget (chunk_token_size) |
| Backtick-wrapped | "::`` | Hard-split โ splits the text and bypasses the token-size merge; each segment becomes its own chunk (delimiter is dropped) |
This distinction is enforced throughout the ingestion stack, from legacy string parsing to the compiled regex patterns used during chunking.
Delimiter Normalization#
The delimiters field accepts three wire formats: a legacy Python single-string, a []string, or a []any . Legacy strings are decoded by ParseDelimiterField in internal/parser/chunk/delim.go:
- Characters outside backticks become individual Unicode delimiter entries.
- A backtick-wrapped token (e.g.
\n\n) is kept as a single multi-character entry, including its surrounding backticks.
This means "\n\n\n" decodes to two entries: "\n" (bare) and "\n\n" (wrapped).
At startup, normalizeGeneralDelimiterValue calls splitGeneralDelimiterString โ chunk.ParseDelimiterField for string values and passes lists through unchanged. Both delimiters and the legacy alias delimiter are handled .
Pattern Compilation: compileDelimPattern#
After normalization, compileDelimPattern delegates to chunk.CompileDelimiterPatternList(delims, keepBare=true). The semantics for keepBare=true are:
- Backtick-wrapped entries: the inner content (backticks stripped) enters the active regex alternation โ these are hard-split triggers.
- Bare entries: also enter the regex when
keepBare=true(which is always the case for the primary delimiter pattern) โ these split the text into segments for downstream merging.
The resulting regex is sorted longest-first by rune count so a longer delimiter always wins over a shorter prefix within it .
HasCustomDelimiterList (called via hasCustomDelim) checks whether any entry uses backtick syntax. This boolean drives branching in the DOCX merge path.
How Bare vs. Hard-Split Diverge During DOCX Chunking#
The DOCX path in chunkDOCX applies delimiters as follows:
splitGeneralUnitsโ splits each parser unit's text wherever the compiled primary pattern matches, producing smaller pieces .mergeDOCXUnitsโ receives the pieces plus thehasCustomDelimflag . InmergeDOCXUnits:- If
customDelimiteris true (backtick-wrapped entry present): each new text unit starts a fresh chunk โ no token-size merge occurs . - If
customDelimiteris false (only bare delimiters, or no delimiters): pieces are merged into the previous text chunk as long asmerged[previousText].TKNums < target.
- If
Media units (tables, images) are always emitted as standalone chunks regardless of the delimiter mode .
children_delimiters#
children_delimiters is compiled by compileChildrenPattern, also with keepBare=true, so every non-empty entry โ bare or wrapped โ produces active splits for child-chunk generation. splitGeneralChildren applies the compiled children pattern after the primary merge phase; the matched delimiter is attached to the preceding child (not dropped), matching the legacy Python behavior.
Config Migration#
Stored parser_config rows use the component key GeneralChunker:SixApplesFall. On startup, migrateGeneralChunkerConfig rewrites any legacy TokenChunker:SixApplesFall entry and normalizes the old flat delimiter key into the canonical delimiters list via normalizeLegacyDelimiter โ ParseDelimiterField . The UI normalizer normalizeParserConfig drops all flat parser-level keys and re-homes chunk_token_num onto GeneralChunker:SixApplesFall.chunk_token_size.
Key Files#
| File | Role |
|---|---|
internal/ingestion/component/chunker/general.go | GeneralChunkerComponent, mergeDOCXUnits, normalizeGeneralDelimiterValue |
internal/parser/chunk/delim.go | ParseDelimiterField, CompileDelimiterPatternList, HasCustomDelimiterList |
internal/ingestion/component/chunker/common.go | compileDelimPattern, splitByDelim |
internal/dao/parser_config_migration.go | migrateGeneralChunkerConfig, normalizeLegacyDelimiter |
web/src/hooks/parser-config-utils.ts | normalizeParserConfig (frontend config normalization) |
internal/ingestion/component/chunker/bare_delimiter_test.go | Behavioral tests locking bare vs. backtick-wrapped contract |