-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[8.19] Pinned retriever (#126401) #127639
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
Merged
mridula-s109
merged 5 commits into
elastic:8.19
from
mridula-s109:backport/8.19/pr-126401
May 2, 2025
+1,295
−7
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2933f25
Pinned retriever (#126401)
mridula-s109 56bd083
Merge branch '8.19' into backport/8.19/pr-126401
mridula-s109 028f636
Fixed the compile issue
mridula-s109 e89a0fb
changed pinned retriever name
mridula-s109 4bfe468
Merge branch '8.19' into backport/8.19/pr-126401
mridula-s109 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 126401 | ||
| summary: Add pinned retriever | ||
| area: Relevance | ||
| type: enhancement | ||
| issues: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...gin/rank-rrf/src/yamlRestTest/resources/rest-api-spec/test/rrf/950_pinned_interaction.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| setup: | ||
| - requires: | ||
| cluster_features: 'pinned_retriever_supported' | ||
| reason: 'test requires pinned retriever implementation' | ||
| - do: | ||
| indices.create: | ||
| index: test-index1 | ||
|
|
||
| - do: | ||
| bulk: | ||
| refresh: true | ||
| index: test-index1 | ||
| body: | ||
| - index: | ||
| _id: doc1 | ||
| - { "text": "document one" } | ||
| - index: | ||
| _id: doc2 | ||
| - { "text": "document two" } | ||
| - index: | ||
| _id: doc3 | ||
| - { "text": "document three" } | ||
| - index: | ||
| _id: doc4 | ||
| - { "text": "document four" } | ||
| - index: | ||
| _id: doc5 | ||
| - { "text": "document five" } | ||
|
|
||
| --- | ||
| "rrf combined with pinned retriever": | ||
| - skip: { features: headers } | ||
| - do: | ||
| headers: | ||
| Content-Type: application/json | ||
| search: | ||
| index: test-index1 | ||
| body: | ||
| retriever: | ||
| pinned: | ||
| ids: ["doc1"] | ||
| retriever: | ||
| rrf: | ||
| retrievers: [ | ||
| { | ||
| standard: { | ||
| query: { | ||
| term: { text: "document" } | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| standard: { | ||
| query: { | ||
| term: { text: "three" } | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| rank_window_size: 10 | ||
|
|
||
| - match: { hits.total.value: 5 } | ||
| - match: { hits.hits.0._id: doc1 } | ||
| - match: { hits.hits.0._score: 1.7014122E38 } | ||
| - match: { hits.hits.1._id: doc3 } | ||
| - match: { hits.hits.1._score < 100.0 } | ||
| - match: { hits.hits.2._id: doc2 } | ||
|
|
||
| --- | ||
| "rrf with pinned retriever as a sub-retriever": | ||
| - skip: { features: headers } | ||
| - do: | ||
| headers: { Content-Type: application/json } | ||
| search: | ||
| index: test-index1 | ||
| body: | ||
| retriever: | ||
| rrf: | ||
| retrievers: | ||
| - | ||
| standard: | ||
| query: | ||
| match: { text: "document" } | ||
| - | ||
| pinned: | ||
| ids: ["doc4", "doc5"] | ||
| retriever: | ||
| standard: | ||
| query: | ||
| match: { text: "document" } | ||
|
|
||
| - match: { hits.total.value: 5 } | ||
| - match: { hits.hits.0._id: doc1 } | ||
| - lt: { hits.hits.0._score: 100.0 } | ||
| - match: { hits.hits.1._id: doc4 } | ||
| - match: { hits.hits.2._id: doc5 } | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...rc/main/java/org/elasticsearch/xpack/searchbusinessrules/SearchBusinessRulesFeatures.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.searchbusinessrules; | ||
|
|
||
| import org.elasticsearch.features.FeatureSpecification; | ||
| import org.elasticsearch.features.NodeFeature; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| import static org.elasticsearch.xpack.searchbusinessrules.retriever.PinnedRetrieverBuilder.PINNED_RETRIEVER_FEATURE; | ||
|
|
||
| public class SearchBusinessRulesFeatures implements FeatureSpecification { | ||
|
|
||
| @Override | ||
| public Set<NodeFeature> getFeatures() { | ||
| return Set.of(); | ||
| } | ||
|
|
||
| @Override | ||
| public Set<NodeFeature> getTestFeatures() { | ||
| return Set.of(PINNED_RETRIEVER_FEATURE); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...es/src/main/java/org/elasticsearch/xpack/searchbusinessrules/retriever/PinnedRankDoc.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.searchbusinessrules.retriever; | ||
|
|
||
| import org.apache.lucene.search.Explanation; | ||
| import org.elasticsearch.TransportVersion; | ||
| import org.elasticsearch.TransportVersions; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.search.rank.RankDoc; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Objects; | ||
|
|
||
| public class PinnedRankDoc extends RankDoc { | ||
| public static final String NAME = "pinned_rank_doc"; | ||
|
|
||
| private final boolean isPinned; | ||
|
|
||
| public PinnedRankDoc(int docId, float score, int shardIndex, boolean isPinned) { | ||
| super(docId, score, shardIndex); | ||
| this.isPinned = isPinned; | ||
| } | ||
|
|
||
| public PinnedRankDoc(StreamInput in) throws IOException { | ||
| super(in); | ||
| this.isPinned = in.readBoolean(); | ||
| } | ||
|
|
||
| public boolean isPinned() { | ||
| return isPinned; | ||
| } | ||
|
|
||
| @Override | ||
| public Explanation explain(Explanation[] sources, String[] queryNames) { | ||
| if (isPinned) { | ||
| return Explanation.match(score, "Pinned document, original explanation:", sources); | ||
| } else { | ||
| return super.explain(sources, queryNames); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return super.toString() + ", isPinned=" + isPinned; | ||
| } | ||
|
|
||
| @Override | ||
| public String getWriteableName() { | ||
| return NAME; | ||
| } | ||
|
|
||
| @Override | ||
| protected void doWriteTo(StreamOutput out) throws IOException { | ||
| out.writeBoolean(isPinned); | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean doEquals(RankDoc rd) { | ||
| if (rd instanceof PinnedRankDoc other) { | ||
| return this.isPinned == other.isPinned; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected int doHashCode() { | ||
| return Objects.hash(super.doHashCode(), isPinned); | ||
| } | ||
|
|
||
| @Override | ||
| public TransportVersion getMinimalSupportedVersion() { | ||
| return TransportVersions.PINNED_RETRIEVER; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.