Skip to content

Commit 7141ff1

Browse files
authored
[8.16] Update Text Similarity Reranker to Properly Handle Aliases (#120062) (#120077)
* Update Text Similarity Reranker to Properly Handle Aliases (#120062) (cherry picked from commit 264d1c2) # Conflicts: # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferenceFeatures.java * Fix compilation error
1 parent c6141dd commit 7141ff1

File tree

5 files changed

+91
-2
lines changed

5 files changed

+91
-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 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
@@ -40,7 +40,8 @@ public Set<NodeFeature> getTestFeatures() {
4040
SemanticTextFieldMapper.SEMANTIC_TEXT_IN_OBJECT_FIELD_FIX,
4141
SemanticTextFieldMapper.SEMANTIC_TEXT_SINGLE_FIELD_UPDATE_FIX,
4242
SemanticTextFieldMapper.SEMANTIC_TEXT_DELETE_FIX,
43-
SemanticTextFieldMapper.SEMANTIC_TEXT_ZERO_SIZE_FIX
43+
SemanticTextFieldMapper.SEMANTIC_TEXT_ZERO_SIZE_FIX,
44+
TextSimilarityRankRetrieverBuilder.TEXT_SIMILARITY_RERANKER_ALIAS_HANDLING_FIX
4445
);
4546
}
4647
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public class TextSimilarityRankRetrieverBuilder extends CompoundRetrieverBuilder
4343
public static final NodeFeature TEXT_SIMILARITY_RERANKER_COMPOSITION_SUPPORTED = new NodeFeature(
4444
"text_similarity_reranker_retriever_composition_supported"
4545
);
46+
public static final NodeFeature TEXT_SIMILARITY_RERANKER_ALIAS_HANDLING_FIX = new NodeFeature(
47+
"text_similarity_reranker_alias_handling_fix"
48+
);
4649

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

0 commit comments

Comments
 (0)