Skip to content
5 changes: 5 additions & 0 deletions docs/changelog/137249.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 137249
summary: Add `chunk_rescorer` usage to output of explain and profile for `text_similarity_rank_retriever`
area: Relevance
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ public void onFailure(Exception e) {
});

final boolean isExplain = source != null && source.explain() != null && source.explain();
final boolean isProfile = source != null && source.profile();
Rewriteable.rewriteAndFetch(
original,
searchService.getRewriteContext(
Expand All @@ -607,7 +608,8 @@ public void onFailure(Exception e) {
resolvedIndices,
original.pointInTimeBuilder(),
shouldMinimizeRoundtrips(original),
isExplain
isExplain,
isProfile
),
rewriteListener
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ public QueryRewriteContext newQueryRewriteContext(
null,
null,
null,
false,
false
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public CoordinatorRewriteContext(
null,
null,
null,
false,
false
);
this.dateFieldRangeInfo = dateFieldRangeInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class QueryRewriteContext {
private QueryRewriteInterceptor queryRewriteInterceptor;
private final Boolean ccsMinimizeRoundTrips;
private final boolean isExplain;
private final boolean isProfile;
private Long timeRangeFilterFromMillis;
private boolean trackTimeRangeFilterFrom = true;

Expand All @@ -103,7 +104,8 @@ public QueryRewriteContext(
final PointInTimeBuilder pit,
final QueryRewriteInterceptor queryRewriteInterceptor,
final Boolean ccsMinimizeRoundTrips,
final boolean isExplain
final boolean isExplain,
final boolean isProfile
) {

this.parserConfiguration = parserConfiguration;
Expand All @@ -127,6 +129,7 @@ public QueryRewriteContext(
this.queryRewriteInterceptor = queryRewriteInterceptor;
this.ccsMinimizeRoundTrips = ccsMinimizeRoundTrips;
this.isExplain = isExplain;
this.isProfile = isProfile;
}

public QueryRewriteContext(final XContentParserConfiguration parserConfiguration, final Client client, final LongSupplier nowInMillis) {
Expand All @@ -150,6 +153,7 @@ public QueryRewriteContext(final XContentParserConfiguration parserConfiguration
null,
null,
null,
false,
false
);
}
Expand All @@ -175,6 +179,7 @@ public QueryRewriteContext(
pit,
queryRewriteInterceptor,
ccsMinimizeRoundTrips,
false,
false
);
}
Expand All @@ -189,7 +194,8 @@ public QueryRewriteContext(
final PointInTimeBuilder pit,
final QueryRewriteInterceptor queryRewriteInterceptor,
final Boolean ccsMinimizeRoundTrips,
final boolean isExplain
final boolean isExplain,
final boolean isProfile
) {
this(
parserConfiguration,
Expand All @@ -211,7 +217,8 @@ public QueryRewriteContext(
pit,
queryRewriteInterceptor,
ccsMinimizeRoundTrips,
isExplain
isExplain,
isProfile
);
}

Expand Down Expand Up @@ -324,6 +331,10 @@ public boolean isExplain() {
return this.isExplain;
}

public boolean isProfile() {
return this.isProfile;
}

public NamedWriteableRegistry getWriteableRegistry() {
return writeableRegistry;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ private SearchExecutionContext(
null,
null,
null,
false,
false
);
this.shardId = shardId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,8 @@ public QueryRewriteContext getRewriteContext(
ResolvedIndices resolvedIndices,
PointInTimeBuilder pit,
final Boolean ccsMinimizeRoundTrips,
final boolean isExplain
final boolean isExplain,
final boolean isProfile
) {
return new QueryRewriteContext(
parserConfig,
Expand All @@ -1865,7 +1866,8 @@ public QueryRewriteContext getRewriteContext(
pit,
queryRewriteInterceptor,
ccsMinimizeRoundTrips,
isExplain
isExplain,
isProfile
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2158,7 +2158,7 @@ public QueryRewriteContext getRewriteContext(
PointInTimeBuilder pit,
final Boolean ccsMinimizeRoundTrips
) {
return getRewriteContext(nowInMillis, minTransportVersion, clusterAlias, resolvedIndices, pit, ccsMinimizeRoundTrips, false);
return getRewriteContext(nowInMillis, minTransportVersion, clusterAlias, resolvedIndices, pit, ccsMinimizeRoundTrips, false, false);
}

/**
Expand All @@ -2171,7 +2171,8 @@ public QueryRewriteContext getRewriteContext(
ResolvedIndices resolvedIndices,
PointInTimeBuilder pit,
final Boolean ccsMinimizeRoundTrips,
final boolean isExplain
final boolean isExplain,
final boolean isProfile
) {
return indicesService.getRewriteContext(
nowInMillis,
Expand All @@ -2180,7 +2181,8 @@ public QueryRewriteContext getRewriteContext(
resolvedIndices,
pit,
ccsMinimizeRoundTrips,
isExplain
isExplain,
isProfile
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ public void onResponse(MultiSearchResponse items) {
failures.forEach(ex::addSuppressed);
listener.onFailure(ex);
} else {
results.set(combineInnerRetrieverResults(topDocs, ctx.isExplain()));
boolean enrichResults = ctx.isExplain() || ctx.isProfile();
results.set(combineInnerRetrieverResults(topDocs, enrichResults));
listener.onResponse(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9204000
2 changes: 1 addition & 1 deletion server/src/main/resources/transport/upper_bounds/9.3.csv
Original file line number Diff line number Diff line change
@@ -1 +1 @@
esql_resolve_fields_response_removed_min_tv,9203000
text_similarity_rank_docs_explain_chunks,9204000
Original file line number Diff line number Diff line change
Expand Up @@ -1784,7 +1784,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
NodeClient client = new NodeClient(settings, threadPool, TestProjectResolvers.alwaysThrow());

SearchService searchService = mock(SearchService.class);
when(searchService.getRewriteContext(any(), any(), any(), any(), any(), anyBoolean(), anyBoolean())).thenReturn(
when(searchService.getRewriteContext(any(), any(), any(), any(), any(), anyBoolean(), anyBoolean(), anyBoolean())).thenReturn(
new QueryRewriteContext(null, null, null, null, null, null, null, null, null)
);
ClusterService clusterService = new ClusterService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void testGetTierPreference() {
null,
null,
null,
false,
false
);

Expand Down Expand Up @@ -89,6 +90,7 @@ public void testGetTierPreference() {
null,
null,
null,
false,
false
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ QueryRewriteContext createQueryRewriteContext() {
null,
createMockQueryRewriteInterceptor(),
null,
false,
false
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.elasticsearch.xpack.inference.queries.LegacySemanticKnnVectorQueryRewriteInterceptor.SEMANTIC_KNN_VECTOR_QUERY_REWRITE_INTERCEPTION_SUPPORTED;
import static org.elasticsearch.xpack.inference.queries.LegacySemanticMatchQueryRewriteInterceptor.SEMANTIC_MATCH_QUERY_REWRITE_INTERCEPTION_SUPPORTED;
import static org.elasticsearch.xpack.inference.queries.LegacySemanticSparseVectorQueryRewriteInterceptor.SEMANTIC_SPARSE_VECTOR_QUERY_REWRITE_INTERCEPTION_SUPPORTED;
import static org.elasticsearch.xpack.inference.rank.textsimilarity.TextSimilarityRankDoc.TEXT_SIMILARITY_RANK_DOC_EXPLAIN_CHUNKS;
import static org.elasticsearch.xpack.inference.rank.textsimilarity.TextSimilarityRankRetrieverBuilder.TEXT_SIMILARITY_RERANKER_SNIPPETS;

/**
Expand Down Expand Up @@ -100,7 +101,8 @@ public Set<NodeFeature> getTestFeatures() {
InterceptedInferenceQueryBuilder.NEW_SEMANTIC_QUERY_INTERCEPTORS,
TEXT_SIMILARITY_RERANKER_SNIPPETS,
ModelStats.SEMANTIC_TEXT_USAGE,
SEARCH_USAGE_EXTENDED_DATA
SEARCH_USAGE_EXTENDED_DATA,
TEXT_SIMILARITY_RANK_DOC_EXPLAIN_CHUNKS
)
);
testFeatures.addAll(getFeatures());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public Integer size() {
return size;
}

public int sizeOrDefault() {
return size != null ? size : DEFAULT_SIZE;
}

public String inferenceText() {
return inferenceText;
}
Expand All @@ -100,6 +104,19 @@ public int hashCode() {
return Objects.hash(size, inferenceText, chunkingSettings);
}

@Override
public String toString() {
return "ChunkScorerConfig{"
+ "size="
+ sizeOrDefault()
+ ", inferenceText=["
+ inferenceText
+ ']'
+ ", chunkingSettings="
+ chunkingSettings
+ "}";
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
Expand Down
Loading