From b4525d90cb60372a0b776a6e4e4ca8a370c137f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20Zolt=C3=A1n=20Szab=C3=B3?= Date: Wed, 24 Sep 2025 17:29:32 +0200 Subject: [PATCH 1/6] Updates the semantic text tutorial for using EIS. --- notebooks/search/09-semantic-text.ipynb | 110 +----------------------- 1 file changed, 4 insertions(+), 106 deletions(-) diff --git a/notebooks/search/09-semantic-text.ipynb b/notebooks/search/09-semantic-text.ipynb index 8a360a5c..920e6e7d 100644 --- a/notebooks/search/09-semantic-text.ipynb +++ b/notebooks/search/09-semantic-text.ipynb @@ -34,7 +34,7 @@ "- An Elastic deployment:\n", " - We'll be using [Elastic Cloud](https://www.elastic.co/guide/en/cloud/current/ec-getting-started.html) for this example (available with a [free trial](https://cloud.elastic.co/registration?onboarding_token=vectorsearch&utm_source=github&utm_content=elasticsearch-labs-notebook))\n", "\n", - "- Elasticsearch 8.15 or above, or [Elasticsearch serverless](https://www.elastic.co/elasticsearch/serverless)" + "- Elasticsearch 9.0 or above, or [Elasticsearch serverless](https://www.elastic.co/elasticsearch/serverless)" ] }, { @@ -241,109 +241,6 @@ "Read [this page](https://www.elastic.co/guide/en/elasticsearch/client/python-api/current/connecting.html#connect-self-managed-new) to learn how to connect using API keys." ] }, - { - "cell_type": "markdown", - "id": "22fa643780acd44a", - "metadata": { - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "source": [ - "## Create the Inference Endpoint\n", - "\n", - "Let's create the inference endpoint by using the [Create inference API](https://www.elastic.co/guide/en/elasticsearch/reference/current/put-inference-api.html).\n", - "\n", - "For this example we'll use the [ELSER service](https://www.elastic.co/guide/en/machine-learning/current/ml-nlp-elser.html), but the inference API also supports [many other inference services](https://www.elastic.co/guide/en/elasticsearch/reference/current/put-inference-api.html#put-inference-api-desc)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "8ee2188ea71324f5", - "metadata": { - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [], - "source": [ - "try:\n", - " client.inference.delete(inference_id=\"my-elser-endpoint\")\n", - "except exceptions.NotFoundError:\n", - " # Inference endpoint does not exist\n", - " pass\n", - "\n", - "try:\n", - " client.options(\n", - " request_timeout=60, max_retries=3, retry_on_timeout=True\n", - " ).inference.put(\n", - " task_type=\"sparse_embedding\",\n", - " inference_id=\"my-elser-endpoint\",\n", - " body={\n", - " \"service\": \"elser\",\n", - " \"service_settings\": {\"num_allocations\": 1, \"num_threads\": 1},\n", - " },\n", - " )\n", - " print(\"Inference endpoint created successfully\")\n", - "except exceptions.BadRequestError as e:\n", - " if e.error == \"resource_already_exists_exception\":\n", - " print(\"Inference endpoint created successfully\")\n", - " else:\n", - " raise e" - ] - }, - { - "cell_type": "markdown", - "id": "e94fd66761fd8087", - "metadata": { - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "source": [ - "Once the endpoint is created, we must wait until the backing ELSER service is deployed.\n", - "This can take a few minutes to complete." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "adb33329ce20b2f1", - "metadata": { - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [], - "source": [ - "inference_endpoint_info = client.inference.get(inference_id=\"my-elser-endpoint\")\n", - "model_id = inference_endpoint_info[\"endpoints\"][0][\"service_settings\"][\"model_id\"]\n", - "\n", - "while True:\n", - " status = client.ml.get_trained_models_stats(\n", - " model_id=model_id,\n", - " )\n", - "\n", - " deployment_stats = status[\"trained_model_stats\"][0].get(\"deployment_stats\")\n", - " if deployment_stats is None:\n", - " print(\"ELSER Model is currently being deployed.\")\n", - " time.sleep(5)\n", - " continue\n", - "\n", - " nodes = deployment_stats.get(\"nodes\")\n", - " if nodes is not None and len(nodes) > 0:\n", - " print(\"ELSER Model has been successfully deployed.\")\n", - " break\n", - " else:\n", - " print(\"ELSER Model is currently being deployed.\")\n", - " time.sleep(5)" - ] - }, { "cell_type": "markdown", "id": "818f7a72a83b5776", @@ -356,7 +253,8 @@ "source": [ "## Create the Index\n", "\n", - "Now we need to create an index with a `semantic_text` field. Let's create one that enables us to perform semantic search on movie plots." + "Now we need to create an index with a `semantic_text` field. Let's create one that enables us to perform semantic search on movie plots.\n", + "We use the preconfigured `.elser-2-elastic` inference endpoint which uses the ELSER model via the [Elastic Inference Service](https://www.elastic.co/docs/explore-analyze/elastic-inference/eis)." ] }, { @@ -381,7 +279,7 @@ " \"plot\": {\"type\": \"text\", \"copy_to\": \"plot_semantic\"},\n", " \"plot_semantic\": {\n", " \"type\": \"semantic_text\",\n", - " \"inference_id\": \"my-elser-endpoint\",\n", + " \"inference_id\": \".elser-2-elastic\",\n", " },\n", " }\n", " },\n", From 7cd8921129b9105e7113d9e52ed7df9ae9dff753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20Zolt=C3=A1n=20Szab=C3=B3?= Date: Wed, 24 Sep 2025 17:32:04 +0200 Subject: [PATCH 2/6] Changes version number. --- notebooks/search/09-semantic-text.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebooks/search/09-semantic-text.ipynb b/notebooks/search/09-semantic-text.ipynb index 920e6e7d..e81d9955 100644 --- a/notebooks/search/09-semantic-text.ipynb +++ b/notebooks/search/09-semantic-text.ipynb @@ -34,7 +34,7 @@ "- An Elastic deployment:\n", " - We'll be using [Elastic Cloud](https://www.elastic.co/guide/en/cloud/current/ec-getting-started.html) for this example (available with a [free trial](https://cloud.elastic.co/registration?onboarding_token=vectorsearch&utm_source=github&utm_content=elasticsearch-labs-notebook))\n", "\n", - "- Elasticsearch 9.0 or above, or [Elasticsearch serverless](https://www.elastic.co/elasticsearch/serverless)" + "- Elasticsearch 9.1 or above, or [Elasticsearch serverless](https://www.elastic.co/elasticsearch/serverless)" ] }, { From f16a00a9acb5000ca5e7504c8699854ea281d9c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20Zolt=C3=A1n=20Szab=C3=B3?= Date: Thu, 25 Sep 2025 11:25:28 +0200 Subject: [PATCH 3/6] Changes install command. --- notebooks/search/09-semantic-text.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebooks/search/09-semantic-text.ipynb b/notebooks/search/09-semantic-text.ipynb index e81d9955..2cb23638 100644 --- a/notebooks/search/09-semantic-text.ipynb +++ b/notebooks/search/09-semantic-text.ipynb @@ -84,7 +84,7 @@ }, "outputs": [], "source": [ - "!pip install \"elasticsearch<9\"" + "!pip install elasticsearch" ] }, { From 9a92e5807e241af89e5758c890975e0d56ab840d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20Zolt=C3=A1n=20Szab=C3=B3?= Date: Thu, 25 Sep 2025 12:26:51 +0200 Subject: [PATCH 4/6] Changes inference ID. --- notebooks/search/09-semantic-text.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebooks/search/09-semantic-text.ipynb b/notebooks/search/09-semantic-text.ipynb index 2cb23638..f80ea557 100644 --- a/notebooks/search/09-semantic-text.ipynb +++ b/notebooks/search/09-semantic-text.ipynb @@ -279,7 +279,7 @@ " \"plot\": {\"type\": \"text\", \"copy_to\": \"plot_semantic\"},\n", " \"plot_semantic\": {\n", " \"type\": \"semantic_text\",\n", - " \"inference_id\": \".elser-2-elastic\",\n", + " \"inference_id\": \".elser-v2-elastic\",\n", " },\n", " }\n", " },\n", From cc598cdab1fb2721f2fbb7858ffbc81e71991b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20Zolt=C3=A1n=20Szab=C3=B3?= Date: Thu, 25 Sep 2025 14:08:54 +0200 Subject: [PATCH 5/6] Adds notebook to allowlist. --- bin/find-notebooks-to-test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/find-notebooks-to-test.sh b/bin/find-notebooks-to-test.sh index cb65fbb8..352d6aa8 100755 --- a/bin/find-notebooks-to-test.sh +++ b/bin/find-notebooks-to-test.sh @@ -5,6 +5,7 @@ EXEMPT_NOTEBOOKS=( "notebooks/esql/esql-getting-started.ipynb" "notebooks/search/07-inference.ipynb" "notebooks/search/08-learning-to-rank.ipynb" + "notebooks/search/09-semantic-text.ipynb" "notebooks/search/10-semantic-reranking-retriever-cohere.ipynb" "notebooks/search/11-semantic-reranking-hugging-face.ipynb" "notebooks/search/12-semantic-reranking-elastic-rerank.ipynb" From dcfc6ae18e81f3b81a3db4b0fada7a555dd4b88f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20Zolt=C3=A1n=20Szab=C3=B3?= Date: Thu, 25 Sep 2025 14:36:49 +0200 Subject: [PATCH 6/6] Removes item from notebook exclude list. --- bin/find-notebooks-to-test.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/find-notebooks-to-test.sh b/bin/find-notebooks-to-test.sh index 352d6aa8..5f0e6ecb 100755 --- a/bin/find-notebooks-to-test.sh +++ b/bin/find-notebooks-to-test.sh @@ -58,7 +58,6 @@ EXEMPT_NOTEBOOKS__8_12=( EXEMPT_NOTEBOOKS__8_14=( # Add any notebooks that must be skipped on versions 8.14 or older here - "notebooks/search/09-semantic-text.ipynb", # This notebook has the text_expansion deprecation notice for 8.15. # Only running on 8.15 so includes the deprecation notice and newer so the local output is the same as CI "notebooks/langchain/langchain-vector-store-using-elser.ipynb",