|
38 | 38 | }, |
39 | 39 | { |
40 | 40 | "cell_type": "code", |
41 | | - "execution_count": null, |
| 41 | + "execution_count": 1, |
42 | 42 | "metadata": { |
43 | 43 | "colab": { |
44 | 44 | "base_uri": "https://localhost:8080/" |
|
129 | 129 | }, |
130 | 130 | { |
131 | 131 | "cell_type": "code", |
132 | | - "execution_count": 12, |
| 132 | + "execution_count": 4, |
133 | 133 | "metadata": { |
134 | 134 | "colab": { |
135 | 135 | "base_uri": "https://localhost:8080/" |
|
173 | 173 | }, |
174 | 174 | { |
175 | 175 | "cell_type": "code", |
176 | | - "execution_count": 6, |
| 176 | + "execution_count": 39, |
177 | 177 | "metadata": {}, |
178 | | - "outputs": [], |
| 178 | + "outputs": [ |
| 179 | + { |
| 180 | + "name": "stdout", |
| 181 | + "output_type": "stream", |
| 182 | + "text": [ |
| 183 | + "Model deleted successfully, We will proceed with creating one\n" |
| 184 | + ] |
| 185 | + }, |
| 186 | + { |
| 187 | + "name": "stderr", |
| 188 | + "output_type": "stream", |
| 189 | + "text": [ |
| 190 | + "/var/folders/_8/2nxt7jjx27bd8bm5lw63ht340000gn/T/ipykernel_34494/2089429255.py:3: ElasticsearchWarning: The default [remove_binary] value of 'false' is deprecated and will be set to 'true' in a future release. Set [remove_binary] explicitly to 'true' or 'false' to ensure no behavior change.\n", |
| 191 | + " client.ml.delete_trained_model(model_id=\".elser_model_2\",force=True)\n" |
| 192 | + ] |
| 193 | + }, |
| 194 | + { |
| 195 | + "data": { |
| 196 | + "text/plain": [ |
| 197 | + "ObjectApiResponse({'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': '11.0.0', 'create_time': 1701689920521, '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'}}})" |
| 198 | + ] |
| 199 | + }, |
| 200 | + "execution_count": 39, |
| 201 | + "metadata": {}, |
| 202 | + "output_type": "execute_result" |
| 203 | + } |
| 204 | + ], |
179 | 205 | "source": [ |
180 | 206 | "# delete model if already downloaded and deployed\n", |
181 | 207 | "try:\n", |
|
202 | 228 | }, |
203 | 229 | { |
204 | 230 | "cell_type": "code", |
205 | | - "execution_count": 10, |
| 231 | + "execution_count": 40, |
206 | 232 | "metadata": {}, |
207 | 233 | "outputs": [ |
208 | 234 | { |
|
237 | 263 | }, |
238 | 264 | { |
239 | 265 | "cell_type": "code", |
240 | | - "execution_count": 11, |
| 266 | + "execution_count": 41, |
241 | 267 | "metadata": {}, |
242 | 268 | "outputs": [ |
243 | 269 | { |
244 | | - "ename": "BadRequestError", |
245 | | - "evalue": "BadRequestError(400, 'status_exception', 'Could not start model deployment because an existing deployment with the same id [.elser_model_2] exist')", |
246 | | - "output_type": "error", |
247 | | - "traceback": [ |
248 | | - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
249 | | - "\u001b[0;31mBadRequestError\u001b[0m Traceback (most recent call last)", |
250 | | - "\u001b[1;32m/Users/joe/projects/elastic/elasticsearch-labs/notebooks/search/03-ELSER.ipynb Cell 16\u001b[0m line \u001b[0;36m2\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/joe/projects/elastic/elasticsearch-labs/notebooks/search/03-ELSER.ipynb#X21sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m \u001b[39m# Start trained model deployment if not already deployed\u001b[39;00m\n\u001b[0;32m----> <a href='vscode-notebook-cell:/Users/joe/projects/elastic/elasticsearch-labs/notebooks/search/03-ELSER.ipynb#X21sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m client\u001b[39m.\u001b[39;49mml\u001b[39m.\u001b[39;49mstart_trained_model_deployment(\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/joe/projects/elastic/elasticsearch-labs/notebooks/search/03-ELSER.ipynb#X21sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m model_id\u001b[39m=\u001b[39;49m\u001b[39m\"\u001b[39;49m\u001b[39m.elser_model_2\u001b[39;49m\u001b[39m\"\u001b[39;49m,\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/joe/projects/elastic/elasticsearch-labs/notebooks/search/03-ELSER.ipynb#X21sZmlsZQ%3D%3D?line=3'>4</a>\u001b[0m number_of_allocations\u001b[39m=\u001b[39;49m\u001b[39m1\u001b[39;49m\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/joe/projects/elastic/elasticsearch-labs/notebooks/search/03-ELSER.ipynb#X21sZmlsZQ%3D%3D?line=4'>5</a>\u001b[0m )\n", |
251 | | - "File \u001b[0;32m~/.pyenv/versions/3.10.3/lib/python3.10/site-packages/elasticsearch/_sync/client/utils.py:402\u001b[0m, in \u001b[0;36m_rewrite_parameters.<locals>.wrapper.<locals>.wrapped\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 399\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mKeyError\u001b[39;00m:\n\u001b[1;32m 400\u001b[0m \u001b[39mpass\u001b[39;00m\n\u001b[0;32m--> 402\u001b[0m \u001b[39mreturn\u001b[39;00m api(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n", |
252 | | - "File \u001b[0;32m~/.pyenv/versions/3.10.3/lib/python3.10/site-packages/elasticsearch/_sync/client/ml.py:3655\u001b[0m, in \u001b[0;36mMlClient.start_trained_model_deployment\u001b[0;34m(self, model_id, cache_size, error_trace, filter_path, human, number_of_allocations, pretty, priority, queue_capacity, threads_per_allocation, timeout, wait_for)\u001b[0m\n\u001b[1;32m 3653\u001b[0m __query[\u001b[39m\"\u001b[39m\u001b[39mwait_for\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m wait_for\n\u001b[1;32m 3654\u001b[0m __headers \u001b[39m=\u001b[39m {\u001b[39m\"\u001b[39m\u001b[39maccept\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mapplication/json\u001b[39m\u001b[39m\"\u001b[39m}\n\u001b[0;32m-> 3655\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mperform_request( \u001b[39m# type: ignore[return-value]\u001b[39;49;00m\n\u001b[1;32m 3656\u001b[0m \u001b[39m\"\u001b[39;49m\u001b[39mPOST\u001b[39;49m\u001b[39m\"\u001b[39;49m, __path, params\u001b[39m=\u001b[39;49m__query, headers\u001b[39m=\u001b[39;49m__headers\n\u001b[1;32m 3657\u001b[0m )\n", |
253 | | - "File \u001b[0;32m~/.pyenv/versions/3.10.3/lib/python3.10/site-packages/elasticsearch/_sync/client/_base.py:389\u001b[0m, in \u001b[0;36mNamespacedClient.perform_request\u001b[0;34m(self, method, path, params, headers, body)\u001b[0m\n\u001b[1;32m 378\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mperform_request\u001b[39m(\n\u001b[1;32m 379\u001b[0m \u001b[39mself\u001b[39m,\n\u001b[1;32m 380\u001b[0m method: \u001b[39mstr\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 387\u001b[0m \u001b[39m# Use the internal clients .perform_request() implementation\u001b[39;00m\n\u001b[1;32m 388\u001b[0m \u001b[39m# so we take advantage of their transport options.\u001b[39;00m\n\u001b[0;32m--> 389\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_client\u001b[39m.\u001b[39;49mperform_request(\n\u001b[1;32m 390\u001b[0m method, path, params\u001b[39m=\u001b[39;49mparams, headers\u001b[39m=\u001b[39;49mheaders, body\u001b[39m=\u001b[39;49mbody\n\u001b[1;32m 391\u001b[0m )\n", |
254 | | - "File \u001b[0;32m~/.pyenv/versions/3.10.3/lib/python3.10/site-packages/elasticsearch/_sync/client/_base.py:320\u001b[0m, in \u001b[0;36mBaseClient.perform_request\u001b[0;34m(self, method, path, params, headers, body)\u001b[0m\n\u001b[1;32m 317\u001b[0m \u001b[39mexcept\u001b[39;00m (\u001b[39mValueError\u001b[39;00m, \u001b[39mKeyError\u001b[39;00m, \u001b[39mTypeError\u001b[39;00m):\n\u001b[1;32m 318\u001b[0m \u001b[39mpass\u001b[39;00m\n\u001b[0;32m--> 320\u001b[0m \u001b[39mraise\u001b[39;00m HTTP_EXCEPTIONS\u001b[39m.\u001b[39mget(meta\u001b[39m.\u001b[39mstatus, ApiError)(\n\u001b[1;32m 321\u001b[0m message\u001b[39m=\u001b[39mmessage, meta\u001b[39m=\u001b[39mmeta, body\u001b[39m=\u001b[39mresp_body\n\u001b[1;32m 322\u001b[0m )\n\u001b[1;32m 324\u001b[0m \u001b[39m# 'X-Elastic-Product: Elasticsearch' should be on every 2XX response.\u001b[39;00m\n\u001b[1;32m 325\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_verified_elasticsearch:\n\u001b[1;32m 326\u001b[0m \u001b[39m# If the header is set we mark the server as verified.\u001b[39;00m\n", |
255 | | - "\u001b[0;31mBadRequestError\u001b[0m: BadRequestError(400, 'status_exception', 'Could not start model deployment because an existing deployment with the same id [.elser_model_2] exist')" |
| 270 | + "name": "stdout", |
| 271 | + "output_type": "stream", |
| 272 | + "text": [ |
| 273 | + "ELSER Model is currently being deployed.\n", |
| 274 | + "ELSER Model is currently being deployed.\n", |
| 275 | + "ELSER Model has been successfully deployed.\n" |
256 | 276 | ] |
257 | 277 | } |
258 | 278 | ], |
259 | 279 | "source": [ |
260 | 280 | "# Start trained model deployment if not already deployed\n", |
261 | 281 | "client.ml.start_trained_model_deployment(\n", |
262 | 282 | " model_id=\".elser_model_2\",\n", |
263 | | - " number_of_allocations=1\n", |
264 | | - ")\n" |
| 283 | + " number_of_allocations=1,\n", |
| 284 | + " wait_for=\"starting\"\n", |
| 285 | + ")\n", |
| 286 | + "\n", |
| 287 | + "while True:\n", |
| 288 | + " status = client.ml.get_trained_models_stats(\n", |
| 289 | + " model_id=\".elser_model_2\",\n", |
| 290 | + " )\n", |
| 291 | + " if (status[\"trained_model_stats\"][0][\"deployment_stats\"][\"state\"] == \"started\"):\n", |
| 292 | + " print(\"ELSER Model has been successfully deployed.\")\n", |
| 293 | + " break\n", |
| 294 | + " else:\n", |
| 295 | + " print(\"ELSER Model is currently being deployed.\")\n", |
| 296 | + " time.sleep(5)\n", |
| 297 | + "\n", |
| 298 | + "\n" |
265 | 299 | ] |
266 | 300 | }, |
267 | 301 | { |
|
286 | 320 | }, |
287 | 321 | { |
288 | 322 | "cell_type": "code", |
289 | | - "execution_count": null, |
| 323 | + "execution_count": 42, |
290 | 324 | "metadata": { |
291 | 325 | "colab": { |
292 | 326 | "base_uri": "https://localhost:8080/" |
293 | 327 | }, |
294 | 328 | "id": "XhRng99KLQsd", |
295 | 329 | "outputId": "00ea73b5-45a4-472b-f4bc-2c2c790ab94d" |
296 | 330 | }, |
297 | | - "outputs": [], |
| 331 | + "outputs": [ |
| 332 | + { |
| 333 | + "data": { |
| 334 | + "text/plain": [ |
| 335 | + "ObjectApiResponse({'acknowledged': True})" |
| 336 | + ] |
| 337 | + }, |
| 338 | + "execution_count": 42, |
| 339 | + "metadata": {}, |
| 340 | + "output_type": "execute_result" |
| 341 | + } |
| 342 | + ], |
298 | 343 | "source": [ |
299 | 344 | "client.ingest.put_pipeline(\n", |
300 | 345 | " id=\"elser-ingest-pipeline\", \n", |
|
349 | 394 | }, |
350 | 395 | { |
351 | 396 | "cell_type": "code", |
352 | | - "execution_count": 162, |
| 397 | + "execution_count": 46, |
353 | 398 | "metadata": { |
354 | 399 | "colab": { |
355 | 400 | "base_uri": "https://localhost:8080/" |
|
364 | 409 | "ObjectApiResponse({'acknowledged': True, 'shards_acknowledged': True, 'index': 'elser-example-movies'})" |
365 | 410 | ] |
366 | 411 | }, |
367 | | - "execution_count": 162, |
| 412 | + "execution_count": 46, |
368 | 413 | "metadata": {}, |
369 | 414 | "output_type": "execute_result" |
370 | 415 | } |
|
375 | 420 | " index=\"elser-example-movies\",\n", |
376 | 421 | " settings={\n", |
377 | 422 | " \"index\": {\n", |
378 | | - " \"number_of_shards\": 1,\n", |
379 | | - " \"number_of_replicas\": 1,\n", |
380 | 423 | " \"default_pipeline\": \"elser-ingest-pipeline\"\n", |
381 | 424 | " }\n", |
382 | 425 | " },\n", |
|
414 | 457 | }, |
415 | 458 | { |
416 | 459 | "cell_type": "code", |
417 | | - "execution_count": 163, |
| 460 | + "execution_count": 44, |
418 | 461 | "metadata": { |
419 | 462 | "colab": { |
420 | 463 | "base_uri": "https://localhost:8080/" |
|
482 | 525 | }, |
483 | 526 | { |
484 | 527 | "cell_type": "code", |
485 | | - "execution_count": 164, |
| 528 | + "execution_count": 45, |
486 | 529 | "metadata": { |
487 | 530 | "colab": { |
488 | 531 | "base_uri": "https://localhost:8080/" |
|
0 commit comments