Skip to content

fix(query): allow rerank on every search operator - #608

Open
dudanogueira wants to merge 4 commits into
mainfrom
fix/rerank-all-operators
Open

dudanogueira wants to merge 4 commits into
mainfrom
fix/rerank-all-operators

Conversation

@dudanogueira

@dudanogueira dudanogueira commented Aug 25, 2026 •

Copy link
Copy Markdown

Problem

Fix

  • Move rerank(Rerank) to BaseQueryOptions.Builder so every operator accepts it, and marshal it from the common options.
  • Add rerankScore to QueryMetadata, QueryResponseGroup and GenerativeResponseGroup; null when the query was not reranked.

Breaking changes

  • NearText, NearVector, NearObject, NearImage, NearAudio, NearVideo, NearDepth, NearThermal, NearImu: the rerank record component is removed (rerank() is still available via QueryOperator).
  • QueryMetadata, QueryResponseGroup, GenerativeResponseGroup: new Double rerankScore component.

Builder-based code is unaffected.

Closes #603
Closes #604

dudanogueira and others added 3 commits August 24, 2026 20:44
rerank(Rerank) was declared on BaseVectorSearchBuilder, so only the near*
searches could be reranked. BM25, Hybrid and FetchObjects could not, even
though rerank is a top-level field of the search request and the server
applies it the same way for all of them.

Move the option to BaseQueryOptions, which every operator builder extends,
and marshal it from BaseQueryOptions.appendTo. The near* records no longer
carry their own rerank component; QueryOperator.rerank() now reads it off
the common options, so it stays readable on every operator.

Closes #603

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WmY5dAGWCccWDoqkKNC2JU
The server returns a rerank score per object (MetadataResult.rerank_score)
and per group (GroupByResult.rerank), but neither was read: a reranked
search arrived correctly ordered with the number that produced the order
missing, and no way to get it short of re-reading the reply.

Add rerankScore to QueryMetadata and QueryResponseGroup and populate both.
The score is only set when the reply says it is present -- 0.0 is what the
dummy reranker returns for a match, so the value alone cannot distinguish
"not reranked" from "reranked with score 0".

Closes #604

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WmY5dAGWCccWDoqkKNC2JU
The generative search reuses the query operators, so it accepts rerank
the same way -- but GenerativeResponseGrouped dropped the group-level
score that QueryResponseGrouped reads, leaving that one path unable to
tell how the groups were ranked.

Per-object scores were already covered: every unmarshal path funnels
through QueryResponse.unmarshalResultObject.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WmY5dAGWCccWDoqkKNC2JU

@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

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

Pull request overview

This PR closes gaps in v6 rerank support by (1) making rerank(...) a true common query option across all search operators and (2) unmarshalling rerank scores from server replies so callers can read the scores that produced the ordering.

Changes:

  • Move rerank(Rerank) into BaseQueryOptions.Builder and marshal it from BaseQueryOptions.appendTo, enabling rerank for BM25, Hybrid, and FetchObjects.
  • Unmarshal rerank scores into public response types: per-object (QueryMetadata.rerankScore) and per-group (QueryResponseGroup / GenerativeResponseGroup), honoring server presence flags/guards.
  • Add unit + integration test coverage across operators and grouped generative responses.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/main/java/io/weaviate/client6/v1/api/collections/query/BaseQueryOptions.java Adds rerank as a common option and marshals it into the top-level gRPC request.
src/main/java/io/weaviate/client6/v1/api/collections/query/BaseVectorSearchBuilder.java Removes the old vector-only rerank plumbing.
src/main/java/io/weaviate/client6/v1/api/collections/query/QueryOperator.java Makes operator.rerank() derive from common() so it stays readable for all operators.
src/main/java/io/weaviate/client6/v1/api/collections/query/QueryRequest.java Removes the old standalone rerank append to avoid split marshalling paths.
src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java Unmarshals per-object rerank score using the proto presence flag.
src/main/java/io/weaviate/client6/v1/api/collections/query/QueryMetadata.java Adds nullable rerankScore to represent presence vs. absent.
src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponseGroup.java Adds nullable per-group rerank score to grouped query results.
src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponseGrouped.java Reads group-level rerank score from GroupByResult when present.
src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponseGroup.java Adds nullable per-group rerank score to grouped generative results.
src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponseGrouped.java Reads group-level rerank score for generative grouped replies.
src/main/java/io/weaviate/client6/v1/api/collections/query/NearText.java Drops rerank from the near* record shape (now provided via common options).
src/main/java/io/weaviate/client6/v1/api/collections/query/NearVector.java Drops rerank from the near* record shape (now provided via common options).
src/main/java/io/weaviate/client6/v1/api/collections/query/NearObject.java Drops rerank from the near* record shape (now provided via common options).
src/main/java/io/weaviate/client6/v1/api/collections/query/NearImage.java Drops rerank from the near* record shape (now provided via common options).
src/main/java/io/weaviate/client6/v1/api/collections/query/NearAudio.java Drops rerank from the near* record shape (now provided via common options).
src/main/java/io/weaviate/client6/v1/api/collections/query/NearVideo.java Drops rerank from the near* record shape (now provided via common options).
src/main/java/io/weaviate/client6/v1/api/collections/query/NearDepth.java Drops rerank from the near* record shape (now provided via common options).
src/main/java/io/weaviate/client6/v1/api/collections/query/NearThermal.java Drops rerank from the near* record shape (now provided via common options).
src/main/java/io/weaviate/client6/v1/api/collections/query/NearImu.java Drops rerank from the near* record shape (now provided via common options).
src/test/java/io/weaviate/client6/v1/api/collections/query/RerankTest.java Adds unit tests asserting rerank marshalling across all operators and score unmarshalling semantics.
src/test/java/io/weaviate/client6/v1/api/collections/generate/GenerativeRerankTest.java Adds unit tests for group-level rerank score in generative grouped replies.
src/it/java/io/weaviate/integration/SearchITest.java Extends integration coverage to BM25/Hybrid/FetchObjects and validates rerankScore presence/absence behavior.
Suppressed comments (1)

src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponseGroup.java:29

  • This Javadoc @link currently relies on imports; after removing the unused imports above, it will no longer resolve. Use a fully-qualified reference so the link stays valid without imports.
     * {@link BaseQueryOptions.Builder#rerank(Rerank)}.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v6: rerank score is never unmarshalled from the search reply v6: rerank cannot be used with BM25, Hybrid or FetchObjects

2 participants