fix: honor batch rate limit under async indexing (#1542)#2081
Open
shaikn6 wants to merge 1 commit into
Open
Conversation
When the server runs in async-indexing mode it does not report batchStats, so dynamic batching cannot tune itself against the indexing queue and falls back to large fixed-size batches. That fallback unconditionally overwrote the batching mode with _FixedSizeBatching(1000, 10), silently discarding a rate limit configured via collection.batch.rate_limit(...). As a result batches contained 1000 objects regardless of the configured requests-per-minute. Extract the fallback decision into _async_indexing_batch_params, which keeps the large-batch behavior for dynamic batching but preserves a configured rate limit. Track the originally requested batch mode so the fallback can tell whether a rate limit was set. Add unit tests covering both paths.
There was a problem hiding this comment.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Infrastructure as Code | View in Orca | ||
| SAST | View in Orca | ||
| Secrets | View in Orca | ||
| Vulnerabilities | View in Orca |
|
To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge. |
Author
|
I have read and agree to the Weaviate Contributor License Agreement. |
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.
What & why
Fixes #1542.
collection.batch.rate_limit(...)was not honored when the Weaviate server runs in async-indexing mode. Batches were sent with 1000 objects regardless of the configured requests-per-minute, defeating the rate limiter exactly as reported in the issue.Root cause
Dynamic batching sizes its batches from the server-reported indexing queue. Under async indexing the server does not return
batchStats, so the background loop in_BatchBase.__dynamic_batchingtakes its "no queue feedback" fallback:This fallback overwrote the batching mode unconditionally, so a rate limit that the user had configured was silently dropped and replaced with fixed-size 1000/10 batching — the "1000 objects no matter the rate" behavior in the report.
The fix
The fallback decision is extracted into a small, side-effect-free helper,
_async_indexing_batch_params, which:_RateLimitedBatchingmode (reusing the same requests-per-minute math as the constructor), and_FixedSizeBatching(1000, 10)) for dynamic batching when no rate limit was set.The originally requested batch mode is tracked separately (
__requested_batch_mode) so the fallback can tell whether a rate limit was configured, since__batching_modeis reassigned at runtime. The rate-limited timing path itself in__batch_sendis unchanged. No public API signatures change.Testing
Added unit tests in
test/collection/test_batch.pythat exercise the decision helper directly, so they need no live Weaviate server:test_async_indexing_preserves_rate_limit— a configuredrate_limit(100)is preserved (not replaced by 1000/10)test_async_indexing_rate_limit_spans_multiple_batches— a limit above the max batch size is split across batches (3000/min → 4 × 750)test_async_indexing_dynamic_falls_back_to_fixed_size— regression guard: dynamic batching without a rate limit keeps the_FixedSizeBatching(1000, 10)fallbackThe "preserve rate limit" tests fail on
main(the helper does not exist / the old branch hardcodes 1000/10) and pass with this change.Ran locally (Python 3.12, fresh venv from
requirements-devel.txt+requirements-test.txt):pytest test/→ 379 passed, 1 skippedruff format --check→ cleanflake8(incl. flake8-docstrings + pydoclint plugin) → cleanpyright→ no errors inbase.py(the 4 pre-existingconnect/v4.pyauthlib errors are present on unmodifiedmain)pydoclint→ no findings for the added functionsI could not run the integration/mock suites, which require a live Weaviate instance via Docker; this change is covered by the server-free unit tests above.
CLA
I understand contributions require a signed Contributor License Agreement per
CONTRIBUTING.md, and I'll complete the DocuSign step from the link the bot posts on this PR.