Skip to content

TypeError: client.ml.inferTrainedModel is not a function #1747

@truskavets-transf

Description

@truskavets-transf

🐛 Bug Report

The inferTrainedModel method is not recognized.

I am trying to create a semantic search functionality using Elastic and a Next.js frontend. As part of this process, I need to convert a string into an embedding vector.

I am able to do this in the dev console without any issues:

POST /_ml/trained_models/<model_id>/_infer
{
  "docs": {
    "text_field": "test string"
  }
}

However, when I try to call the same method using this library, I get an error saying that the method is not recognized:

TypeError: client.ml.inferTrainedModel is not a function

The relevant code from the API route is here:

    try {
      const test = await client.ml.inferTrainedModel({
        index: 'embeddings-test',
        model_id: <model_id>,
        docs: { text_field: req.body },
      });

As a sanity check, I was able to successfully access other methods in the ml class, like the getTrainedModelStats method.

To Reproduce

Steps to reproduce the behavior:

  1. upload transformer model to Elastic (in this case, a custom fine-tuned BERT model)
  2. create dense vector field in mapping
  3. create API route to the inferTrainedModel endpoint in Next.js
  4. send string to this route

Expected behavior

An embedding vector in response to the inferTrainedModel request.

Your Environment

  • node version: 18.2.0
  • @elastic/elasticsearch version: 8.2.1
  • os: Mac
  • framework: Next.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions