fix(groupBy): correct minDistance and maxDistance in multi-shard merge and hybrid search (#13108) by ManoharPaturi · Pull Request #13131 · weaviate/weaviate · GitHub
Skip to content

fix(groupBy): correct minDistance and maxDistance in multi-shard merge and hybrid search (#13108) - #13131

Open
ManoharPaturi wants to merge 1 commit into
weaviate:mainfrom
ManoharPaturi:fix/group-by-min-max-distance
Open

ManoharPaturi wants to merge 1 commit into
weaviate:mainfrom
ManoharPaturi:fix/group-by-min-max-distance

Conversation

@ManoharPaturi

Copy link
Copy Markdown

Fixes #13108

Problem

In groupBy queries, minDistance and maxDistance describe the minimum and maximum distances of the group's hits. Two execution paths compute or assign them incorrectly:

  1. Multi-shard group merge (adapters/repos/db/group_merger.go):
    After hits from all shards are merged and sorted ascending by distance (hits[i].Distance < hits[j].Distance), MaxDistance was assigned hits[0] (the lowest distance) and MinDistance was assigned hits[len(hits)-1] (the highest distance). For multi-shard queries, this inverted minDistance and maxDistance (minDistance > maxDistance).
  2. Hybrid search group by (usecases/traverser/hybrid_group_by.go):
    In groupSearchResults, both MinDistance and MaxDistance were assigned first.Dist, copying only the first hit's distance and ignoring all other members of the group. Since hybrid search ranks hits by fusion score (not pure distance), first.Dist does not represent the minimum or maximum distance of the group.

Solution

  • In adapters/repos/db/group_merger.go: Assign MinDistance from hits[0] (smallest distance) and MaxDistance from hits[len(hits)-1] (largest distance).
  • In usecases/traverser/hybrid_group_by.go: Iterate over all retained groupMembers to compute the minimum and maximum hit distances for the group.
  • Added comprehensive unit tests in adapters/repos/db/group_merger_test.go and usecases/traverser/hybrid_group_by_test.go covering multi-shard merges, ObjectsPerGroup capping, group ordering, and hybrid search distance tracking.

Verification

  • go test -v -run TestGroupMerger ./adapters/repos/db passes.
  • go test -v -run TestExplorerGroupSearchResults ./usecases/traverser passes.

…e and hybrid search (weaviate#13108)

Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 17, 2026 11:13

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sonarqubecloud

Copy link
Copy Markdown

@orca-security-eu orca-security-eu Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed SAST high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

@weaviate-git-bot weaviate-git-bot added the community originated from the community label Sep 17, 2026
@weaviate-git-bot

Copy link
Copy Markdown

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.

beep boop - the Weaviate bot 👋🤖

PS:
Are you already a member of the Weaviate Forum?

@ManoharPaturi

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community originated from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

groupBy minDistance / maxDistance do not match the distances of the group's hits

3 participants