Skip to content

Use a FunctionName.REMOTE for all ML inference requests - #1897

Closed
heemin32 wants to merge 1 commit into
opensearch-project:mainfrom
heemin32:funtionname
Closed

Use a FunctionName.REMOTE for all ML inference requests#1897
heemin32 wants to merge 1 commit into
opensearch-project:mainfrom
heemin32:funtionname

Conversation

@heemin32

@heemin32 heemin32 commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Description

FunctionName is not used by ml-commons for inference, so centralize it as a single FunctionName.REMOTE and remove it from all internal method signatures to avoid confusion.

Related Issues

opensearch-project/ml-commons#4891

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.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

PR Code Analyzer ❗

AI-powered 'Code-Diff-Analyzer' found issues on commit 800191f.

PathLineSeverityDescription
src/test/java/org/opensearch/neuralsearch/ml/NeuralSearchMLInputBuilderTests.java71lowTest renamed from 'testCreateTextEmbeddingInput_remoteSymmetricModel_throwsException' and assertions on FunctionName removed. The removal of algorithm-type assertions reduces test coverage on behavior that changed (all inputs now use FunctionName.REMOTE). Worth verifying the claim in the comment that FunctionName is unused during inference is accurate for all model types.

The table above displays the top 10 most important findings.

Total: 1 | Critical: 0 | High: 0 | Medium: 0 | Low: 1


Pull Requests Author(s): Please update your Pull Request according to the report above.

Repository Maintainer(s): You can bypass diff analyzer by adding label skip-diff-analyzer after reviewing the changes carefully, then re-run failed actions. To re-enable the analyzer, remove the label, then re-run all actions.


⚠️ Note: The Code-Diff-Analyzer helps protect against potentially harmful code patterns. Please ensure you have thoroughly reviewed the changes beforehand.

Thanks.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit bbc551c)

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ Recommended focus areas for review

Parameter Type Change

createRemoteInput was changed to accept Map<String, String> instead of Map<String, Object>. The previous implementation converted non-string values via toString() and handled nulls. Any callers passing non-string values (or code paths previously relying on that conversion) will now fail to compile or lose functionality. Verify no external callers depend on the old signature and that all values put into the parameters map are already strings.

private static MLInput createRemoteInput(Map<String, String> parameters) {
    return createMLInput(new RemoteInferenceInputDataSet(parameters), null);
}

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Preserve correct FunctionName for local inference

Using FunctionName.REMOTE unconditionally for local model inference paths (e.g.,
TextDocsInputDataSet, TextSimilarityInputDataSet, QuestionAnsweringInputDataSet) may
break local model inference, since ml-commons routes execution based on the
algorithm/function name. The comment claims FunctionName is not used, but this is
not universally true for local models. Verify that ml-commons dispatches inference
correctly for local models when the algorithm is set to REMOTE, otherwise retain the
original per-dataset function names.

src/main/java/org/opensearch/neuralsearch/ml/NeuralSearchMLInputBuilder.java [75-78]

 private static MLInput createMLInput(MLInputDataset inputDataset, MLAlgoParams mlAlgoParams) {
-    // FunctionName is not used by ml-commons for inference, so any value can be passed.
-    return new MLInput(FunctionName.REMOTE, mlAlgoParams, inputDataset);
+    FunctionName functionName;
+    if (inputDataset instanceof RemoteInferenceInputDataSet) {
+        functionName = FunctionName.REMOTE;
+    } else if (inputDataset instanceof TextSimilarityInputDataSet) {
+        functionName = FunctionName.TEXT_SIMILARITY;
+    } else if (inputDataset instanceof QuestionAnsweringInputDataSet) {
+        functionName = FunctionName.QUESTION_ANSWERING;
+    } else {
+        functionName = FunctionName.TEXT_EMBEDDING;
+    }
+    return new MLInput(functionName, mlAlgoParams, inputDataset);
 }
Suggestion importance[1-10]: 8

__

Why: This is a valid concern - using FunctionName.REMOTE unconditionally for local inference datasets like TextDocsInputDataSet, TextSimilarityInputDataSet, and QuestionAnsweringInputDataSet could break local model inference routing in ml-commons. The suggestion highlights a potentially significant behavioral regression that warrants verification.

