Skip to content
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 initial search request inference processor #2616

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ext {
apply plugin: 'opensearch.opensearchplugin'
apply plugin: 'opensearch.testclusters'
apply plugin: 'opensearch.pluginzip'
apply plugin: 'opensearch.yaml-rest-test'
ext {
projectSubstitutions = [:]
licenseFile = rootProject.file('LICENSE.txt')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
import org.opensearch.ml.model.MLModelCacheHelper;
import org.opensearch.ml.model.MLModelManager;
import org.opensearch.ml.processor.MLInferenceIngestProcessor;
import org.opensearch.ml.processor.MLInferenceSearchRequestProcessor;
import org.opensearch.ml.repackage.com.google.common.collect.ImmutableList;
import org.opensearch.ml.rest.RestMLCreateConnectorAction;
import org.opensearch.ml.rest.RestMLCreateControllerAction;
Expand Down Expand Up @@ -967,7 +968,11 @@ public Map<String, Processor.Factory<SearchRequestProcessor>> getRequestProcesso
GenerativeQAProcessorConstants.REQUEST_PROCESSOR_TYPE,
new GenerativeQARequestProcessor.Factory(() -> this.ragSearchPipelineEnabled)
);

requestProcessors
.put(
MLInferenceSearchRequestProcessor.TYPE,
new MLInferenceSearchRequestProcessor.Factory(parameters.client, parameters.namedXContentRegistry)
);
return requestProcessors;
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@ default Object getModelOutputValue(MLOutput mlOutput, String modelOutputFieldNam
return modelTensorOutputMap;
} else {
try {
return JsonPath.parse(modelTensorOutputMap).read(modelOutputFieldName);
Object modelOutputValue = JsonPath.parse(modelTensorOutputMap).read(modelOutputFieldName);
if (modelOutputValue == null) {
throw new IllegalArgumentException(
"model inference output cannot find such json path: " + modelOutputFieldName + " in " + modelTensorOutputMap
);
}
return modelOutputValue;
} catch (Exception e) {
if (ignoreMissing) {
return modelTensorOutputMap;
Expand Down Expand Up @@ -313,7 +319,6 @@ default List<String> writeNewDotPathForNestedObject(Object json, String dotPath)
* @return the converted dot path notation string
*/
default String convertToDotPath(String path) {

return path.replaceAll("\\[(\\d+)\\]", "$1\\.").replaceAll("\\['(.*?)']", "$1\\.").replaceAll("^\\$", "").replaceAll("\\.$", "");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.opensearch.ml.common.spi.MLCommonsExtension;
import org.opensearch.ml.common.spi.tools.Tool;
import org.opensearch.ml.engine.tools.MLModelTool;
import org.opensearch.ml.processor.MLInferenceSearchRequestProcessor;
import org.opensearch.plugins.ExtensiblePlugin;
import org.opensearch.plugins.SearchPipelinePlugin;
import org.opensearch.plugins.SearchPlugin;
Expand Down Expand Up @@ -73,10 +74,11 @@ public void testGetSearchExts() {
public void testGetRequestProcessors() {
SearchPipelinePlugin.Parameters parameters = mock(SearchPipelinePlugin.Parameters.class);
Map<String, ?> requestProcessors = plugin.getRequestProcessors(parameters);
assertEquals(1, requestProcessors.size());
assertEquals(2, requestProcessors.size());
assertTrue(
requestProcessors.get(GenerativeQAProcessorConstants.REQUEST_PROCESSOR_TYPE) instanceof GenerativeQARequestProcessor.Factory
);
assertTrue(requestProcessors.get(MLInferenceSearchRequestProcessor.TYPE) instanceof MLInferenceSearchRequestProcessor.Factory);
}

@Test
Expand Down
Loading
Loading