Automate ELSER v2 Trained Models download

Hi,

I need to automate ELSER v2 Machine Learning Trained Models download into Elastic for integration testing purposes.

There is documentation on how to download ELSER v2 from local files https://www.elastic.co/guide/en/machine-learning/current/ml-nlp-elser.html#_using_file_based_access. But it requires some manual operations in Kibana (Machine Learning -> Trained Models -> Add trained model -> Download)

I'd like to download ELSER v2 files to local file system and automatically download this Model into Elastic without any interaction with Kibana for integration testing purposes.

I reviewed available APIs https://www.elastic.co/guide/en/elasticsearch/reference/current/put-trained-models.html and was able to compose "Create trained models API", but the model cannot be started because index with model dictionary is not initialized during this API call.

Could you please suggest how it is possible to automatically download and deploy ELSER v2 into Elastic?

Thank you in advance,
Gleb

Hi @GlebCA Welcome to the community

I think everything you are looking for is here

I have not loaded from a filesystem but I just ran these and it worked

Downloaded and start.

There is also python libraries for this beside just pure curl

sbrown$ curl -X PUT "localhost:9200/_ml/trained_models/.elser_model_2?pretty" -H 'Content-Type: application/json' -d'{  "input": { "field_names": ["text_field"] }}'

{
  "model_id" : ".elser_model_2",
  "model_type" : "pytorch",
  "model_package" : {
    "packaged_model_id" : "elser_model_2",
    "model_repository" : "https://ml-models.elastic.co",
    "minimum_version" : "11.0.0",
    "size" : 438123914,
    "sha256" : "2e0450a1c598221a919917cbb05d8672aed6c613c028008fedcd696462c81af0",
    "metadata" : { },
    "tags" : [ ],
    "vocabulary_file" : "elser_model_2.vocab.json"
  },
  "created_by" : "api_user",
  "version" : "12.0.0",
  "create_time" : 1710191067705,
  "model_size_bytes" : 0,
  "estimated_operations" : 0,
  "license_level" : "platinum",
  "description" : "Elastic Learned Sparse EncodeR v2",
  "tags" : [
    "elastic"
  ],
  "metadata" : { },
  "input" : {
    "field_names" : [
      "text_field"
    ]
  },
  "inference_config" : {
    "text_expansion" : {
      "vocabulary" : {
        "index" : ".ml-inference-native-000002"
      },
      "tokenization" : {
        "bert" : {
          "do_lower_case" : true,
          "with_special_tokens" : true,
          "max_sequence_length" : 512,
          "truncate" : "first",
          "span" : -1
        }
      }
    }
  },
  "location" : {
    "index" : {
      "name" : ".ml-inference-native-000002"
    }
  }
}

hyperion:docker sbrown$ 

hyperion:docker sbrown$ curl -X POST "localhost:9200/_ml/trained_models/.elser_model_2/deployment/_start?deployment_id=for_search&pretty"
{
  "assignment" : {
    "task_parameters" : {
      "model_id" : ".elser_model_2",
      "deployment_id" : "for_search",
      "model_bytes" : 438123914,
      "threads_per_allocation" : 1,
      "number_of_allocations" : 1,
      "queue_capacity" : 1024,
      "cache_size" : "438123914b",
      "priority" : "normal",
      "per_deployment_memory_bytes" : 0,
      "per_allocation_memory_bytes" : 0
    },
    "routing_table" : {
      "xrWfSmBySNaLakwl5N46XQ" : {
        "current_allocations" : 1,
        "target_allocations" : 1,
        "routing_state" : "started",
        "reason" : ""
      }
    },
    "assignment_state" : "started",
    "start_time" : "2024-03-11T21:05:36.439254475Z",
    "max_assigned_allocations" : 1
  }
}
hyperion:docker sbrown$

Great, thank you for the quick help!

The model was deployed successfully. The only concern I have is a message in Kibana -> Machine Learning -> Trained Models:

ML job and trained model synchronization required
Some jobs or trained models are missing or have incomplete saved objects. Synchronize your jobs and trained models.

It is necessary to synchronize? Can synchronization be done via API?

I think that is a UI thing
I can tell you I have loaded and used the models without ever logging into Kibana.

I have a slightly dated Collab notebook that does everything... No Kibana.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.