Skip to content

Commit

Permalink
Update Text Similarity Reranker to Properly Handle Aliases (elastic#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikep86 authored Jan 13, 2025
1 parent 2f944bd commit 264d1c2
Show file tree
Hide file tree
Showing 5 changed files with 92 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 static 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 @@ -52,7 +52,8 @@ public Set<NodeFeature> getTestFeatures() {
SEMANTIC_MATCH_QUERY_REWRITE_INTERCEPTION_SUPPORTED,
SEMANTIC_SPARSE_VECTOR_QUERY_REWRITE_INTERCEPTION_SUPPORTED,
SemanticInferenceMetadataFieldsMapper.EXPLICIT_NULL_FIXES,
SEMANTIC_KNN_VECTOR_QUERY_REWRITE_INTERCEPTION_SUPPORTED
SEMANTIC_KNN_VECTOR_QUERY_REWRITE_INTERCEPTION_SUPPORTED,
TextSimilarityRankRetrieverBuilder.TEXT_SIMILARITY_RERANKER_ALIAS_HANDLING_FIX
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public class TextSimilarityRankRetrieverBuilder extends CompoundRetrieverBuilder
"text_similarity_reranker_retriever_composition_supported",
true
);
public static final NodeFeature TEXT_SIMILARITY_RERANKER_ALIAS_HANDLING_FIX = new NodeFeature(
"text_similarity_reranker_alias_handling_fix",
true
);

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 @@ -216,3 +216,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 264d1c2

Please sign in to comment.