-
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
Introduce Ml Inference Search Request Extension #3284
base: main
Are you sure you want to change the base?
Introduce Ml Inference Search Request Extension #3284
Conversation
@mingshl let's take the update from main. File has conflict. |
b2504c4
to
d5f7605
Compare
thanks @dhrubo-os , rebased and resolved conflicts. |
Tests are failing |
there is no changes related to ConversationalMemory, will try rerun the tests.
|
Signed-off-by: Mingshi Liu <[email protected]>
d5f7605
to
cfa8a38
Compare
rebased and resolved conflicts. |
|
9c576ec
to
3cf89dc
Compare
Signed-off-by: Mingshi Liu <[email protected]>
3cf89dc
to
037fd7f
Compare
Object modelOutputValue = getModelOutputValue(mlOutput, modelOutputFieldName, ignoreMissing, fullResponsePath); | ||
String jsonPathExpression = "$." + newQueryField; | ||
JsonPath.parse(incomeQueryObject).set(jsonPathExpression, modelOutputValue); | ||
String newQueryField = null; |
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 declaration can be moved inside the try/catch block
requestContext.setAttribute(newQueryField, modelOutputValue); | ||
|
||
} catch (PathNotFoundException e) { | ||
throw new IllegalArgumentException("can not find path " + newQueryField + "in query 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.
do you want to log the full exception message here?
if (!queryField.startsWith("ext.") && !queryField.startsWith("$.ext.")) { | ||
Object pathData = jsonData.read(queryField); | ||
if (pathData == null) { | ||
throw new IllegalArgumentException(); |
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.
please add more information so user can have more information on the cause and address the issue
@@ -334,4 +341,26 @@ default List<String> writeNewDotPathForNestedObject(Object json, String dotPath) | |||
default String convertToDotPath(String path) { | |||
return path.replaceAll("\\[(\\d+)\\]", "$1\\.").replaceAll("\\['(.*?)']", "$1\\.").replaceAll("^\\$", "").replaceAll("\\.$", ""); | |||
} | |||
|
|||
default void setRequestContextFromExt(SearchRequest request, PipelineProcessingContext requestContext) { |
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 class looks more like an abstract class rather then an interface, there are verbose default implementations for every method. Consider refactoring interface->abstract class sometime in the future
mlParams | ||
.forEach( | ||
(key, value) -> requestContext | ||
.setAttribute(String.format("ext.%s.%s", MLInferenceRequestParametersExtBuilder.NAME, key), value) |
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.
you need to use locale with String.format
, default should be good enough
import org.opensearch.core.xcontent.XContentParser; | ||
import org.opensearch.search.SearchExtBuilder; | ||
|
||
public class MLInferenceRequestParametersExtBuilder extends SearchExtBuilder { |
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.
Please add class level java doc that describes class responsibilities
|
||
public class MLInferenceRequestParametersExtBuilder extends SearchExtBuilder { | ||
private static final Logger logger = LogManager.getLogger(MLInferenceRequestParametersExtBuilder.class); | ||
public static final String NAME = ML_INFERENCE_FIELD; |
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.
you can use ML_INFERENCE_FIELD directly, NAME is not needed
import org.opensearch.action.search.SearchRequest; | ||
import org.opensearch.search.SearchExtBuilder; | ||
|
||
public class MLInferenceRequestParametersUtil { |
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.
please add class level comments
.collect(Collectors.toList()); | ||
|
||
if (!extBuilders.isEmpty()) { | ||
mLInferenceRequestParametersExtBuilder = (MLInferenceRequestParametersExtBuilder) extBuilders.get(0); |
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 scenario with more than one element is valid did we document current behavior of using only first element and ignoring everything else? Btw, is this guaranteed that ext elements in this list will be in the same order as in user requst?
.filter(extBuilder -> MLInferenceRequestParametersExtBuilder.NAME.equals(extBuilder.getWriteableName())) | ||
.collect(Collectors.toList()); | ||
|
||
if (!extBuilders.isEmpty()) { |
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 suggest we check for extBuilders.isEmpty()
condition first and fail fast by returning null
. This way we can organize code on lines 32-36
Description
Introduce Ml Inference Search Request Extension, this is adding ml_inference search extension during search request/query phase,
For the search response side, I already introduced a
ml_inference
search response extension in earlier PR released in 2.18. Support ML Inference Search Processor Writing to Search ExtensionRelated Issues
#3286
#3054
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.