fix: raise a clear error for zero-sum weights in DocumentJoiner#11629
Merged
bogdankostic merged 2 commits intoJun 19, 2026
Merged
Conversation
DocumentJoiner normalized weights via float(i) / sum(weights); when the weights summed to zero this raised an opaque ZeroDivisionError at construction. Validate the sum and raise a clear ValueError instead.
|
@i-anubhav-anand is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
Contributor
|
Thanks for creating this PR @i-anubhav-anand! The release note check is currently failing, please fix it by using double backticks instead of single backticks for in-line code. |
bogdankostic
approved these changes
Jun 19, 2026
bogdankostic
left a comment
Contributor
There was a problem hiding this comment.
Thanks @i-anubhav-anand
sjrl
pushed a commit
that referenced
this pull request
Jun 22, 2026
Co-authored-by: bogdankostic <bogdankostic@web.de>
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.
Related Issues
Self-found bug (no existing issue).
DocumentJoinercrashes with an opaqueZeroDivisionErrorat construction when the providedweightssum to zero.Proposed Changes:
DocumentJoiner.__init__normalized the weights with:If
weightsis non-empty but sums to zero (e.g.[0, 0, 0], or[1, -1]),sum(weights)is0and this raises a bareZeroDivisionError: float division by zerowith no indication of what went wrong. This change validates the sum and raises a clearValueErrorinstead.Reproduction (before the fix):
How did you test it?
Added
test_init_with_zero_sum_weights_raisesintest/components/joiners/test_document_joiner.pyasserting aValueError(matching "must not sum to zero") is raised. Ranhatch run test:unit test/components/joiners/test_document_joiner.py(33 passed),hatch run fmt(clean), andhatch run test:types haystack/components/joiners/document_joiner.py(mypy clean). Added a release note.Notes for the reviewer
Tiny, isolated change to the constructor; normal weights are unaffected.
Checklist
fix:).hatch run fmtand fixed any issue.