Skip to content

Accumulate join Total/Avg scores in double precision - #16378

Merged
javanna merged 3 commits into
apache:mainfrom
javanna:join_util_scores
Jul 9, 2026
Merged

Accumulate join Total/Avg scores in double precision#16378
javanna merged 3 commits into
apache:mainfrom
javanna:join_util_scores

Conversation

@javanna

@javanna javanna commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

TermsWithScoreCollector, JoinUtil's numeric point join, and TestJoinUtil summed per-document scores in float. Float addition isn't associative, so summing the same scores in a different order can round to a different float, causing TestJoinUtil.testMultiValueRandomJoin to intermittently fail on exact score/doc-order assertions.

Scores are now accumulated in double and narrowed to float only where exposed.

TermsWithScoreCollector, JoinUtil's numeric point join, and TestJoinUtil
summed per-document scores in float. Float addition isn't associative,
so summing the same scores in a different order can round to a different float,
causing TestJoinUtil.testMultiValueRandomJoin to intermittently fail on exact
score/doc-order assertions.

Scores are now accumulated in double and narrowed to float only where exposed.

@romseygeek romseygeek 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.

LGTM.

I think this removes the only use of LongFloatHashMap in the codebase so maybe we should delete that too?

@javanna

javanna commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@romseygeek good point! I did not realize this was the only usage. I will remove as a follow-up. Thanks for the review.

@javanna javanna added this to the 10.6.0 milestone Jul 8, 2026

@dweiss dweiss 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.

I understand the hope is that computing over doubles won't propagate rounding errors to the resulting float-trimmed result, right? Because in principle the same unfortunate thing can still happen with doubles, it's just less likely...

@romseygeek

Copy link
Copy Markdown
Contributor

IIUC the errors will always be smaller than the delta we use in the tests if we sum over doubles though?

@javanna

javanna commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Indeed, I could no longer reproduce any failures with this fix. You still have precision errors, but when you narrow the double sum down to a float at the end ((float) total), that tiny double-level discrepancy is almost always well below the float's rounding granularity, so both orderings round to the same float.

In alternative, we could introduce some additional tolerance in the assertions?

@javanna

javanna commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

In alternative, we could introduce some additional tolerance in the assertions?

The reason why I went for the current approach is that I thought it would make things a little more predictable with the introduction of search concurrency, in production code too. Let me know what you think.

@javanna

javanna commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

I will merge this for now to address the test failures, let me know if there are concerns and we can always revise our approach? Thanks!

@dweiss

dweiss commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

I'm fine. I just wondered if switching to double precision (twice the amount of ram) is worth it, considering it's a single assertion change (adding delta). Your call.

@javanna
javanna merged commit d96acfd into apache:main Jul 9, 2026
12 checks passed
javanna added a commit that referenced this pull request Jul 9, 2026
TermsWithScoreCollector, JoinUtil's numeric point join, and TestJoinUtil
summed per-document scores in float. Float addition isn't associative,
so summing the same scores in a different order can round to a different float,
causing TestJoinUtil.testMultiValueRandomJoin to intermittently fail on exact
score/doc-order assertions.

Scores are now accumulated in double and narrowed to float only where exposed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants