fix: keep insertion order when MetaFieldGroupingRanker sort values have mixed types#11942
Open
Otis0408 wants to merge 1 commit into
Open
Conversation
|
@Otis0408 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 |
||||||||||||||||||||||||
a2feaa5 to
b7a3a86
Compare
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.
MetaFieldGroupingRankersorts the documents inside each group by a metadata field whensort_docs_byis set. The sort key(value is None, value)correctly pushes documents with a missing sort value to the end, but it does not protect against two documents that both have a present value of mutually non-comparable types. When a group contains, for example, onesplit_idthat is anintand another that is astr, both keys evaluate to(False, <value>)and Python compares the raw values, raisingTypeError: '<' not supported between instances of 'str' and 'int'. Because the sort was not guarded, the exception propagates out ofrun()and aborts the whole component/pipeline.Heterogeneous metadata types for a field like
split_id,page, ordateare realistic in RAG setups where documents come from different converters or document stores (for instance JSON-sourced strings mixed with int-typed values). Any user running such documents through this ranker withsort_docs_byset hits the crash.This is also inconsistent with the sibling
MetaFieldRanker, which already wraps itssorted(...)in atry/except TypeErrorand falls back to the original order with a warning. This change mirrors that behavior: the per-group sort is wrapped intry/except TypeError, and on failure the group's original insertion order is kept and a warning is logged. The misleading comment claiming the tuple makes the sort work "for numbers, strings, and other types" was corrected.Before:
After:
A release note is included at
releasenotes/notes/meta-field-grouping-ranker-mixed-type-sort-a1b2c3d4e5f60718.yaml.