fix: split Chinese and Japanese sentences at full-width terminators in DocumentSplitter #13834
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
its-amann
Related Issues
Proposed Changes:
Chinese and Japanese text has no space after
。,!or?, so NLTK's Punkt returns the whole text as one sentence, andDocumentSplitter(split_by="sentence")and the"sentence"separator ofRecursiveDocumentSplittercannot split it. Adding the characters tosent_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 whenkeep_white_spaces=True, as for other sentences. These characters are not used as sentence ends in other scripts, so this applies for everylanguage; 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 onmainand 7 chunks with this change.How did you test it?
test/components/preprocessors/test_sentence_tokenizer.pyfor bothkeep_white_spacesvalues: Chinese and Japanese text with newlines between sentences, and terminators inside quotes. They fail onmainand pass here.hatch run test:unit test/components/preprocessors/: 553 passed.pre-commit runon the changed files: all hooks pass exceptcodespell, which flags the existing Telugu code"te"insentence_tokenizer.py(lines 47 and 73, not touched here).hatch run test:typeson 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
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.This PR was generated with an AI assistant (Claude Code). I have reviewed the changes and run the tests above.