-
Notifications
You must be signed in to change notification settings - Fork 24
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
Personalized intelligent ranking for open search requests #138
Personalized intelligent ranking for open search requests #138
Conversation
64bd77b
to
4d8cde4
Compare
...relevance/transformer/personalizeintelligentranking/PersonalizeRankingResponseProcessor.java
Outdated
Show resolved
Hide resolved
...ch/relevance/transformer/personalizeintelligentranking/client/PersonalizeClientSettings.java
Show resolved
Hide resolved
@kulket -- Can you please rebase from main and force-push to your fork? If you check the list of commits associated with this PR, it includes the Jackson-core update, which isn't actually part of this PR. |
* @param clientSettings Personalize client settings | ||
* @return AWS credentials provider for accessing Personalize | ||
*/ | ||
public AWSCredentialsProvider getCredentialsProvider(PersonalizeClientSettings clientSettings) { |
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.
Does this one get called from anywhere else? Can it be private
+ static
?
.../transformer/personalizeintelligentranking/client/PersonalizeCredentialsProviderFactory.java
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## main #138 +/- ##
============================================
+ Coverage 81.05% 82.05% +0.99%
- Complexity 218 293 +75
============================================
Files 29 41 +12
Lines 887 1131 +244
Branches 120 139 +19
============================================
+ Hits 719 928 +209
- Misses 106 127 +21
- Partials 62 76 +14
|
Description: ============ This change uses search pipeline feature of open search to allow customers to create a response processor. Response processor will rerank search results obtained from open search using Personalization solution before returning results to the user. Check List: ========== - [Y] New functionality includes testing. - [Y] All tests pass - [Y] New functionality has been documented. - [Y] New functionality has javadoc added - [Y] Commits are signed as per the DCO using --signoff Signed-off-by: Ketan Kulkarni <kektnr@amazon.com>
Description: ============ This change introduces ability ot pass user id as part of search request to be used by Personalize response processor. SearchExtSpec will be used to support getting user id as well as other personalize related request parameters to personalize search results. Check list: =========== - [x] New functionality includes testing. - [x] All tests pass - [x] New functionality has been documented. - [x] New functionality has javadoc added - [x] Commits are signed as per the DCO using --signoff Signed-off-by: Ketan Kulkarni <kektnr@amazon.com>
Description: ============ SearchPipelinePlugin interface now uses Processor.Factory<SearchResponseProcessor> instead of Processor.Factory. Also use getResponseProcessors method instead of getProcessors method. Check list: =========== - [x] New functionality includes testing. - [x] All tests pass - [x] New functionality has been documented. - [x] New functionality has javadoc added - [x] Commits are signed as per the DCO using --signoff Signed-off-by: Ketan Kulkarni <kektnr@amazon.com>
f789ebd
to
0472a12
Compare
Performed rebased as well as force push. |
Added unit tests for PersonalizeRankingResponseProcessor and PersonalizeRequestParameterUtil. Also, needed to update JaCoCo to 0.8.9 in order to get rid of warnings about invalid bytecode versions since we upgraded to JDK 20. Signed-off-by: Michael Froh <froh@amazon.com>
import java.util.concurrent.TimeUnit; | ||
import java.util.function.BiFunction; | ||
|
||
import static org.opensearch.search.relevance.transformer.personalizeintelligentranking.configuration.Constants.CAMPAIGN_ARN_CONFIG_NAME; |
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.
it seems that the class is importing individual configuration constants from the configuration package. While this approach can work, I believe it might be more maintainable and flexible to incorporate the configuration as an attribute of the plugins and access it using this.personalizeClientsetting
. This way, the class can receive the configuration as a parameter, allowing for greater modularity and easier testing.
Check out this PR, which use this.kendraClientsetting
search-processor/src/main/java/org/opensearch/search/relevance/SearchRelevancePlugin.java
Line 95 in 01ca204
this.kendraClientSettings = KendraClientSettings.getClientSettings(environment.settings()); |
search-processor/src/main/java/org/opensearch/search/relevance/SearchRelevancePlugin.java
Line 119 in 01ca204
return Map.of(KendraRankingResponseProcessor.TYPE, new KendraRankingResponseProcessor.Factory(this.kendraClientSettings)); |
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.
Hi mingshl,
Thank you for your review and comment.
I kept code for getting PersonalizeClientSettings
instance to limited to the PersonalizeRankingResponseProcessor.Factory
instance creation so that PersonalizeClientSettings
are not created when they are not required. For e.g. Creating that instance outside factory creation may create PersonalizeClientSettings
instance when using plugin for Kendra only use case.
I did thought about creating one common class for Kendra and Personalize related settings. But Kendra needs more configurations than just credentials and hence opted to keep separate class for Personalize.
Let me know your thoughts regarding above.
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.
I guess another question is whether it makes sense to declare the Factory
parameters in a separate Constants
class just to use them here. They're only used to pass values to the processor Factory
. As such, they can be kept in this class.
A "global" Constants
class is only really useful for values used in multiple classes. Otherwise, it's just an extra hop to find values that are only used in one class.
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.
Makes sense. Updated code to move search pipeline related configuration constants to Factory class instead of using earlier approach of global constants.
result = AccessController.doPrivileged( | ||
(PrivilegedAction<GetPersonalizedRankingResult>) () -> personalizeRuntime.getPersonalizedRanking(request)); | ||
} catch (AmazonServiceException ex) { | ||
throw ex; |
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.
Should this be a direct rethrow or an OpenSearchException?
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.
Will be using follow up PR to update exception handling mentioned here.
// TODO: Parse context from request parameters | ||
String userId = requestParameters.getUserId(); | ||
logger.info("User ID from request parameters. User ID: {}", userId); | ||
GetPersonalizedRankingRequest personalizeRequest = new GetPersonalizedRankingRequest() | ||
.withCampaignArn(rankerConfig.getPersonalizeCampaign()) | ||
.withInputList(documentIdsToRank) | ||
.withUserId(userId); | ||
GetPersonalizedRankingResult result = personalizeClient.getPersonalizedRanking(personalizeRequest); | ||
|
||
//TODO: Combine Personalize and open search result. Change the result after transform logic is implemented |
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.
Seems to unfinished impl. If it's impl else where, please remove the TODOs
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.
We will update unfinished implementation as a follow up PR.
/** | ||
* Factory for creating Personalize ranker instance based on Personalize ranker configuration | ||
*/ | ||
public class PersonalizedRankerFactory { |
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.
If there is only one impl expected, can we simplify the code structure without utilizing a factory?
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.
We expect more than one implementation going forward so use factory approach here.
Description: ============ Configuration constants are only used by search response processor factory. Move related constants from global configuration constants file to factory class to ensure they are closer to the palce where they are used. Signed-off-by: Ketan Kulkarni <kektnr@amazon.com>
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.
LGTM
* Personalized intelligent ranking for open search requests Description: ============ This change uses search pipeline feature of open search to allow customers to create a response processor. Response processor will rerank search results obtained from open search using Personalization solution before returning results to the user. Check List: ========== - [Y] New functionality includes testing. - [Y] All tests pass - [Y] New functionality has been documented. - [Y] New functionality has javadoc added - [Y] Commits are signed as per the DCO using --signoff Signed-off-by: Ketan Kulkarni <kektnr@amazon.com> * Support passing user id for Personalization as part of search request Description: ============ This change introduces ability ot pass user id as part of search request to be used by Personalize response processor. SearchExtSpec will be used to support getting user id as well as other personalize related request parameters to personalize search results. Check list: =========== - [x] New functionality includes testing. - [x] All tests pass - [x] New functionality has been documented. - [x] New functionality has javadoc added - [x] Commits are signed as per the DCO using --signoff Signed-off-by: Ketan Kulkarni <kektnr@amazon.com> * Incorporate changes to SearchPipelinePlugin interface Description: ============ SearchPipelinePlugin interface now uses Processor.Factory<SearchResponseProcessor> instead of Processor.Factory. Also use getResponseProcessors method instead of getProcessors method. Check list: =========== - [x] New functionality includes testing. - [x] All tests pass - [x] New functionality has been documented. - [x] New functionality has javadoc added - [x] Commits are signed as per the DCO using --signoff Signed-off-by: Ketan Kulkarni <kektnr@amazon.com> * Improve test coverage Added unit tests for PersonalizeRankingResponseProcessor and PersonalizeRequestParameterUtil. Also, needed to update JaCoCo to 0.8.9 in order to get rid of warnings about invalid bytecode versions since we upgraded to JDK 20. Signed-off-by: Michael Froh <froh@amazon.com> * Move configruation constants to the search pipeline processor factory Description: ============ Configuration constants are only used by search response processor factory. Move related constants from global configuration constants file to factory class to ensure they are closer to the palce where they are used. Signed-off-by: Ketan Kulkarni <kektnr@amazon.com> --------- Signed-off-by: Ketan Kulkarni <kektnr@amazon.com> Signed-off-by: Michael Froh <froh@amazon.com> Co-authored-by: Michael Froh <froh@amazon.com> (cherry picked from commit 23b5226)
* Personalized intelligent ranking for open search requests Description: ============ This change uses search pipeline feature of open search to allow customers to create a response processor. Response processor will rerank search results obtained from open search using Personalization solution before returning results to the user. Signed-off-by: Ketan Kulkarni <kektnr@amazon.com> * Support passing user id for Personalization as part of search request Description: ============ This change introduces ability ot pass user id as part of search request to be used by Personalize response processor. SearchExtSpec will be used to support getting user id as well as other personalize related request parameters to personalize search results. Signed-off-by: Ketan Kulkarni <kektnr@amazon.com> * Incorporate changes to SearchPipelinePlugin interface Description: ============ SearchPipelinePlugin interface now uses Processor.Factory<SearchResponseProcessor> instead of Processor.Factory. Also use getResponseProcessors method instead of getProcessors method. Signed-off-by: Ketan Kulkarni <kektnr@amazon.com> * Improve test coverage Added unit tests for PersonalizeRankingResponseProcessor and PersonalizeRequestParameterUtil. Also, needed to update JaCoCo to 0.8.9 in order to get rid of warnings about invalid bytecode versions since we upgraded to JDK 20. Signed-off-by: Michael Froh <froh@amazon.com> * Move configruation constants to the search pipeline processor factory Description: ============ Configuration constants are only used by search response processor factory. Move related constants from global configuration constants file to factory class to ensure they are closer to the palce where they are used. Signed-off-by: Ketan Kulkarni <kektnr@amazon.com> --------- Signed-off-by: Ketan Kulkarni <kektnr@amazon.com> Signed-off-by: Michael Froh <froh@amazon.com> Co-authored-by: Michael Froh <froh@amazon.com> (cherry picked from commit 23b5226) Co-authored-by: kulket <130191298+kulket@users.noreply.github.com>
Description:
This change uses search pipeline feature of open search to allow customers to create a response processor.
Response processor will rerank search results obtained from open search using Personalization solution before returning results to the user.
Check List:
Signed-off-by: Ketan Kulkarni kektnr@amazon.com
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.