Medium

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.44%. Comparing base (a5e4e8f) to head (bbc551c).

Files with missing lines Patch % Lines
...ch/neuralsearch/ml/NeuralSearchMLInputBuilder.java 91.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1897      +/-   ##
============================================
- Coverage     83.46%   83.44%   -0.03%     
+ Complexity     3893     3891       -2     
============================================
  Files           291      291              
  Lines         13835    13829       -6     
  Branches       2300     2298       -2     
============================================
- Hits          11547    11539       -8     
- Misses         1455     1457       +2     
  Partials        833      833              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

FunctionName is not used by ml-commons for inference, so centralize
it as a single DEFAULT_FUNCTION_NAME constant (REMOTE) and remove it
from all internal method signatures to avoid confusion.

Signed-off-by: Heemin Kim <heemin@amazon.com>
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit bbc551c

@heemin32

heemin32 commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author
The AsymmetricTextEmbeddingParameters is annotated with:
  @MLAlgoParameter(algorithms = { FunctionName.TEXT_EMBEDDING,
  FunctionName.SPARSE_ENCODING, FunctionName.SPARSE_TOKENIZE })

  This means parameterClassMap maps TEXT_EMBEDDING →
  AsymmetricTextEmbeddingParameters, but there is no mapping for REMOTE.

  Now here's where the error happens. When the predict request is
  serialized over transport (even to the local node), it goes through:

  // MLInput.java line 115-118
  public MLInput(StreamInput in) throws IOException {
      this.algorithm = in.readEnum(FunctionName.class);  // reads REMOTE
      if (in.readBoolean()) {
          this.parameters =
  MLCommonsClassLoader.initMLInstance(algorithm, in, StreamInput.class);
   // tries to deserialize params for REMOTE
      }
  }

  When parameters != null (which it is for asymmetric models —
  AsymmetricTextEmbeddingParameters), it's written to the stream. On
  deserialization, initMLInstance(REMOTE, in, StreamInput.class) looks
  up REMOTE in parameterClassMap and throws "Can't find class for type
  REMOTE" because REMOTE has no registered parameter class.

  Summary: The exception is thrown during transport deserialization of
  the MLInput. The predict request is serialized for transport (even on
  a single-node cluster, the transport layer still
  serializes/deserializes). Since AsymmetricTextEmbeddingParameters is
  passed with algorithm = REMOTE, and parameterClassMap has no entry for
  REMOTE, it fails with "Can't find class for type REMOTE" when trying
  to reconstruct the parameters on the receiving end.[3:50 PM]
┌─────────────────────┬───────────────────────────────────┐
  │    FunctionName     │          Parameter Class          │
  ├─────────────────────┼───────────────────────────────────┤
  │ KMEANS              │ KMeansParams                      │
  ├─────────────────────┼───────────────────────────────────┤
  │ RCF_SUMMARIZE       │ RCFSummarizeParams                │
  ├─────────────────────┼───────────────────────────────────┤
  │ AD_LIBSVM           │ AnomalyDetectionLibSVMParams      │
  ├─────────────────────┼───────────────────────────────────┤
  │ FIT_RCF             │ FitRCFParams                      │
  ├─────────────────────┼───────────────────────────────────┤
  │ TEXT_EMBEDDING      │ AsymmetricTextEmbeddingParameters │
  ├─────────────────────┼───────────────────────────────────┤
  │ SPARSE_ENCODING     │ AsymmetricTextEmbeddingParameters │
  ├─────────────────────┼───────────────────────────────────┤
  │ SPARSE_TOKENIZE     │ AsymmetricTextEmbeddingParameters │
  ├─────────────────────┼───────────────────────────────────┤
  │ BATCH_RCF           │ BatchRCFParams                    │
  ├─────────────────────┼───────────────────────────────────┤
  │ LOGISTIC_REGRESSION │ LogisticRegressionParams          │
  ├─────────────────────┼───────────────────────────────────┤
  │ SAMPLE_ALGO         │ SampleAlgoParams                  │
  ├─────────────────────┼───────────────────────────────────┤
  │ LINEAR_REGRESSION   │ LinearRegressionParams            │
  └─────────────────────┴───────────────────────────────────┘

@heemin32 heemin32 closed this Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant