-
Notifications
You must be signed in to change notification settings - Fork 148
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
support embedding types #3560
support embedding types #3560
Conversation
Signed-off-by: zane-neo <zaniu@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, but can you add ITs for the added embedding types in this PR?
Signed-off-by: zane-neo <zaniu@amazon.com>
Signed-off-by: zane-neo <zaniu@amazon.com>
Added more ITs, also updated the blueprint under tutorial, please help review again. |
The change should be compatible with neural-search plugin as the post_process_function are mainly to convert the response to a format that neural-search plugin accepts so that user can use the model to create ingestion pipeline, the PR in neural-search are merged now: opensearch-project/neural-search#1007 |
Signed-off-by: zane-neo <zaniu@amazon.com>
@@ -244,6 +247,15 @@ public static ModelTensors processOutput( | |||
return ModelTensors.builder().mlModelTensors(modelTensors).build(); | |||
} | |||
|
|||
private static MLResultDataType parseMLResultDataTypeFromResponseFilter(String responseFilter) { | |||
for (MLResultDataType type : MLResultDataType.values()) { | |||
if (responseFilter.contains("." + type.name()) || responseFilter.contains("." + type.name().toLowerCase(Locale.ROOT))) { |
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.
What about using containsIgnoreCase to support type in a case-insensitivity way?
import org.opensearch.ml.common.output.model.ModelTensor; | ||
|
||
public abstract class ConnectorPostProcessFunction<T> implements Function<Object, List<ModelTensor>> { | ||
public abstract class ConnectorPostProcessFunction<T> implements BiFunction<Object, MLResultDataType, List<ModelTensor>> { |
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.
This interface change looks like a breaking change, and not all PostProcessFunctions are using the ResultDataType like BedrockBatchJobArnPostProcessFunction. So what I am thinking is 1. to use extend instead of implements to support additional parameter MLResultDataType, or 2. to have MLResultDataType covering all cases and all PostProcessFunctions to use/set it, for example, not use null as dateType but have a default type something like FLOAT32.
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 considered to change the Function to a self-defined interface/abstract class, but that needs more code changes and I want to limit the changes in this PR for easier reviewing. I'm open to make these changes in this PR if you insist or create a separate PR for better reviewing experience.
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.
Yeah, for this pr, I am OK. We can have more discussion about if we need refactoring later.
…ately Signed-off-by: zane-neo <zaniu@amazon.com>
import java.util.Map; | ||
|
||
@Log4j2 | ||
public class RestBedRockV2PostProcessFunctionInferenceIT extends MLCommonsRestTestCase { |
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 nor merge into the BedRock Inference IT to share the IT resources, reducing the overall IT run time length?
https://github.com/opensearch-project/ml-commons/blob/main/plugin/src/test/java/org/opensearch/ml/rest/RestBedRockInferenceIT.java
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.
The template of RestBedRockInferenceIT and RestBedRockV2PostProcessFunctionInferenceIT are different, so if we merge them together, the code will seem mess up, separating them is for better code reading experience.
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.
agree, but this means a simple test case would need spinning up new IT cluster resources. Given the IT suites already takes 40+ mins, it's not scalable to keep adding new test classes. So organizing the same test categories into a same test suite sharing the resources is a better approach overall. Do you have any better ideas on this matter?
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.
Ok, I can take a look again to find a way to merge them and maintain the readability in best effort.
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class RestCohereInferenceIT extends MLCommonsRestTestCase { |
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.
This IT can be merged into the RemoteInferenceIT?
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.
The RemoteInferenceIT class file is already too big, I prefer we use separate file to test single feature for better maintenance.
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.
btw, the spotless is not applied yet.
Signed-off-by: zane-neo <zaniu@amazon.com>
Signed-off-by: zane-neo <zaniu@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, thanks for changes.
import org.opensearch.ml.common.input.MLInput; | ||
|
||
public class RestCohereInferenceIT extends MLCommonsRestTestCase { | ||
private final String COHERE_KEY = Optional.ofNullable(System.getenv("COHERE_KEY")).orElse("UzRF34a6gj0OKkvHOO6FZxLItv8CNpK5dFdCaUDW"); |
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 shouldn't expose this API key!!!
cc @ylwu-amzn
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.
@zane-neo, let's avoid adding credentials in code
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's my private API key for testing, forgot to remove it in the PR.
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.
git-secrets could be helpful here.
* support embedding types Signed-off-by: zane-neo <zaniu@amazon.com> * Add ITs and blueprints in tutorial Signed-off-by: zane-neo <zaniu@amazon.com> * format code Signed-off-by: zane-neo <zaniu@amazon.com> * add licence header Signed-off-by: zane-neo <zaniu@amazon.com> * use containsIgnoreCase instead of checking capital & lower case separately Signed-off-by: zane-neo <zaniu@amazon.com> * merge post processing function IT to existing file Signed-off-by: zane-neo <zaniu@amazon.com> * format code Signed-off-by: zane-neo <zaniu@amazon.com> --------- Signed-off-by: zane-neo <zaniu@amazon.com>
Description
BedRock titan model V2 and Cohere V2 model now supports multiple embedding types in their API, which means you can specify different embedding types as a list in the request, and model generates different results based on embedding types in response, e.g.:
Response:
The current bedrock and cohere post process function has default response filter to
$.embedding
and$.embeddings
respectively and the extracted results are bothList<List<Float>>
type, after they support embedding types, the response structure is different and the default response filter extractsList<List<Float>>
andMap<String, List<List<Number>>
type separately. This PR is to add support to user who wants to extract different types of results in model response, and this can be classified into several categories:BedRock (The post process function applies for both v1 and v2 model)
$.embeddingsByType
, the response will be captured intodataAsMap
in ModelTensor, and user can get all embedding types result.$.embeddingsByType.{concrete_embedding_type}
, the response will be captured similar to default case to thedata
field in ModelTensor.Cohere V2 (A new v2 post process function is added to v2 model)
$.embeddings
, the response will be captured intodataAsMap
in ModelTensor, and user can get all embedding types result.$.embeddings.{concrete_embedding_type}
, the response will be captured similar to default case to thedata
field in ModelTensor.Related Issues
#3093
Check List
--signoff
.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.