Skip to content

Retrievers - Fix rank_window_size validation #128108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ public ActionRequestValidationException validate(
if (isScroll) {
validationException = addValidationError("cannot specify [" + getName() + "] and [scroll]", validationException);
}
if (rankWindowSize < 0) {
validationException = addValidationError(
"[" + getRankWindowSizeField().getPreferredName() + "] parameter cannot be negative, found [" + rankWindowSize + "]",
validationException
);
}

for (RetrieverSource innerRetriever : innerRetrievers) {
validationException = innerRetriever.retriever().validate(source, validationException, isScroll, allowPartialSearchResults);
if (innerRetriever.retriever() instanceof CompoundRetrieverBuilder<?> compoundChild) {
Expand Down Expand Up @@ -279,6 +286,10 @@ public int doHashCode() {
return Objects.hash(innerRetrievers);
}

public int rankWindowSize() {
return rankWindowSize;
}

protected final SearchSourceBuilder createSearchSourceBuilder(PointInTimeBuilder pit, RetrieverBuilder retrieverBuilder) {
var sourceBuilder = new SearchSourceBuilder().pointInTimeBuilder(pit)
.trackTotalHits(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@
* retrievers can be added individually with additional functionality.
*/
public class RetrieversFeatures implements FeatureSpecification {
public static final NodeFeature NEGATIVE_RANK_WINDOW_SIZE_FIX = new NodeFeature("retriever.negative_rank_window_size_fix");

@Override
public Set<NodeFeature> getFeatures() {
return Set.of();
}

@Override
public Set<NodeFeature> getTestFeatures() {
return Set.of(NEGATIVE_RANK_WINDOW_SIZE_FIX);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ public String getName() {
return NAME;
}

public int rankWindowSize() {
return rankWindowSize;
}

@Override
protected SearchSourceBuilder finalizeSourceBuilder(SearchSourceBuilder source) {
checkValidSort(source.sorts());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,6 @@ public String inferenceId() {
return inferenceId;
}

public int rankWindowSize() {
return rankWindowSize;
}

public boolean failuresAllowed() {
return failuresAllowed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1063,3 +1063,42 @@ setup:
- close_to: { hits.hits.0._score: { value: 10.5, error: 0.001 } }
- match: { hits.hits.1._id: "1" }
- match: { hits.hits.1._score: 10 }

---
"should throw when rank_window_size is negative":
- requires:
cluster_features: [ "retriever.negative_rank_window_size_fix" ]
reason: "Fix for negative rank_window_size error message"
- do:
catch: /\[rank_window_size\] parameter cannot be negative, found \[-10\]/
search:
index: test
body:
retriever:
linear:
retrievers: [
{
retriever: {
standard: {
query: {
match_all: { }
}
}
},
weight: 10.0,
normalizer: "minmax"
},
{
retriever: {
knn: {
field: "vector",
query_vector: [ 4 ],
k: 1,
num_candidates: 1
}
},
weight: 2.0
}
]
rank_window_size: -10
- match: { status: 400 }
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ public String getName() {
return NAME;
}

public int rankWindowSize() {
return rankWindowSize;
}

/**
* Creates a PinnedQueryBuilder with the appropriate pinned documents.
*
Expand Down