Skip to content

Commit

Permalink
[8.16] Update Text Similarity Reranker to Properly Handle Aliases (el…
Browse files Browse the repository at this point in the history
…astic#120062) (elastic#120077)

* Update Text Similarity Reranker to Properly Handle Aliases (elastic#120062)

(cherry picked from commit 264d1c2)

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

* Fix compilation error
  • Loading branch information
Mikep86 authored Jan 13, 2025
1 parent c6141dd commit 7141ff1
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/120062.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 120062
summary: Update Text Similarity Reranker to Properly Handle Aliases
area: Ranking
type: bug
issues:
- 119617
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void processFetch(SearchContext searchContext) {
// FetchSearchResult#shardResult()
SearchHits hits = fetchSearchResult.hits();
RankFeatureShardResult featureRankShardResult = (RankFeatureShardResult) rankFeaturePhaseRankShardContext
.buildRankFeatureShardResult(hits, searchContext.shardTarget().getShardId().id());
.buildRankFeatureShardResult(hits, searchContext.request().shardRequestIndex());
// save the result in the search context
// need to add profiling info as well available from fetch
if (featureRankShardResult != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public Set<NodeFeature> getTestFeatures() {
SemanticTextFieldMapper.SEMANTIC_TEXT_IN_OBJECT_FIELD_FIX,
SemanticTextFieldMapper.SEMANTIC_TEXT_SINGLE_FIELD_UPDATE_FIX,
SemanticTextFieldMapper.SEMANTIC_TEXT_DELETE_FIX,
SemanticTextFieldMapper.SEMANTIC_TEXT_ZERO_SIZE_FIX
SemanticTextFieldMapper.SEMANTIC_TEXT_ZERO_SIZE_FIX,
TextSimilarityRankRetrieverBuilder.TEXT_SIMILARITY_RERANKER_ALIAS_HANDLING_FIX
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public class TextSimilarityRankRetrieverBuilder extends CompoundRetrieverBuilder
public static final NodeFeature TEXT_SIMILARITY_RERANKER_COMPOSITION_SUPPORTED = new NodeFeature(
"text_similarity_reranker_retriever_composition_supported"
);
public static final NodeFeature TEXT_SIMILARITY_RERANKER_ALIAS_HANDLING_FIX = new NodeFeature(
"text_similarity_reranker_alias_handling_fix"
);

public static final ParseField RETRIEVER_FIELD = new ParseField("retriever");
public static final ParseField INFERENCE_ID_FIELD = new ParseField("inference_id");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,82 @@ setup:
- close_to: { hits.hits.0._explanation.value: { value: 0.4, error: 0.000001 } }
- match: {hits.hits.0._explanation.description: "/text_similarity_reranker.match.using.inference.endpoint:.\\[my-rerank-model\\].on.document.field:.\\[text\\].*/" }
- match: {hits.hits.0._explanation.details.0.description: "/weight.*science.*/" }

---
"text similarity reranker properly handles aliases":
- requires:
cluster_features: "text_similarity_reranker_alias_handling_fix"
reason: Test for alias handling fix

# Create an empty index that will have an earlier shard index than the index with the desired result when referenced
# via the alias
- do:
indices.create:
index: first-test-index
body:
mappings:
properties:
text:
type: text
topic:
type: keyword
subtopic:
type: keyword

- do:
indices.create:
index: second-test-index
body:
settings:
number_of_shards: 2
number_of_replicas: 0
mappings:
properties:
text:
type: text
topic:
type: keyword
subtopic:
type: keyword

- do:
indices.put_alias:
index: first-test-index
name: test-alias

- do:
indices.put_alias:
index: second-test-index
name: test-alias

- do:
index:
index: second-test-index
id: doc_1
body:
text: "As seen from Earth, a solar eclipse happens when the Moon is directly between the Earth and the Sun."
topic: [ "science" ]
subtopic: [ "technology" ]
refresh: true

- do:
search:
index: test-alias
body:
track_total_hits: true
retriever:
text_similarity_reranker:
retriever:
standard:
query:
term:
topic: "science"
rank_window_size: 10
inference_id: my-rerank-model
inference_text: "How often does the moon hide the sun?"
field: text
size: 10

- match: { hits.total.value: 1 }
- length: { hits.hits: 1 }
- match: { hits.hits.0._id: "doc_1" }

0 comments on commit 7141ff1

Please sign in to comment.