← Back to Pull requests

fix: split Chinese and Japanese sentences at full-width terminators in DocumentSplitter #13834

Open
unknown opened this pull request with 402 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 20, 2026 12:21 UTC
Author

Related Issues

  • fixes #13833
  • Proposed Changes:

    Chinese and Japanese text has no space after 。, ! or ?, so NLTK's Punkt returns the whole text as one sentence, and DocumentSplitter(split_by="sentence") and the "sentence" separator of RecursiveDocumentSplitter cannot split it. Adding the characters to sent_end_chars (as #13646 did for the danda) is not enough here: Punkt reads a run of Chinese text without spaces as one word.

    SentenceSplitter.split_sentences() now splits each Punkt sentence after 。, !, ? (and the half-width 。). A terminator followed by a closing quote or bracket (”, 」, ), ...) is not a split point, so 他说:“我走了。”然后离开了。 stays one sentence. The whitespace after a terminator goes to the previous sentence when keep_white_spaces=True, as for other sentences. These characters are not used as sentence ends in other scripts, so this applies for every language; English output is unchanged.

    Use case: splitting Chinese PDFs for retrieval. On a Chinese bank terms-of-service page converted with PDFMinerToDocument, DocumentSplitter(split_by="sentence", split_length=3) gives 1 chunk of 2818 characters on main and 7 chunks with this change.

    How did you test it?

  • New tests in test/components/preprocessors/test_sentence_tokenizer.py for both keep_white_spaces values: Chinese and Japanese text with newlines between sentences, and terminators inside quotes. They fail on main and pass here.

  • hatch run test:unit test/components/preprocessors/: 553 passed.

  • pre-commit run on the changed files: all hooks pass except codespell, which flags the existing Telugu code "te" in sentence_tokenizer.py (lines 47 and 73, not touched here). hatch run test:types on the module: clean.
  • Notes for the reviewer

    Because a terminator followed by a closing quote is never a split point, 「行きます。」と言った。 is one sentence, as it should be, but so is 「行きます。」「はい。」次の文。: a sentence that starts right after such a quote is not split off. I kept the rule simple and conservative (a longer sentence rather than a wrong cut); tell me if you'd prefer a different trade-off.

    Checklist

  • I have read the contributors guidelines and the code of conduct.

  • I have updated the related issue with new insights and changes.

  • I have added unit tests and updated the docstrings.

  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.

  • I have documented my code.

  • I have added a release note file, following the contributors guidelines.

  • I have run pre-commit hooks and fixed any issue.
  • This PR was generated with an AI assistant (Claude Code). I have reviewed the changes and run the tests above.

    Diff: 402 lines (+301 / -101) across 5 files Reviewer: its-amann Review duration: 14578m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 402 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.359
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #13834"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.7% (MEDIUM) · Higher = larger blast radius
    44.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 23.8% · Safe to merge
    23.8%