-
Notifications
You must be signed in to change notification settings - Fork 138
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
Adds preset contentRegistry for IngestProcessors #3281
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.core.xcontent.NamedXContentRegistry; | ||
import org.opensearch.ingest.IngestDocument; | ||
import org.opensearch.ml.common.FunctionName; | ||
import org.opensearch.ml.common.dataset.remote.RemoteInferenceInputDataSet; | ||
import org.opensearch.ml.common.input.MLInput; | ||
import org.opensearch.ml.common.output.model.MLResultDataType; | ||
|
@@ -138,6 +139,60 @@ public void testExecute_Exception() throws Exception { | |
|
||
} | ||
|
||
/** | ||
* Models that use the parameters field need to have a valid NamedXContentRegistry object to create valid MLInputs. For example | ||
* <pre> | ||
* PUT /_plugins/_ml/_predict/text_embedding/model_id | ||
* { | ||
* "parameters": { | ||
* "content_type" : "query" | ||
* }, | ||
* "text_docs" : ["what day is it today?"], | ||
* "target_response" : ["sentence_embedding"] | ||
* } | ||
* </pre> | ||
* These types of models like Local Asymmetric embedding models use the parameters field. | ||
* And as such we need to test that having the contentRegistry throws an exception as it can not | ||
* properly create a valid MLInput to perform prediction | ||
* | ||
* @implNote If you check the stack trace of the test you will see it tells you that it's a direct consequence of xContentRegistry being null | ||
*/ | ||
public void testExecute_xContentRegistryNullWithLocalModel_throwsException() throws Exception { | ||
// Set the registry to null and reset after exiting the test | ||
xContentRegistry = null; | ||
|
||
String localModelInput = | ||
"{ \"text_docs\": [\"What day is it today?\"],\"target_response\": [\"sentence_embedding\"], \"parameters\": { \"contentType\" : \"query\"} }"; | ||
|
||
MLInferenceIngestProcessor processor = createMLInferenceProcessor( | ||
"local_model_id", | ||
null, | ||
null, | ||
null, | ||
false, | ||
FunctionName.TEXT_EMBEDDING.toString(), | ||
false, | ||
false, | ||
false, | ||
localModelInput | ||
); | ||
try { | ||
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.
What do you think about this? 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 like this, but the problem is that the exception is passed by the handler its not done by the method itself. So this wouldn't be possible thats the reason why this class and more specifically this method has a catch to make sure that an exception is not possible. i.e. the handler passes an exception only. |
||
String npeMessage = | ||
"Cannot invoke \"org.opensearch.ml.common.input.MLInput.setAlgorithm(org.opensearch.ml.common.FunctionName)\" because \"mlInput\" is null"; | ||
|
||
processor.execute(ingestDocument, handler); | ||
verify(handler) | ||
.accept( | ||
isNull(), | ||
argThat(exception -> exception instanceof NullPointerException && exception.getMessage().equals(npeMessage)) | ||
); | ||
} catch (Exception e) { | ||
assertEquals("this catch block should not get executed.", e.getMessage()); | ||
} | ||
// reset to mocked object | ||
xContentRegistry = mock(NamedXContentRegistry.class); | ||
} | ||
|
||
/** | ||
* test nested object document with array of Map<String,String> | ||
*/ | ||
|
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't we add another test for success case with Asymmetric model?
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.
Yes its possible but that would involve hosting the model zip somewhere so we can test that it makes embeddings.
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 we take some idea from here: https://github.com/opensearch-project/ml-commons/pull/2123/files#diff-cd8365f3263802b111604d62b751e5264a2e51df44b46b9fb650ca001466328a
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.
Oh! I didn't realize the community user did that, I can definitely use that thanks!