Skip to content

Conversation

Sq-eng
Copy link
Contributor

@Sq-eng Sq-eng commented Aug 15, 2025

Description

This PR adds support for parameter propagation in the predict API when using text_embedding function by ensuring user-supplied parameters are correctly merged into the connector's request_body and included in the outgoing request.

Related Issues

Resolves #4105

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.

Xia added 3 commits August 15, 2025 14:52
Signed-off-by: Shiqi Xia <[email protected]>
Signed-off-by: Shiqi Xia <[email protected]>
@Sq-eng Sq-eng force-pushed the main branch 2 times, most recently from 62c5b93 to 42fc5a5 Compare August 15, 2025 07:04
@Sq-eng Sq-eng had a problem deploying to ml-commons-cicd-env-require-approval August 15, 2025 07:06 — with GitHub Actions Failure
@Sq-eng Sq-eng had a problem deploying to ml-commons-cicd-env-require-approval August 15, 2025 07:06 — with GitHub Actions Failure
@Sq-eng Sq-eng had a problem deploying to ml-commons-cicd-env-require-approval August 15, 2025 07:06 — with GitHub Actions Failure
@Sq-eng Sq-eng had a problem deploying to ml-commons-cicd-env-require-approval August 15, 2025 07:06 — with GitHub Actions Failure
return (T) parameters.get("http_body");
}

public String removeMissingParameterFields(String payload, Map<String, String> params) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add description for this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need remove the unused field. We should keep consistent behavior with previous code. I.e. if user set a parameter in template and don't provide values, we just keep it. Otherwise it may change the behavior at user side

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. I’ve updated the code to follow this logic – now it keeps the unused fields consistent with the previous behavior.

@Sq-eng Sq-eng had a problem deploying to ml-commons-cicd-env-require-approval August 15, 2025 08:17 — with GitHub Actions Error
@Sq-eng Sq-eng had a problem deploying to ml-commons-cicd-env-require-approval August 15, 2025 08:17 — with GitHub Actions Failure
@Sq-eng Sq-eng had a problem deploying to ml-commons-cicd-env-require-approval August 15, 2025 08:17 — with GitHub Actions Error
@Sq-eng Sq-eng had a problem deploying to ml-commons-cicd-env-require-approval August 15, 2025 08:17 — with GitHub Actions Failure
import java.util.Map;
import java.util.Optional;
import java.io.IOException;
import java.util.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should aviod using import *, and restore to the previous import

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

import org.opensearch.core.action.ActionListener;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.core.xcontent.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@Sq-eng Sq-eng requested a deployment to ml-commons-cicd-env-require-approval August 26, 2025 05:09 — with GitHub Actions Waiting

HashMap<String, String> paramMap = new HashMap<>();
for (Map.Entry<String, Object> entry : tempMap.entrySet()) {
paramMap.put(entry.getKey(), entry.getValue() != null ? entry.getValue().toString() : null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the Object is a map/list type, the toString by default returns their address in memory instead of a json, it seems not correct here, do you have test cases to cover this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve addressed this issue by updating the code so that all types except basic types and String are serialized to JSON strings. Also added a unit test.

@zane-neo
Copy link
Collaborator

Patch coverage is 60.00000% with 8 lines in your changes missing coverage.

The code coverage in this PR is little bit low, can you add more UTs to increase the coverage?

@Sq-eng
Copy link
Contributor Author

Sq-eng commented Aug 26, 2025

Patch coverage is 60.00000% with 8 lines in your changes missing coverage.

The code coverage in this PR is little bit low, can you add more UTs to increase the coverage?

I've already added UT for it. But the Codecov Report hasn't been updated yet. Could you please allow CI/CD so it can rerun the test?

@Sq-eng Sq-eng requested a deployment to ml-commons-cicd-env-require-approval August 26, 2025 08:43 — with GitHub Actions Waiting
@Sq-eng Sq-eng requested a deployment to ml-commons-cicd-env-require-approval August 26, 2025 08:43 — with GitHub Actions Waiting
@Sq-eng Sq-eng requested a deployment to ml-commons-cicd-env-require-approval August 26, 2025 08:43 — with GitHub Actions Waiting
@Sq-eng Sq-eng requested a deployment to ml-commons-cicd-env-require-approval August 26, 2025 08:43 — with GitHub Actions Waiting
Comment on lines 259 to 272
HashMap<String, String> paramMap = new HashMap<>();
for (Map.Entry<String, Object> entry : tempMap.entrySet()) {
Object value = entry.getValue();
if (value == null) {
paramMap.put(entry.getKey(), null);
} else if (value instanceof String) {
paramMap.put(entry.getKey(), value.toString());
} else {
try {
String jsonValue = StringUtils.MAPPER.writeValueAsString(value);
paramMap.put(entry.getKey(), jsonValue);
} catch (JsonProcessingException e) {
paramMap.put(entry.getKey(), null);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part can be replaced with the existing util method: getParameterMap in org.opensearch.ml.common.utils.StringUtils, right? A good practice in coding is reusing and avoid duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. I’ve updated the code to reuse getParameterMap from StringUtils to avoid duplication. Thanks for the suggestion!

@Sq-eng Sq-eng temporarily deployed to ml-commons-cicd-env-require-approval August 27, 2025 09:38 — with GitHub Actions Inactive
@Sq-eng Sq-eng temporarily deployed to ml-commons-cicd-env-require-approval August 27, 2025 09:38 — with GitHub Actions Inactive
@Sq-eng Sq-eng temporarily deployed to ml-commons-cicd-env-require-approval August 27, 2025 09:38 — with GitHub Actions Inactive
@Sq-eng Sq-eng temporarily deployed to ml-commons-cicd-env-require-approval August 27, 2025 09:38 — with GitHub Actions Inactive
zane-neo
zane-neo previously approved these changes Aug 28, 2025
@Sq-eng Sq-eng temporarily deployed to ml-commons-cicd-env-require-approval August 28, 2025 04:27 — with GitHub Actions Inactive
@Sq-eng Sq-eng temporarily deployed to ml-commons-cicd-env-require-approval August 28, 2025 04:27 — with GitHub Actions Inactive
@Sq-eng Sq-eng temporarily deployed to ml-commons-cicd-env-require-approval August 28, 2025 07:47 — with GitHub Actions Inactive
@Sq-eng Sq-eng temporarily deployed to ml-commons-cicd-env-require-approval August 28, 2025 07:47 — with GitHub Actions Inactive
@Sq-eng Sq-eng temporarily deployed to ml-commons-cicd-env-require-approval August 28, 2025 07:47 — with GitHub Actions Inactive
@Sq-eng Sq-eng temporarily deployed to ml-commons-cicd-env-require-approval August 28, 2025 07:47 — with GitHub Actions Inactive
@Sq-eng Sq-eng temporarily deployed to ml-commons-cicd-env-require-approval August 28, 2025 09:01 — with GitHub Actions Inactive
@Sq-eng Sq-eng temporarily deployed to ml-commons-cicd-env-require-approval August 28, 2025 09:01 — with GitHub Actions Inactive
@xinyual xinyual merged commit d077f31 into opensearch-project:main Aug 29, 2025
13 checks passed
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.

[FEATURE] Parameter Passing for Predict via Remote Connector
4 participants