-
Notifications
You must be signed in to change notification settings - Fork 140
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
Add pre and post process functions for Bedrock Rerank API #3254 #3339
base: main
Are you sure you want to change the base?
Changes from 2 commits
3f7a00f
316de2c
4af169a
8a4fdb2
ededf78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,11 @@ public BedrockRerankPreProcessFunction() { | |
|
||
@Override | ||
public void validate(MLInput mlInput) { | ||
|
||
if (mlInput.getInputDataset() == null) { | ||
throw new IllegalArgumentException("Input dataset cannot be null."); | ||
} | ||
|
||
if (!(mlInput.getInputDataset() instanceof TextSimilarityInputDataSet)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe also check for null before getInputDataset()? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, will be updated on the next commit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've checked null check is already implemented in apply method in superclass, ConnectorPreProcessFunction and ConnectorPostProcessFunction. apply method is wrapping validate method. Thus, I think it's not necessary to implement nullcheck in validate method again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've just added following validation in validate method.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated on 4af169a |
||
throw new IllegalArgumentException("This pre_process_function can only support TextSimilarityInputDataSet"); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
@@ -36,18 +35,53 @@ public void process_WrongInput_NotList() { | |
function.apply("abc"); | ||
} | ||
|
||
@Test | ||
public void process_EmptyInput() { | ||
exceptionRule.expect(IllegalArgumentException.class); | ||
exceptionRule.expectMessage("Post process function input is empty."); | ||
function.apply(Arrays.asList()); | ||
} | ||
|
||
@Test | ||
public void process_WrongInput_NotCorrectList() { | ||
exceptionRule.expect(IllegalArgumentException.class); | ||
exceptionRule.expectMessage("Post process function input is not a List of Map."); | ||
exceptionRule.expectMessage("Rerank result is not a Map."); | ||
function.apply(Arrays.asList("abc")); | ||
} | ||
|
||
@Test | ||
public void process_EmptyMapInput() { | ||
exceptionRule.expect(IllegalArgumentException.class); | ||
exceptionRule.expectMessage("Rerank result is empty."); | ||
function.apply(Arrays.asList(Map.of())); | ||
} | ||
|
||
@Test | ||
public void process_WrongInput_NotCorrectMap() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. process_WrongInput_NotCorrectListOfMapsFormat(){ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated on the commit 8a4fdb2 |
||
exceptionRule.expect(IllegalArgumentException.class); | ||
exceptionRule.expectMessage("The rerank result should contain index and relevance_score."); | ||
function.apply(Arrays.asList(Map.of("test1", "value1"))); | ||
exceptionRule.expectMessage("Rerank result should have both index and relevanceScore."); | ||
List<Map<String, Object>> rerankResults = List | ||
.of( | ||
Map.of("index", 2, "relevanceScore", 0.7711548805236816), | ||
Map.of("index", 0, "relevanceScore", 0.0025114635936915874), | ||
Map.of("index", 1, "relevanceScore", 2.4876489987946115e-05), | ||
Map.of("test1", "value1") | ||
); | ||
function.apply(rerankResults); | ||
} | ||
|
||
@Test | ||
public void process_WrongInput_NotCorrectRelevanceScore() { | ||
exceptionRule.expect(IllegalArgumentException.class); | ||
exceptionRule.expectMessage("relevanceScore is not BigDecimal or Double."); | ||
List<Map<String, Object>> rerankResults = List | ||
.of( | ||
Map.of("index", 2, "relevanceScore", 0.7711548805236816), | ||
Map.of("index", 0, "relevanceScore", 0.0025114635936915874), | ||
Map.of("index", 1, "relevanceScore", 2.4876489987946115e-05), | ||
Map.of("index", 3, "relevanceScore", "value1") | ||
); | ||
function.apply(rerankResults); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe lets make a null test? just so we can understand? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. null test can be implemented by referring superclass, but writing superclass's test case in test class for extended class can lead build failure when superclass is updated. |
||
@Test | ||
|
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.
why do we need to cast the elements as Map? We defined this as parameter:
List<Map<String, Object>> rerankResults
.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.
Thank you for your review. I agree with you. For the logic, we don't need to cast as Map but just specify data type for enhanced loop as follows.
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.
fixed on ededf78