Conversation
ChunkingOptions._validate() checked new_after_n_chars and new_after_n_tokens for negative values but never checked overlap. A negative overlap then corrupted output two ways with no error and no warning. On the character-split path, base.py:2731 computes the remainder as s[maxlen - overlap:], so a negative overlap starts the remainder past the end of the fragment and drops that many characters at every split boundary. A 60-character input at max_characters=20 and overlap=-5 loses 'UVWXY' and 'tuvwx' from the output entirely. With overlap_all=True, base.py:755 computes self._text[-overlap:], which for a negative overlap is a forward slice, so the tail carried into the next chunk repeats most of the current one. Reachable from chunk_elements, chunk_by_title and partition(chunking_strategy=). Now raises ValueError, matching the two sibling options.
Contributor
|
@chrikrah , lets keep the ValueError , since overlap is intended to be non-negative. thanks! |
cragwolfe
approved these changes
Sep 26, 2026
chrikrah
commented
Oct 3, 2026
chrikrah
left a comment
Author
There was a problem hiding this comment.
@cragwolfe, make check fails on this branch today, before any merge. #4472 took the 0.27.17 heading on main the next afternoon. The resolution moves CHANGELOG.md and unstructured/__version__.py together, onto whichever number is free.
$ git archive refs/pull/4501/head | tar -x -C /tmp/t && cd /tmp/t # b180227
$ scripts/version-sync.sh -c -f unstructured/__version__.py semver # origin/main served from 2c0c7a6
Error: there is already a commit associated with version 0.27.17.
$ sed -i '1s/0.27.17/0.27.18/' CHANGELOG.md
$ scripts/version-sync.sh -c -f unstructured/__version__.py semver
version sync would make the following changes to unstructured/__version__.py:
< __version__ = "0.27.17" # pragma: no cover
> __version__ = "0.27.18" # pragma: no cover
Versions are out of sync! See above for diffs.
# not run: python -m pytest test_unstructured/chunking -q, 484 passed / 24 skipped on 81f0630
You approved it on 26 September, and it will collide again on every release until it lands. Is the renumber the last thing, or does something else block it? I can push both files within the hour of your word.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No open issue covers this. None. Found while reading the three sibling validators in
_validate()against the parameters they guard.ChunkingOptions._validate()atunstructured/chunking/base.pyrejects a negativenew_after_n_charsand a negativenew_after_n_tokens. It never checksoverlap. A negative overlap then corrupts output two ways, with no error and no warning.base.py:2731computes the remainder ass[maxlen - self._opts.overlap :]. Withoverlap = -5that remainder starts five characters past the end of the fragment, so five characters of the document disappear at every split boundary.base.py:755computesself._text[-overlap:]. Withoverlap = -5that is a forward slice, so the tail carried into the next chunk is most of the current chunk.Before, on a 60-character input of unique characters at
max_characters=20:The
overlap=0line is the control: same input, same commit, nothing lost.With
overlap_all=True, three 10-character elements atmax_characters=12:Text duplicated and out of order.
Reachable from all three public entry points:
chunk_elements(...),chunk_by_title(...), andpartition(filename=..., chunking_strategy="basic", overlap=-5). All three drop the same characters.After, the four added lines mirror the existing
new_after_n_charscheck and raiseValueError.Baseline on
1bedf7bis482 passed, 24 skipped, so the delta is the two new parametrised cases. Revertingunstructured/chunking/base.pyand keeping the test gives2 failed, 482 passed, 24 skipped, both of themFailed: DID NOT RAISE ValueError.ruff checkis clean on both touched files.I did not run
make testormake checkin full, and no PDF, image or OCR test ran here: the install was-e ".[csv,docx,md,pptx,xlsx]"without the inference extras.make check-versionpasses, withCHANGELOG.mdand__version__.pyboth at0.27.10.Duplicate check: all 130 open pull requests enumerated, 10 touching
unstructured/chunking/. I grepped each diff for added lines matching_validate|overlap.*must be|overlap_arg. The only hit is #4487, which capscombine_text_under_n_charsintitle.py::_validate: different file, different function, different parameter. #4392 is the nearest neighbour and changes_split_by_tokensrather than validation, so the two do not collide.@cragwolfe you merged the last chunking change here. Would you rather this raised, or clamped a negative overlap to zero with a warning?