-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Text_similarity_reranker retriever rework to be evaluated during rewrite phase #114085
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
pmpailis
merged 17 commits into
elastic:main
from
pmpailis:text_similarity_reranker_rework
Oct 8, 2024
Merged
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5c3386c
semantic reranker rework to be evaluated during rewrite phase
pmpailis e41b879
iter
pmpailis f0d652a
Merge branch 'main' into text_similarity_reranker_rework
elasticmachine 1b34667
iter
pmpailis b2d37f5
Merge branch 'text_similarity_reranker_rework' of github.com:pmpailis…
pmpailis f90d278
addressing PR comments - adding cluster_feature and new transportvers…
pmpailis 73ab244
updating cluster_feature requirements in yml test
pmpailis 4b15561
updating minimum supported versions
pmpailis 34f6368
adding rankdoc serialization tests through AbstractRankDocWireSeriali…
pmpailis 19bea06
Merge branch 'main' into text_similarity_reranker_rework
elasticmachine c1d8987
Merge branch 'main' into text_similarity_reranker_rework
elasticmachine d82cfcc
Merge branch 'main' into text_similarity_reranker_rework
pmpailis a740af1
addressing PR comments - adding validation for text_similarity_rerank…
pmpailis 5bc3d42
Merge branch 'main' into text_similarity_reranker_rework
pmpailis e6e8eb1
Merge branch 'main' into text_similarity_reranker_rework
pmpailis b2f5528
spotless
pmpailis bf8038e
adding missing imports
pmpailis 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
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
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
103 changes: 103 additions & 0 deletions
103
...ain/java/org/elasticsearch/xpack/inference/rank/textsimilarity/TextSimilarityRankDoc.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,103 @@ | ||
/* | ||
* 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.inference.rank.textsimilarity; | ||
|
||
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 org.elasticsearch.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class TextSimilarityRankDoc extends RankDoc { | ||
|
||
public static final String NAME = "text_similarity_rank_doc"; | ||
|
||
public final String inferenceId; | ||
public final String field; | ||
|
||
public TextSimilarityRankDoc(int doc, float score, int shardIndex, String inferenceId, String field) { | ||
super(doc, score, shardIndex); | ||
this.inferenceId = inferenceId; | ||
this.field = field; | ||
} | ||
|
||
public TextSimilarityRankDoc(StreamInput in) throws IOException { | ||
super(in); | ||
inferenceId = in.readString(); | ||
field = in.readString(); | ||
} | ||
|
||
@Override | ||
public Explanation explain(Explanation[] sources, String[] queryNames) { | ||
final String queryAlias = queryNames[0] == null ? "" : "[" + queryNames[0] + "]"; | ||
return Explanation.match( | ||
score, | ||
"text_similarity_reranker match using inference endpoint: [" | ||
+ inferenceId | ||
+ "] on document field: [" | ||
+ field | ||
+ "] matching on source query " | ||
+ queryAlias, | ||
sources | ||
); | ||
} | ||
|
||
@Override | ||
public void doWriteTo(StreamOutput out) throws IOException { | ||
out.writeString(inferenceId); | ||
out.writeString(field); | ||
} | ||
|
||
@Override | ||
public boolean doEquals(RankDoc rd) { | ||
TextSimilarityRankDoc tsrd = (TextSimilarityRankDoc) rd; | ||
return Objects.equals(inferenceId, tsrd.inferenceId) && Objects.equals(field, tsrd.field); | ||
} | ||
|
||
@Override | ||
public int doHashCode() { | ||
return Objects.hash(inferenceId, field); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "TextSimilarityRankDoc{" | ||
+ "doc=" | ||
+ doc | ||
+ ", shardIndex=" | ||
+ shardIndex | ||
+ ", score=" | ||
+ score | ||
+ ", inferenceId=" | ||
+ inferenceId | ||
+ ", field=" | ||
+ field | ||
+ '}'; | ||
} | ||
|
||
@Override | ||
public String getWriteableName() { | ||
return NAME; | ||
} | ||
|
||
@Override | ||
protected void doToXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.field("inferenceId", inferenceId); | ||
builder.field("field", field); | ||
} | ||
|
||
@Override | ||
public TransportVersion getMinimalSupportedVersion() { | ||
return TransportVersions.TEXT_SIMILARITY_RERANKER_QUERY_REWRITE; | ||
} | ||
} |
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.