Repository navigation
fix(query): allow rerank on every search operator - #608
Open
dudanogueira wants to merge 4 commits into
Open
dudanogueira wants to merge 4 commits into
dudanogueira wants to merge 4 commits into
Conversation
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
There was a problem hiding this comment.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Infrastructure as Code | View in Orca | ||
| SAST | View in Orca | ||
| Secrets | View in Orca | ||
| Vulnerabilities | View in Orca |
There was a problem hiding this comment.
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)intoBaseQueryOptions.Builderand marshal it fromBaseQueryOptions.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
@linkcurrently 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.
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.
Problem
rerank(...)was only available on thenear*operators; BM25, Hybrid and FetchObjects could not be reranked (v6: rerank cannot be used with BM25, Hybrid or FetchObjects #603).Fix
rerank(Rerank)toBaseQueryOptions.Builderso every operator accepts it, and marshal it from the common options.rerankScoretoQueryMetadata,QueryResponseGroupandGenerativeResponseGroup;nullwhen the query was not reranked.Breaking changes
NearText,NearVector,NearObject,NearImage,NearAudio,NearVideo,NearDepth,NearThermal,NearImu: thererankrecord component is removed (rerank()is still available viaQueryOperator).QueryMetadata,QueryResponseGroup,GenerativeResponseGroup: newDouble rerankScorecomponent.Builder-based code is unaffected.
Closes #603
Closes #604