Skip to content

Commit 264d1c2

Browse files
authored
Update Text Similarity Reranker to Properly Handle Aliases (elastic#120062)
1 parent 2f944bd commit 264d1c2

File tree

5 files changed

+92
-2
lines changed

5 files changed

+92
-2
lines changed

docs/changelog/120062.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 120062
2+
summary: Update Text Similarity Reranker to Properly Handle Aliases
3+
area: Ranking
4+
type: bug
5+
issues:
6+
- 119617

server/src/main/java/org/elasticsearch/search/rank/feature/RankFeatureShardPhase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static void processFetch(SearchContext searchContext) {
8383
// FetchSearchResult#shardResult()
8484
SearchHits hits = fetchSearchResult.hits();
8585
RankFeatureShardResult featureRankShardResult = (RankFeatureShardResult) rankFeaturePhaseRankShardContext
86-
.buildRankFeatureShardResult(hits, searchContext.shardTarget().getShardId().id());
86+
.buildRankFeatureShardResult(hits, searchContext.request().shardRequestIndex());
8787
// save the result in the search context
8888
// need to add profiling info as well available from fetch
8989
if (featureRankShardResult != null) {

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferenceFeatures.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public Set<NodeFeature> getTestFeatures() {
5252
SEMANTIC_MATCH_QUERY_REWRITE_INTERCEPTION_SUPPORTED,
5353
SEMANTIC_SPARSE_VECTOR_QUERY_REWRITE_INTERCEPTION_SUPPORTED,
5454
SemanticInferenceMetadataFieldsMapper.EXPLICIT_NULL_FIXES,
55-
SEMANTIC_KNN_VECTOR_QUERY_REWRITE_INTERCEPTION_SUPPORTED
55+
SEMANTIC_KNN_VECTOR_QUERY_REWRITE_INTERCEPTION_SUPPORTED,
56+
TextSimilarityRankRetrieverBuilder.TEXT_SIMILARITY_RERANKER_ALIAS_HANDLING_FIX
5657
);
5758
}
5859
}

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/rank/textsimilarity/TextSimilarityRankRetrieverBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public class TextSimilarityRankRetrieverBuilder extends CompoundRetrieverBuilder
4444
"text_similarity_reranker_retriever_composition_supported",
4545
true
4646
);
47+
public static final NodeFeature TEXT_SIMILARITY_RERANKER_ALIAS_HANDLING_FIX = new NodeFeature(
48+
"text_similarity_reranker_alias_handling_fix",
49+
true
50+
);
4751

4852
public static final ParseField RETRIEVER_FIELD = new ParseField("retriever");
4953
public static final ParseField INFERENCE_ID_FIELD = new ParseField("inference_id");

x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/70_text_similarity_rank_retriever.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,82 @@ setup:
216216
- close_to: { hits.hits.0._explanation.value: { value: 0.4, error: 0.000001 } }
217217
- match: {hits.hits.0._explanation.description: "/text_similarity_reranker.match.using.inference.endpoint:.\\[my-rerank-model\\].on.document.field:.\\[text\\].*/" }
218218
- match: {hits.hits.0._explanation.details.0.description: "/weight.*science.*/" }
219+
220+
---
221+
"text similarity reranker properly handles aliases":
222+
- requires:
223+
cluster_features: "text_similarity_reranker_alias_handling_fix"
224+
reason: Test for alias handling fix
225+
226+
# Create an empty index that will have an earlier shard index than the index with the desired result when referenced
227+
# via the alias
228+
- do:
229+
indices.create:
230+
index: first-test-index
231+
body:
232+
mappings:
233+
properties:
234+
text:
235+
type: text
236+
topic:
237+
type: keyword
238+
subtopic:
239+
type: keyword
240+
241+
- do:
242+
indices.create:
243+
index: second-test-index
244+
body:
245+
settings:
246+
number_of_shards: 2
247+
number_of_replicas: 0
248+
mappings:
249+
properties:
250+
text:
251+
type: text
252+
topic:
253+
type: keyword
254+
subtopic:
255+
type: keyword
256+
257+
- do:
258+
indices.put_alias:
259+
index: first-test-index
260+
name: test-alias
261+
262+
- do:
263+
indices.put_alias:
264+
index: second-test-index
265+
name: test-alias
266+
267+
- do:
268+
index:
269+
index: second-test-index
270+
id: doc_1
271+
body:
272+
text: "As seen from Earth, a solar eclipse happens when the Moon is directly between the Earth and the Sun."
273+
topic: [ "science" ]
274+
subtopic: [ "technology" ]
275+
refresh: true
276+
277+
- do:
278+
search:
279+
index: test-alias
280+
body:
281+
track_total_hits: true
282+
retriever:
283+
text_similarity_reranker:
284+
retriever:
285+
standard:
286+
query:
287+
term:
288+
topic: "science"
289+
rank_window_size: 10
290+
inference_id: my-rerank-model
291+
inference_text: "How often does the moon hide the sun?"
292+
field: text
293+
size: 10
294+
295+
- match: { hits.total.value: 1 }
296+
- length: { hits.hits: 1 }
297+
- match: { hits.hits.0._id: "doc_1" }

0 commit comments

Comments
 (0)