Skip to content

Commit c15274e

Browse files
authored
Add ignoreFailure and pipelineContext (#152)
* Add ignoreFailure and pipelineContext Signed-off-by: Mingshi Liu <mingshl@amazon.com> * use lowercase Signed-off-by: Mingshi Liu <mingshl@amazon.com> --------- Signed-off-by: Mingshi Liu <mingshl@amazon.com>
1 parent 25d3e08 commit c15274e

File tree

6 files changed

+37
-24
lines changed

6 files changed

+37
-24
lines changed

src/main/java/org/opensearch/search/relevance/SearchRelevancePlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public List<SearchExtSpec<?>> getSearchExts() {
119119
}
120120

121121
@Override
122-
public Map<String, Processor.Factory<SearchResponseProcessor>> getResponseProcessors(Processor.Parameters parameters) {
122+
public Map<String, Processor.Factory<SearchResponseProcessor>> getResponseProcessors(Parameters parameters) {
123123
return Map.of(PersonalizeRankingResponseProcessor.TYPE, new PersonalizeRankingResponseProcessor.Factory(PersonalizeClientSettings.getClientSettings(parameters.env.settings())),
124124
KendraRankingResponseProcessor.TYPE, new KendraRankingResponseProcessor.Factory(this.kendraClientSettings));
125125
}

src/main/java/org/opensearch/search/relevance/configuration/ConfigurationUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class ConfigurationUtils {
2727
* Get result transformer configurations from Search Request
2828
*
2929
* @param settings all index settings configured for this plugin
30+
* @param resultTransformerMap map of transformed results
3031
* @return ordered and validated list of result transformers, empty list if not specified
3132
*/
3233
public static List<ResultTransformerConfiguration> getResultTransformersFromIndexConfiguration(Settings settings,

src/main/java/org/opensearch/search/relevance/transformer/kendraintelligentranking/pipeline/KendraRankingResponseProcessor.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.opensearch.search.SearchHits;
1818
import org.opensearch.search.aggregations.InternalAggregations;
1919
import org.opensearch.search.internal.InternalSearchResponse;
20+
import org.opensearch.search.pipeline.AbstractProcessor;
2021
import org.opensearch.search.pipeline.Processor;
2122
import org.opensearch.search.pipeline.SearchResponseProcessor;
2223
import org.opensearch.search.profile.SearchProfileShardResults;
@@ -35,7 +36,7 @@
3536
/**
3637
* This is a {@link SearchResponseProcessor} that applies kendra intelligence ranking
3738
*/
38-
public class KendraRankingResponseProcessor implements SearchResponseProcessor {
39+
public class KendraRankingResponseProcessor extends AbstractProcessor implements SearchResponseProcessor {
3940
/**
4041
* key to reference this processor type from a search pipeline
4142
*/
@@ -54,13 +55,14 @@ public class KendraRankingResponseProcessor implements SearchResponseProcessor {
5455
*
5556
* @param tag processor tag
5657
* @param description processor description
58+
* @param ignoreFailure processor ignoreFailure config
5759
* @param titleField titleField applied to kendra re-ranking
5860
* @param bodyField bodyField applied to kendra re-ranking
5961
* @param inputDocLimit docLimit applied to kendra re-ranking
6062
* @param kendraClient kendraClient to connect with kendra
6163
*/
62-
public KendraRankingResponseProcessor(String tag, String description, List<String> titleField, List<String> bodyField, Integer inputDocLimit, KendraHttpClient kendraClient) {
63-
super();
64+
public KendraRankingResponseProcessor(String tag, String description, boolean ignoreFailure, List<String> titleField, List<String> bodyField, Integer inputDocLimit, KendraHttpClient kendraClient) {
65+
super(tag, description, ignoreFailure);
6466
this.titleField = titleField;
6567
this.bodyField = bodyField;
6668
this.tag = tag;
@@ -99,6 +101,7 @@ public String getDescription() {
99101
return description;
100102
}
101103

104+
102105
/**
103106
* Transform the response hit and apply kendra re-ranking logic
104107
*/
@@ -156,7 +159,9 @@ public KendraRankingResponseProcessor create(
156159
Map<String, Processor.Factory<SearchResponseProcessor>> processorFactories,
157160
String tag,
158161
String description,
159-
Map<String, Object> config
162+
boolean ignoreFailure,
163+
Map<String, Object> config,
164+
PipelineContext pipelineContext
160165
) throws Exception {
161166
List<String> titleField = Collections.singletonList(ConfigurationUtils.readOptionalStringProperty(TYPE, tag, config, "title_field"));
162167
List<String> bodyField = Collections.singletonList(ConfigurationUtils.readStringProperty(TYPE, tag, config, "body_field"));
@@ -168,7 +173,7 @@ public KendraRankingResponseProcessor create(
168173
} else {
169174
docLimit = Integer.parseInt(inputDocLimit);
170175
}
171-
return new KendraRankingResponseProcessor(tag, description, titleField, bodyField, docLimit, kendraClient);
176+
return new KendraRankingResponseProcessor(tag, description, ignoreFailure, titleField, bodyField, docLimit, kendraClient);
172177
}
173178
}
174179
}

src/main/java/org/opensearch/search/relevance/transformer/personalizeintelligentranking/PersonalizeRankingResponseProcessor.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.opensearch.search.SearchHits;
1818
import org.opensearch.search.aggregations.InternalAggregations;
1919
import org.opensearch.search.internal.InternalSearchResponse;
20+
import org.opensearch.search.pipeline.AbstractProcessor;
2021
import org.opensearch.search.pipeline.Processor;
2122
import org.opensearch.search.pipeline.SearchResponseProcessor;
2223
import org.opensearch.search.profile.SearchProfileShardResults;
@@ -36,7 +37,7 @@
3637
/**
3738
* This is a {@link SearchResponseProcessor} that applies Personalized intelligent ranking
3839
*/
39-
public class PersonalizeRankingResponseProcessor implements SearchResponseProcessor {
40+
public class PersonalizeRankingResponseProcessor extends AbstractProcessor implements SearchResponseProcessor {
4041

4142
private static final Logger logger = LogManager.getLogger(PersonalizeRankingResponseProcessor.class);
4243

@@ -51,14 +52,16 @@ public class PersonalizeRankingResponseProcessor implements SearchResponseProces
5152
*
5253
* @param tag processor tag
5354
* @param description processor description
55+
* @param ignoreFailure processor ignoreFailure config
5456
* @param rankerConfig personalize ranker config
5557
* @param client personalize client
5658
*/
5759
public PersonalizeRankingResponseProcessor(String tag,
5860
String description,
61+
boolean ignoreFailure,
5962
PersonalizeIntelligentRankerConfiguration rankerConfig,
6063
PersonalizeClient client) {
61-
super();
64+
super(tag, description, ignoreFailure);
6265
this.tag = tag;
6366
this.description = description;
6467
this.rankerConfig = rankerConfig;
@@ -150,7 +153,7 @@ public Factory(PersonalizeClientSettings settings) {
150153
}
151154

152155
@Override
153-
public PersonalizeRankingResponseProcessor create(Map<String, Processor.Factory<SearchResponseProcessor>> processorFactories, String tag, String description, Map<String, Object> config) throws Exception {
156+
public PersonalizeRankingResponseProcessor create(Map<String, Processor.Factory<SearchResponseProcessor>> processorFactories, String tag, String description, boolean ignoreFailure, Map<String, Object> config, PipelineContext pipelineContext) throws Exception {
154157
String personalizeCampaign = ConfigurationUtils.readStringProperty(TYPE, tag, config, CAMPAIGN_ARN_CONFIG_NAME);
155158
String iamRoleArn = ConfigurationUtils.readOptionalStringProperty(TYPE, tag, config, IAM_ROLE_ARN_CONFIG_NAME);
156159
String recipe = ConfigurationUtils.readStringProperty(TYPE, tag, config, RECIPE_CONFIG_NAME);
@@ -162,7 +165,7 @@ public PersonalizeRankingResponseProcessor create(Map<String, Processor.Factory<
162165
new PersonalizeIntelligentRankerConfiguration(personalizeCampaign, iamRoleArn, recipe, itemIdField, awsRegion, weight);
163166
AWSCredentialsProvider credentialsProvider = PersonalizeCredentialsProviderFactory.getCredentialsProvider(personalizeClientSettings, iamRoleArn, awsRegion);
164167
PersonalizeClient personalizeClient = clientBuilder.apply(credentialsProvider, awsRegion);
165-
return new PersonalizeRankingResponseProcessor(tag, description, rankerConfig, personalizeClient);
168+
return new PersonalizeRankingResponseProcessor(tag, description, ignoreFailure, rankerConfig, personalizeClient);
166169
}
167170
}
168171
}

src/test/java/org/opensearch/search/relevance/transformer/kendraintelligentranking/pipeline/KendraRankingResponseProcessorTests.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ public void testFactory() throws Exception {
6666
Collections.emptyMap(),
6767
null,
6868
null,
69-
Collections.emptyMap()
69+
false,
70+
Collections.emptyMap(),
71+
null
7072
));
7173

7274
//test create with all fields
@@ -76,15 +78,15 @@ public void testFactory() throws Exception {
7678
configuration.put("title_field","field");
7779
configuration.put("body_field","body");
7880
configuration.put("doc_limit","500");
79-
KendraRankingResponseProcessor processorWithAllFields = factory.create(Collections.emptyMap(),"tmp0","testingAllFields", configuration);
81+
KendraRankingResponseProcessor processorWithAllFields = factory.create(Collections.emptyMap(),"tmp0","testingAllFields", false, configuration,null);
8082
assertEquals(TYPE, processorWithAllFields.getType());
8183
assertEquals("tmp0", processorWithAllFields.getTag());
8284
assertEquals("testingAllFields", processorWithAllFields.getDescription());
8385

8486
//test create with required field
8587
Map<String,Object> shortConfiguration = new HashMap<>();
8688
shortConfiguration.put("body_field","body");
87-
KendraRankingResponseProcessor processorWithOneFields = factory.create(Collections.emptyMap(),"tmp1","testingBodyField", shortConfiguration);
89+
KendraRankingResponseProcessor processorWithOneFields = factory.create(Collections.emptyMap(),"tmp1","testingBodyField", false, shortConfiguration, null);
8890
assertEquals(TYPE, processorWithOneFields.getType());
8991
assertEquals("tmp1", processorWithOneFields.getTag());
9092
assertEquals("testingBodyField", processorWithOneFields.getDescription());
@@ -93,7 +95,7 @@ public void testFactory() throws Exception {
9395
Map<String,Object> nullDocLimitConfiguration = new HashMap<>();
9496
nullDocLimitConfiguration.put("body_field","body");
9597
nullDocLimitConfiguration.put("doc_limit",null);
96-
KendraRankingResponseProcessor processorWithNullDocLimit = factory.create(Collections.emptyMap(),"tmp2","testingNullDocLimit", nullDocLimitConfiguration);
98+
KendraRankingResponseProcessor processorWithNullDocLimit = factory.create(Collections.emptyMap(),"tmp2","testingNullDocLimit", false, nullDocLimitConfiguration, null );
9799
assertEquals(TYPE, processorWithNullDocLimit.getType());
98100
assertEquals("tmp2", processorWithNullDocLimit.getTag());
99101
assertEquals("testingNullDocLimit", processorWithNullDocLimit.getDescription());
@@ -102,7 +104,7 @@ public void testFactory() throws Exception {
102104
Map<String,Object> nullTitleConfiguration = new HashMap<>();
103105
nullTitleConfiguration.put("body_field","body");
104106
nullTitleConfiguration.put("title_field",null);
105-
KendraRankingResponseProcessor processorWithNullTitleField = factory.create(Collections.emptyMap(),"tmp3","testingNullTitleField", nullTitleConfiguration);
107+
KendraRankingResponseProcessor processorWithNullTitleField = factory.create(Collections.emptyMap(),"tmp3","testingNullTitleField", false, nullTitleConfiguration, null);
106108
assertEquals(TYPE, processorWithNullTitleField.getType());
107109
assertEquals("tmp3", processorWithNullTitleField.getTag());
108110
assertEquals("testingNullTitleField", processorWithNullTitleField.getDescription());
@@ -116,18 +118,18 @@ public void testRankingResponse() throws Exception {
116118
bodyField.add("body");
117119

118120
//test response with titleField, bodyField and docLimit
119-
KendraRankingResponseProcessor processorWtOptionalConfig = new KendraRankingResponseProcessor(null,null,titleField,bodyField,500,kendraClient);
121+
KendraRankingResponseProcessor processorWtOptionalConfig = new KendraRankingResponseProcessor(null,null,false, titleField,bodyField,500,kendraClient);
120122
int size = 5;
121123
SearchResponse reRankedResponse0 = processorWtOptionalConfig.processResponse(createRequest(),createResponse(size));
122124
assertEquals(size,reRankedResponse0.getHits().getHits().length);
123125

124126
//test response with null doc limit
125-
KendraRankingResponseProcessor processorWtTwoConfig = new KendraRankingResponseProcessor(null,null,titleField,bodyField,null,kendraClient);
127+
KendraRankingResponseProcessor processorWtTwoConfig = new KendraRankingResponseProcessor(null,null,false, titleField,bodyField,null,kendraClient);
126128
SearchResponse reRankedResponse1 = processorWtTwoConfig.processResponse(createRequest(),createResponse(size));
127129
assertEquals(size,reRankedResponse1.getHits().getHits().length);
128130

129131
//test response with null doc limit and null title field
130-
KendraRankingResponseProcessor processorWtOneConfig = new KendraRankingResponseProcessor(null,null,null,bodyField,null,kendraClient);
132+
KendraRankingResponseProcessor processorWtOneConfig = new KendraRankingResponseProcessor(null,null,false,null,bodyField,null,kendraClient);
131133
SearchResponse reRankedResponse2 = processorWtOneConfig.processResponse(createRequest(),createResponse(size));
132134
assertEquals(size,reRankedResponse2.getHits().getHits().length);
133135

src/test/java/org/opensearch/search/relevance/transformer/personalizeintelligentranking/PersonalizeResponseProcessorTests.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public void testCreateFactoryThrowsExceptionWithEmptyConfig() {
5555
Collections.emptyMap(),
5656
null,
5757
null,
58-
Collections.emptyMap()
58+
false,
59+
Collections.emptyMap(),
60+
null
5961
));
6062
}
6163

@@ -72,7 +74,7 @@ public void testCreateFactoryWithAllPersonalizeConfig() throws Exception {
7274
configuration.put("aws_region", region);
7375

7476
PersonalizeRankingResponseProcessor personalizeResponseProcessor =
75-
factory.create(Collections.emptyMap(), "testTag", "testingAllFields", configuration);
77+
factory.create(Collections.emptyMap(), "testTag", "testingAllFields", false, configuration, null);
7678

7779
assertEquals(TYPE, personalizeResponseProcessor.getType());
7880
assertEquals("testTag", personalizeResponseProcessor.getTag());
@@ -94,7 +96,7 @@ public void testProcessorWithNoHits() throws Exception {
9496
configuration.put("aws_region", region);
9597

9698
PersonalizeRankingResponseProcessor personalizeResponseProcessor =
97-
factory.create(Collections.emptyMap(), "testTag", "testingAllFields", configuration);
99+
factory.create(Collections.emptyMap(), "testTag", "testingAllFields", false, configuration, null);
98100
SearchRequest searchRequest = new SearchRequest();
99101
SearchHits hits = new SearchHits(new SearchHit[0], new TotalHits(0, TotalHits.Relation.EQUAL_TO), 0.0f);
100102
SearchResponseSections searchResponseSections = new SearchResponseSections(hits, null, null, false, false, null, 0);
@@ -118,7 +120,7 @@ public void testProcessorWithHits() throws Exception {
118120
configuration.put("aws_region", region);
119121

120122
PersonalizeRankingResponseProcessor personalizeResponseProcessor =
121-
factory.create(Collections.emptyMap(), "testTag", "testingAllFields", configuration);
123+
factory.create(Collections.emptyMap(), "testTag", "testingAllFields", false, configuration, null);
122124
SearchRequest searchRequest = new SearchRequest();
123125
SearchHit[] searchHits = new SearchHit[10];
124126
for (int i = 0; i < searchHits.length; i++) {
@@ -147,7 +149,7 @@ public void testProcessorWithHitsAndSearchProcessorExt() throws Exception {
147149
configuration.put("aws_region", region);
148150

149151
PersonalizeRankingResponseProcessor personalizeResponseProcessor =
150-
factory.create(Collections.emptyMap(), "testTag", "testingAllFields", configuration);
152+
factory.create(Collections.emptyMap(), "testTag", "testingAllFields", false, configuration, null);
151153

152154
Map<String, Object> personalizeContext = new HashMap<>();
153155
personalizeContext.put("contextKey2", "contextValue2");
@@ -186,7 +188,7 @@ public void testProcessorWithHitsWithInvalidPersonalizeContext() throws Exceptio
186188
configuration.put("aws_region", region);
187189

188190
PersonalizeRankingResponseProcessor personalizeResponseProcessor =
189-
factory.create(Collections.emptyMap(), "testTag", "testingAllFields", configuration);
191+
factory.create(Collections.emptyMap(), "testTag", "testingAllFields", false, configuration,null);
190192

191193
Map<String, Object> personalizeContext = new HashMap<>();
192194
personalizeContext.put("contextKey2", 5);

0 commit comments

Comments
 (0)