← Back to Pull requests

fix: keep trailing whitespace when splitting text into sentences #13862

Open
unknown opened this pull request with 193 lines diff across 2 files
View on GitHub
unknown unknown commented on Nov 22, 2026 13:14 UTC
Author

Related Issues

  • fixes #13861
  • Proposed Changes:

    DocumentSplitter with split_by="sentence" (and split_by="word" with respect_sentence_boundary=True) drops the whitespace at the end of the text. NLTK ends the last span at len(text.rstrip()), so "One. Two.\n\n" comes back as "One. " and "Two.".

    SentenceSplitter.split_sentences now extends the last span to the end of the text when keep_white_spaces is on. With keep_white_spaces=False nothing changes. Use case: files read from disk usually end with a newline, which was lost in the last chunk.

    How did you test it?

    New unit tests in test_sentence_tokenizer.py (trailing newline, \n\n, form feed, spaces, and the keep_white_spaces=False control) and test_document_splitter.py (chunks add up to the original text for both split modes). The new tests fail without the change and pass with it. test/components/preprocessors and test/components/retrievers pass, ruff check and ruff format --check are clean.

    Notes for the reviewer

    None.

    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:.

  • I have documented my code.

  • I have added a release note file.

  • I have run pre-commit hooks and fixed any issue.
  • This PR was fully generated with an AI assistant. I have reviewed the changes and run the relevant tests.

    Diff: 193 lines (+144 / -49) across 2 files Reviewer: chrikrah Review duration: 2957m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.36) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 193 lines diff across 2 files
    0.36
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.315
    Real PR Conversation Timeline
    1 comments
    "Review active on #13862"
    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: 36.0% (MEDIUM) · Higher = larger blast radius
    36.0%
    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: 19.2% · Safe to merge
    19.2%