Skip to content

Commit 8948851

Browse files
authored
Updates the semantic text tutorial to use EIS (#490)
1 parent 9790974 commit 8948851

File tree

2 files changed

+6
-108
lines changed

2 files changed

+6
-108
lines changed

bin/find-notebooks-to-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ EXEMPT_NOTEBOOKS=(
55
"notebooks/esql/esql-getting-started.ipynb"
66
"notebooks/search/07-inference.ipynb"
77
"notebooks/search/08-learning-to-rank.ipynb"
8+
"notebooks/search/09-semantic-text.ipynb"
89
"notebooks/search/10-semantic-reranking-retriever-cohere.ipynb"
910
"notebooks/search/11-semantic-reranking-hugging-face.ipynb"
1011
"notebooks/search/12-semantic-reranking-elastic-rerank.ipynb"
@@ -57,7 +58,6 @@ EXEMPT_NOTEBOOKS__8_12=(
5758

5859
EXEMPT_NOTEBOOKS__8_14=(
5960
# Add any notebooks that must be skipped on versions 8.14 or older here
60-
"notebooks/search/09-semantic-text.ipynb",
6161
# This notebook has the text_expansion deprecation notice for 8.15.
6262
# Only running on 8.15 so includes the deprecation notice and newer so the local output is the same as CI
6363
"notebooks/langchain/langchain-vector-store-using-elser.ipynb",

notebooks/search/09-semantic-text.ipynb

Lines changed: 5 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"- An Elastic deployment:\n",
3535
" - 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",
3636
"\n",
37-
"- Elasticsearch 8.15 or above, or [Elasticsearch serverless](https://www.elastic.co/elasticsearch/serverless)"
37+
"- Elasticsearch 9.1 or above, or [Elasticsearch serverless](https://www.elastic.co/elasticsearch/serverless)"
3838
]
3939
},
4040
{
@@ -84,7 +84,7 @@
8484
},
8585
"outputs": [],
8686
"source": [
87-
"!pip install \"elasticsearch<9\""
87+
"!pip install elasticsearch"
8888
]
8989
},
9090
{
@@ -241,109 +241,6 @@
241241
"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."
242242
]
243243
},
244-
{
245-
"cell_type": "markdown",
246-
"id": "22fa643780acd44a",
247-
"metadata": {
248-
"collapsed": false,
249-
"jupyter": {
250-
"outputs_hidden": false
251-
}
252-
},
253-
"source": [
254-
"## Create the Inference Endpoint\n",
255-
"\n",
256-
"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",
257-
"\n",
258-
"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)."
259-
]
260-
},
261-
{
262-
"cell_type": "code",
263-
"execution_count": null,
264-
"id": "8ee2188ea71324f5",
265-
"metadata": {
266-
"collapsed": false,
267-
"jupyter": {
268-
"outputs_hidden": false
269-
}
270-
},
271-
"outputs": [],
272-
"source": [
273-
"try:\n",
274-
" client.inference.delete(inference_id=\"my-elser-endpoint\")\n",
275-
"except exceptions.NotFoundError:\n",
276-
" # Inference endpoint does not exist\n",
277-
" pass\n",
278-
"\n",
279-
"try:\n",
280-
" client.options(\n",
281-
" request_timeout=60, max_retries=3, retry_on_timeout=True\n",
282-
" ).inference.put(\n",
283-
" task_type=\"sparse_embedding\",\n",
284-
" inference_id=\"my-elser-endpoint\",\n",
285-
" body={\n",
286-
" \"service\": \"elser\",\n",
287-
" \"service_settings\": {\"num_allocations\": 1, \"num_threads\": 1},\n",
288-
" },\n",
289-
" )\n",
290-
" print(\"Inference endpoint created successfully\")\n",
291-
"except exceptions.BadRequestError as e:\n",
292-
" if e.error == \"resource_already_exists_exception\":\n",
293-
" print(\"Inference endpoint created successfully\")\n",
294-
" else:\n",
295-
" raise e"
296-
]
297-
},
298-
{
299-
"cell_type": "markdown",
300-
"id": "e94fd66761fd8087",
301-
"metadata": {
302-
"collapsed": false,
303-
"jupyter": {
304-
"outputs_hidden": false
305-
}
306-
},
307-
"source": [
308-
"Once the endpoint is created, we must wait until the backing ELSER service is deployed.\n",
309-
"This can take a few minutes to complete."
310-
]
311-
},
312-
{
313-
"cell_type": "code",
314-
"execution_count": null,
315-
"id": "adb33329ce20b2f1",
316-
"metadata": {
317-
"collapsed": false,
318-
"jupyter": {
319-
"outputs_hidden": false
320-
}
321-
},
322-
"outputs": [],
323-
"source": [
324-
"inference_endpoint_info = client.inference.get(inference_id=\"my-elser-endpoint\")\n",
325-
"model_id = inference_endpoint_info[\"endpoints\"][0][\"service_settings\"][\"model_id\"]\n",
326-
"\n",
327-
"while True:\n",
328-
" status = client.ml.get_trained_models_stats(\n",
329-
" model_id=model_id,\n",
330-
" )\n",
331-
"\n",
332-
" deployment_stats = status[\"trained_model_stats\"][0].get(\"deployment_stats\")\n",
333-
" if deployment_stats is None:\n",
334-
" print(\"ELSER Model is currently being deployed.\")\n",
335-
" time.sleep(5)\n",
336-
" continue\n",
337-
"\n",
338-
" nodes = deployment_stats.get(\"nodes\")\n",
339-
" if nodes is not None and len(nodes) > 0:\n",
340-
" print(\"ELSER Model has been successfully deployed.\")\n",
341-
" break\n",
342-
" else:\n",
343-
" print(\"ELSER Model is currently being deployed.\")\n",
344-
" time.sleep(5)"
345-
]
346-
},
347244
{
348245
"cell_type": "markdown",
349246
"id": "818f7a72a83b5776",
@@ -356,7 +253,8 @@
356253
"source": [
357254
"## Create the Index\n",
358255
"\n",
359-
"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."
256+
"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",
257+
"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)."
360258
]
361259
},
362260
{
@@ -381,7 +279,7 @@
381279
" \"plot\": {\"type\": \"text\", \"copy_to\": \"plot_semantic\"},\n",
382280
" \"plot_semantic\": {\n",
383281
" \"type\": \"semantic_text\",\n",
384-
" \"inference_id\": \"my-elser-endpoint\",\n",
282+
" \"inference_id\": \".elser-v2-elastic\",\n",
385283
" },\n",
386284
" }\n",
387285
" },\n",

0 commit comments

Comments
 (0)