Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.15] Properly handle filters on TextSimilarityRank retriever (#111673) #111675

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/111673.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 111673
summary: Properly handle filters on `TextSimilarityRank` retriever
area: Ranking
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public TextSimilarityRankRetrieverBuilder(

@Override
public void extractToSearchSourceBuilder(SearchSourceBuilder searchSourceBuilder, boolean compoundUsed) {
retrieverBuilder.getPreFilterQueryBuilders().addAll(preFilterQueryBuilders);
retrieverBuilder.extractToSearchSourceBuilder(searchSourceBuilder, compoundUsed);

// Combining with other rank builder (such as RRF) is not supported yet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ setup:
type: text
topic:
type: keyword
subtopic:
type: keyword

- do:
index:
Expand All @@ -37,6 +39,7 @@ setup:
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:
Expand All @@ -46,6 +49,7 @@ setup:
body:
text: "The phases of the Moon come from the position of the Moon relative to the Earth and Sun."
topic: ["science"]
subtopic: ["astronomy"]
refresh: true

- do:
Expand Down Expand Up @@ -88,3 +92,35 @@ setup:
- match: { hits.hits.1._id: "doc_1" }
- match: { hits.hits.1._rank: 2 }
- close_to: { hits.hits.1._score: { value: 0.2, error: 0.001 } }

---
"Simple text similarity rank retriever and filtering":

- do:
search:
index: test-index
body:
track_total_hits: true
fields: [ "text", "topic" ]
retriever:
text_similarity_reranker:
retriever:
standard:
query:
term:
topic: "science"
filter:
term:
subtopic: "technology"
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" }
- match: { hits.hits.0._rank: 1 }
- close_to: { hits.hits.0._score: { value: 0.2, error: 0.001 } }