-
Notifications
You must be signed in to change notification settings - Fork 21
Add Import Capability for externally run Search Evaluation #120
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
Open
epugh
wants to merge
36
commits into
opensearch-project:main
Choose a base branch
from
epugh:use_post_to_import_experiment_results
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+9,123
−23
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
128f739
Import Search Evaluation
epugh 662b3f5
Use correct package path
epugh ea68771
working POC style code
epugh 117723c
Remove extra code that is not used
epugh e158809
enhance the test to reflect modern data structure for metrics
epugh fe0f9c3
Handle async failures better
epugh bf414db
Update fields to the new esci schema
epugh 53233e5
150 query set imported, easy way to test import feature plus have act…
epugh ec8a3f6
Fix null safety in RestPostExperimentAction and update test expectations
sstults d87239a
Add validation to all fields in the request
sstults 621624c
Add limit to the number of results we process
sstults 797d999
Add logic to ERROR results if one of the entries fails, if all succee…
sstults 614a78e
Changed the constant we reference for queryText
sstults b258ad2
Update src/test/data-esci/README.md
epugh 12cb96a
Merge remote-tracking branch 'upstream/main' into use_post_to_import_…
epugh ec0ba8f
Clean up changelog
epugh 6530990
Merge remote-tracking branch 'upstream/main' into use_post_to_import_…
epugh 517c769
Responding to feedback
epugh 2483142
Merge remote-tracking branch 'upstream/main' into use_post_to_import_…
epugh 4132524
Correct the filename and provide some instructions on using it
epugh 8d9443e
Correct the filename and provide some instructions on using it
epugh f447486
Merge branch 'opensearch-project:main' into use_post_to_import_experi…
epugh 0c5ee12
Now have a way of testing a real export from another tool (Quepid) in…
epugh f2c25fd
Ensure that Integer ratings do not cause problems by making them strings
epugh bf70771
Merge remote-tracking branch 'upstream/main' into use_post_to_import_…
epugh 3c1f109
Demonstrate importing a pointwise experiment.
epugh dea5c09
Language tweak
epugh dc97ef5
When importing, you need the experimentId to tie all the evaluation r…
epugh a670d37
Prep to have a pairwise example too
epugh dd9d1d5
Refactoring to prep for adding importPairwise experiment
epugh e9f633d
Introduce capablity to import a PAIRWISE_COMPARISON as well.
epugh d5476fb
Script demonstrating pairwise import.
epugh f7b5f3e
Fix constnats (respond to feedback)
epugh 7b21763
lint
epugh 914a79b
Reduce level of detail, prompted by feedback
epugh e3f1d90
Allow these demos to be run in any opensearch environment that has SR…
epugh 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
147 changes: 147 additions & 0 deletions
147
src/main/java/org/opensearch/searchrelevance/rest/RestPostExperimentAction.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,147 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.searchrelevance.rest; | ||
|
||
import static java.util.Collections.singletonList; | ||
import static org.opensearch.rest.RestRequest.Method.POST; | ||
import static org.opensearch.searchrelevance.common.PluginConstants.EVALUATION_RESULT_LIST; | ||
import static org.opensearch.searchrelevance.common.PluginConstants.EXPERIMENTS_URI; | ||
import static org.opensearch.searchrelevance.common.PluginConstants.JUDGMENT_LIST; | ||
import static org.opensearch.searchrelevance.common.PluginConstants.QUERYSET_ID; | ||
import static org.opensearch.searchrelevance.common.PluginConstants.RESULTS; | ||
import static org.opensearch.searchrelevance.common.PluginConstants.SEARCH_CONFIGURATION_LIST; | ||
import static org.opensearch.searchrelevance.common.PluginConstants.SIZE; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.opensearch.action.index.IndexResponse; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.core.rest.RestStatus; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.core.xcontent.XContentParser; | ||
import org.opensearch.rest.BaseRestHandler; | ||
import org.opensearch.rest.BytesRestResponse; | ||
import org.opensearch.rest.RestRequest; | ||
import org.opensearch.searchrelevance.exception.SearchRelevanceException; | ||
import org.opensearch.searchrelevance.model.ExperimentType; | ||
import org.opensearch.searchrelevance.settings.SearchRelevanceSettingsAccessor; | ||
import org.opensearch.searchrelevance.transport.experiment.PostExperimentAction; | ||
import org.opensearch.searchrelevance.transport.experiment.PostExperimentRequest; | ||
import org.opensearch.searchrelevance.utils.ParserUtils; | ||
import org.opensearch.transport.client.node.NodeClient; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
|
||
@Log4j2 | ||
/** | ||
* Rest Action to facilitate requests to import a experiment. | ||
*/ | ||
@AllArgsConstructor | ||
public class RestPostExperimentAction extends BaseRestHandler { | ||
private static final String POST_EXPERIMENT_ACTION = "post_experiment_action"; | ||
private SearchRelevanceSettingsAccessor settingsAccessor; | ||
|
||
@Override | ||
public String getName() { | ||
return POST_EXPERIMENT_ACTION; | ||
} | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return singletonList(new Route(POST, EXPERIMENTS_URI)); | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { | ||
if (!settingsAccessor.isWorkbenchEnabled()) { | ||
return channel -> channel.sendResponse(new BytesRestResponse(RestStatus.FORBIDDEN, "Search Relevance Workbench is disabled")); | ||
} | ||
|
||
PostExperimentRequest createRequest = null; | ||
XContentParser parser = request.contentParser(); | ||
Map<String, Object> source = parser.map(); | ||
|
||
String typeString = (String) source.get("type"); | ||
ExperimentType type; | ||
try { | ||
type = ExperimentType.valueOf(typeString); | ||
} catch (IllegalArgumentException | NullPointerException e) { | ||
throw new IllegalArgumentException("Invalid or missing experiment type", e); | ||
} | ||
|
||
if (type == ExperimentType.POINTWISE_EVALUATION) { | ||
String querySetId = (String) source.get(QUERYSET_ID); | ||
List<String> searchConfigurationList = ParserUtils.convertObjToList(source, SEARCH_CONFIGURATION_LIST); | ||
if (searchConfigurationList.size() != 1) { | ||
throw new IOException("Must have exactly one search configuration. Had " + searchConfigurationList.size() + " size."); | ||
} | ||
Integer sizeObj = (Integer) source.get(SIZE); | ||
int size = sizeObj != null ? sizeObj.intValue() : 10; // Default size to 10 if not provided | ||
|
||
List<String> judgmentList = ParserUtils.convertObjToList(source, JUDGMENT_LIST); | ||
if (judgmentList.size() != 1) { | ||
throw new IOException("Must have exactly one judgment list. Had " + judgmentList.size() + " size."); | ||
} | ||
|
||
List<Map<String, Object>> evaluationResultList = ParserUtils.convertObjToListOfMaps(source, EVALUATION_RESULT_LIST); | ||
|
||
createRequest = new PostExperimentRequest( | ||
type, | ||
querySetId, | ||
searchConfigurationList, | ||
judgmentList, | ||
size, | ||
evaluationResultList, | ||
null | ||
); | ||
} else if (type == ExperimentType.PAIRWISE_COMPARISON) { | ||
String querySetId = (String) source.get(QUERYSET_ID); | ||
List<String> searchConfigurationList = ParserUtils.convertObjToList(source, SEARCH_CONFIGURATION_LIST); | ||
if (searchConfigurationList.size() != 2) { | ||
throw new IOException("Must have exactly two search configurations. Had " + searchConfigurationList.size() + " size."); | ||
} | ||
Integer sizeObj = (Integer) source.get(SIZE); | ||
int size = sizeObj != null ? sizeObj.intValue() : 10; // Default size to 10 if not provided | ||
|
||
List<Map<String, Object>> results = ParserUtils.convertObjToListOfMaps(source, RESULTS); | ||
|
||
createRequest = new PostExperimentRequest(type, querySetId, searchConfigurationList, List.of(), size, null, results); | ||
} else { | ||
throw new SearchRelevanceException("Importing experimentType" + type + " is not supported", RestStatus.BAD_REQUEST); | ||
} | ||
|
||
PostExperimentRequest finalCreateRequest = createRequest; | ||
return channel -> client.execute(PostExperimentAction.INSTANCE, finalCreateRequest, new ActionListener<IndexResponse>() { | ||
@Override | ||
public void onResponse(IndexResponse response) { | ||
try { | ||
XContentBuilder builder = channel.newBuilder(); | ||
builder.startObject(); | ||
builder.field("experiment_id", response.getId()); | ||
builder.field("experiment_result", response.getResult()); | ||
builder.endObject(); | ||
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder)); | ||
} catch (IOException e) { | ||
onFailure(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
try { | ||
channel.sendResponse(new BytesRestResponse(channel, RestStatus.INTERNAL_SERVER_ERROR, e)); | ||
} catch (IOException ex) { | ||
log.error("Failed to send error response", ex); | ||
} | ||
} | ||
}); | ||
} | ||
} |
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
src/main/java/org/opensearch/searchrelevance/transport/experiment/PostExperimentAction.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 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.searchrelevance.transport.experiment; | ||
|
||
import static org.opensearch.searchrelevance.common.PluginConstants.TRANSPORT_ACTION_NAME_PREFIX; | ||
|
||
import org.opensearch.action.ActionType; | ||
import org.opensearch.action.index.IndexResponse; | ||
|
||
/** | ||
* External Action for public facing RestPostExperimentAction | ||
*/ | ||
public class PostExperimentAction extends ActionType<IndexResponse> { | ||
/** The name of this action */ | ||
public static final String NAME = TRANSPORT_ACTION_NAME_PREFIX + "experiment/import"; | ||
|
||
/** An instance of this action */ | ||
public static final PostExperimentAction INSTANCE = new PostExperimentAction(); | ||
|
||
private PostExperimentAction() { | ||
super(NAME, IndexResponse::new); | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please update the error handling here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you share some more detail on what you are looking for?