Skip to content

refactor(parser): align TextParser with Python _code delimiter split - #18099

Closed
xugangqiang wants to merge 2 commits into
fix/parser-align-foundationfrom
fix/textcode-parser-align
Closed

xugangqiang wants to merge 2 commits into
fix/parser-align-foundationfrom
fix/textcode-parser-align

Conversation

@xugangqiang

@xugangqiang xugangqiang commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Make Go TextParser match Python deepdoc TxtParser._code:

  • Split on the flow default delimiter set \n!?;。;!? (was blank-line only).
  • keep_delimiters=True: each trailing delimiter is retained on its segment.
  • Normalize CRLF/CR -> LF like Python.
  • Do NOT perform the OVER_CAP token merge; chunking stays with the downstream
    Chunker (PARSER_ALIGNMENT_HANDOFF.md §2.3).
  • The 8192-byte per-item cap is dropped: the parser is a pure delimiter
    splitter, matching Python's parser_txt (no size slicing). Sizing is
    delegated to the Chunker + embedding truncation — see contract Internal discussion: TokenChunker contract — delimiter boundary + token_size soft-target merge #17799 below.

Why dropping the 8192-byte cap is safe (contract #17799)

The parser layer must NOT do token-size splitting. internal/ingestion/component/chunker/token.go
(OVER-BUDGET UNITS, contract #17799) states: a single item exceeding
chunk_token_size is KEPT WHOLE as its own chunk and is NOT atom-split; the
downstream embedding/rerank layer truncates it later. Token-size chunking —
including any oversized-item handling — belongs to the Chunker (or a PreSplitter
stage between Parser and Chunker), explicitly NOT in the parser and NOT as a
char-window split. So removing the per-item byte cap converges Go with Python's
parser_txt (which also does no size slicing) instead of diverging, and the
Chunker already owns the oversized-item case.

Test plan

  • TestTextParser_ParseWithResult_DefaultDelimiter pins the new split rule
    (single-newline + sentence-delimiter splitting with delimiter retained).
  • TestTextParser_ParseWithResult_NoSizeCap pins no per-item byte slicing.
  • TestTextParser_AdjacentDelimiters pins the documented adjacent-delimiter
    behavior (Go drops the standalone second delimiter) so a future silent change
    in splitCapturingDelims is caught.
  • TestTextParser_AlignmentGolden verifies content-equivalence vs the Python
    golden on a shared sample.

Dependency

Stacks on #18014 (framework in main) and the foundation helpers PR
(fix/parser-align-foundation).

Note

Adjacent-delimiter input (e.g. "a..b") keeps only the merged segment in Go
while Python keeps the second delimiter as its own segment. The alignment test
normalizes this away; tracked as a known follow-up, not fixed here.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Aug 11, 2026
@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d7f8dcb1-39d7-4a06-a159-c79f3a569dc0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Make Go TextParser match Python deepdoc TxtParser._code:
- Split on the flow default delimiter set "\n!?;。;!?" (was blank-line only).
- keep_delimiters=True: each trailing delimiter is retained on its segment.
- Normalize CRLF/CR -> LF like Python.
- Do NOT perform the OVER_CAP token merge; chunking stays with the downstream
  Chunker (PARSER_ALIGNMENT_HANDOFF.md §2.3).
- The 8192-byte per-item cap is dropped: the parser is a pure delimiter
  splitter, matching Python's parser_txt (no size slicing). Sizing is delegated
  to the Chunker + embedding truncation per contract #17799.

Tests:
- TestTextParser_ParseWithResult_DefaultDelimiter pins the new split rule
  (single-newline + sentence-delimiter splitting with delimiter retained).
- TestTextParser_ParseWithResult_NoSizeCap pins no per-item byte slicing.
- TestTextParser_AlignmentGolden verifies content-equivalence vs the Python
  golden on a shared sample.

Depends on #18014 and the foundation helpers PR (align_test.go).

Files:
  internal/parser/parser/text_parser.go
  internal/parser/parser/parse_with_result_test.go
  internal/parser/parser/testdata/textcode.sample.txt (new)
  internal/parser/parser/testdata/textcode.python.golden.json (new)
…-delimiter test

- text_parser.go now uses the shared DefaultTextCodeDelimiter from
  delimiter.go instead of a private duplicate that could drift silently.
- Fix the golden-regeneration comment: no generator script is committed;
  the baseline is reproducible from the golden's meta block.
- Add TestTextParser_AdjacentDelimiters pinning the documented adjacent-
  delimiter behavior (Go drops the standalone second delimiter) so a
  future silent change in splitCapturingDelims is caught.
@xugangqiang
xugangqiang force-pushed the fix/textcode-parser-align branch from 0e8c69d to f8688b1 Compare August 11, 2026 09:21
@yingfeng
yingfeng deleted the branch fix/parser-align-foundation August 11, 2026 11:02
@yingfeng yingfeng closed this Aug 11, 2026
@yingfeng
yingfeng deleted the fix/textcode-parser-align branch August 19, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants