Skip to content

fix: stop generator_batching_wbytes from dropping items or yielding an empty batch - #832

Merged
awalker4 merged 2 commits into
Unstructured-IO:mainfrom
r0h1tb:fix/batching-wbytes-empty-batches
Nov 19, 2026
Merged

awalker4 merged 2 commits into
Unstructured-IO:mainfrom
r0h1tb:fix/batching-wbytes-empty-batches

Conversation

@r0h1tb

@r0h1tb r0h1tb commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

What

generator_batching_wbytes (used by the Elasticsearch, OpenSearch and Pinecone uploaders) had two batching bugs:

generator_batching_wbytes(items)                                  # before: no batches   after: [items]
generator_batching_wbytes([big, small], batch_size_limit_bytes=20) # before: [[], [big], [small]]   after: [[big], [small]]

Why

The return iterable shortcut for "no limits" is inside a generator, so it ends iteration without yielding anything. An Elasticsearch or OpenSearch upload with batch_size_bytes=0 therefore sent no documents and reported no error. Separately, when the first item alone exceeded the byte limit, the still-empty batch was yielded before it — the same empty-batch problem #694 fixed in split_dataframe.

The shortcut is removed, so with no limits everything goes in one batch, and a batch is only closed once it has items. Behaviour with limits is otherwise unchanged; an oversized item still gets a batch of its own.

Validation

Two new tests in test/unit/utils/test_data_prep.py; both fail on main. pytest test/unit --ignore test/unit/unstructured: 1941 → 1943 passed, same 69 skipped. ruff check . and ruff format --check pass. Adds a CHANGELOG entry and bumps the version to 1.11.27.

…n empty batch

The early `return iterable` sits inside a generator, so with no byte limit
and no batch size it produced no batches at all. And when the first item
alone was over the byte limit, the empty current batch was yielded before
it. Drop the early return, so no limits means one batch, and only close a
batch that has items.
@r0h1tb
r0h1tb requested a review from a team as a code owner October 24, 2026 14:11

@awalker4 awalker4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. I ran the old and new function side by side over the edge cases: no limits, batch_size_limit_bytes=0, generator input, a single oversized item, oversized first/last/both, the exact byte boundary, and max_batch_size alone and combined. The only differences are the two you describe; everything else batches identically. I'll merge main and bump the version on the branch.

@awalker4
awalker4 merged commit a9ec948 into Unstructured-IO:main Nov 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants