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

Introduce Ml Inference Search Request Extension #3284

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mingshl
Copy link
Collaborator

@mingshl mingshl commented Dec 16, 2024

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 Extension

Related Issues

#3286
#3054

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

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.

@dhrubo-os
Copy link
Collaborator

@mingshl let's take the update from main. File has conflict.

@mingshl mingshl force-pushed the feature/ml-inference-search-extension branch from b2504c4 to d5f7605 Compare December 17, 2024 19:45
@mingshl mingshl had a problem deploying to ml-commons-cicd-env-require-approval December 17, 2024 19:45 — with GitHub Actions Failure
@mingshl mingshl had a problem deploying to ml-commons-cicd-env-require-approval December 17, 2024 19:45 — with GitHub Actions Failure
@mingshl
Copy link
Collaborator Author

mingshl commented Dec 17, 2024

thanks @dhrubo-os , rebased and resolved conflicts.

@mingshl mingshl changed the title Introduce Ml Inference Search Extension Introduce Ml Inference Search Request Extension Dec 17, 2024
@dhrubo-os
Copy link
Collaborator

Tests are failing

@mingshl
Copy link
Collaborator Author

mingshl commented Dec 30, 2024

Tests are failing

there is no changes related to ConversationalMemory, will try rerun the tests.

> Task :opensearch-ml-memory:test

ConversationalMemoryHandlerITTests > testDifferentUsers_DifferentConversations FAILED
    java.lang.NoClassDefFoundError at ConversationalMemoryHandlerITTests.java:389
        Caused by: java.lang.ClassNotFoundException at ConversationalMemoryHandlerITTests.java:389

@mingshl mingshl had a problem deploying to ml-commons-cicd-env-require-approval December 30, 2024 22:40 — with GitHub Actions Failure
@mingshl mingshl had a problem deploying to ml-commons-cicd-env-require-approval December 31, 2024 00:36 — with GitHub Actions Failure
@mingshl mingshl had a problem deploying to ml-commons-cicd-env-require-approval December 31, 2024 00:36 — with GitHub Actions Failure
@mingshl mingshl force-pushed the feature/ml-inference-search-extension branch from d5f7605 to cfa8a38 Compare December 31, 2024 06:29
@mingshl mingshl had a problem deploying to ml-commons-cicd-env-require-approval December 31, 2024 06:30 — with GitHub Actions Failure
@mingshl mingshl had a problem deploying to ml-commons-cicd-env-require-approval December 31, 2024 06:30 — with GitHub Actions Failure
@mingshl
Copy link
Collaborator Author

mingshl commented Dec 31, 2024

rebased and resolved conflicts.

@dhrubo-os
Copy link
Collaborator

D:\a\ml-commons\ml-commons\common\build\generated\sources\delombok\java\main\org\opensearch\ml\common\utils\StringUtils.java:379: error: unknown tag: implNote
     * @implNote This method uses JsonPath for JSON manipulation and StringUtils for path existence checks.
       ^

@mingshl mingshl had a problem deploying to ml-commons-cicd-env-require-approval December 31, 2024 20:07 — with GitHub Actions Failure
@mingshl mingshl had a problem deploying to ml-commons-cicd-env-require-approval December 31, 2024 20:07 — with GitHub Actions Failure
@mingshl mingshl force-pushed the feature/ml-inference-search-extension branch from 9c576ec to 3cf89dc Compare December 31, 2024 22:34
@mingshl mingshl requested a deployment to ml-commons-cicd-env-require-approval December 31, 2024 22:34 — with GitHub Actions Waiting
@mingshl mingshl requested a deployment to ml-commons-cicd-env-require-approval December 31, 2024 22:34 — with GitHub Actions Waiting
@mingshl mingshl force-pushed the feature/ml-inference-search-extension branch from 3cf89dc to 037fd7f Compare December 31, 2024 22:39
@mingshl mingshl temporarily deployed to ml-commons-cicd-env-require-approval December 31, 2024 22:40 — with GitHub Actions Inactive
@mingshl mingshl temporarily deployed to ml-commons-cicd-env-require-approval December 31, 2024 22:40 — with GitHub Actions Inactive
@mingshl mingshl temporarily deployed to ml-commons-cicd-env-require-approval January 2, 2025 20:33 — with GitHub Actions Inactive
Object modelOutputValue = getModelOutputValue(mlOutput, modelOutputFieldName, ignoreMissing, fullResponsePath);
String jsonPathExpression = "$." + newQueryField;
JsonPath.parse(incomeQueryObject).set(jsonPathExpression, modelOutputValue);
String newQueryField = null;
Copy link
Member

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");
Copy link
Member

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();
Copy link
Member

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) {
Copy link
Member

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)
Copy link
Member

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 {
Copy link
Member

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;
Copy link
Member

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 {
Copy link
Member

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);
Copy link
Member

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()) {
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants