Skip to content

Commit 695a866

Browse files
[Search] Updating Notebook to address inference_id is not required (#437)
1 parent 63284ab commit 695a866

File tree

1 file changed

+5
-88
lines changed

1 file changed

+5
-88
lines changed

notebooks/search/12-semantic-reranking-elastic-rerank.ipynb

+5-88
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
"\n",
1313
"In this notebook you'll learn how to implement semantic reranking in Elasticsearch using the built-in [Elastic Rerank model](https://www.elastic.co/guide/en/machine-learning/master/ml-nlp-rerank.html). You'll also learn about the `retriever` abstraction, a simpler syntax for crafting queries and combining different search operations.\n",
1414
"\n",
15-
"You will:\n",
16-
"\n",
17-
"- Create an inference endpoint to manage your `rerank` task. This will download and deploy the Elastic Rerank model.\n",
18-
"- Query your data using the `text_similarity_rerank` retriever, leveraging the Elastic Rerank model."
15+
"You will query your data using the `text_similarity_rerank` retriever, and the Elastic Rerank model to boost the relevance of your search results."
1916
]
2017
},
2118
{
@@ -234,87 +231,6 @@
234231
"time.sleep(3)"
235232
]
236233
},
237-
{
238-
"cell_type": "markdown",
239-
"metadata": {
240-
"id": "DRIABkGAgV_Q"
241-
},
242-
"source": [
243-
"## Create inference endpoint\n",
244-
"\n",
245-
"Next we'll create an inference endpoint for the `rerank` task to deploy and manage our model and, if necessary, spin up the necessary ML resources behind the scenes."
246-
]
247-
},
248-
{
249-
"cell_type": "code",
250-
"execution_count": null,
251-
"metadata": {
252-
"colab": {
253-
"base_uri": "https://localhost:8080/"
254-
},
255-
"id": "DiKsd3YygV_Q",
256-
"outputId": "c3c46c6b-b502-4167-c98c-d2e2e0a4613c"
257-
},
258-
"outputs": [],
259-
"source": [
260-
"try:\n",
261-
" client.inference.delete(inference_id=\"my-elastic-reranker\")\n",
262-
"except exceptions.NotFoundError:\n",
263-
" # Inference endpoint does not exist\n",
264-
" pass\n",
265-
"\n",
266-
"try:\n",
267-
" client.options(\n",
268-
" request_timeout=60, max_retries=3, retry_on_timeout=True\n",
269-
" ).inference.put(\n",
270-
" task_type=\"rerank\",\n",
271-
" inference_id=\"my-elastic-reranker\",\n",
272-
" inference_config={\n",
273-
" \"service\": \"elasticsearch\",\n",
274-
" \"service_settings\": {\n",
275-
" \"model_id\": \".rerank-v1\",\n",
276-
" \"num_threads\": 1,\n",
277-
" \"adaptive_allocations\": {\n",
278-
" \"enabled\": True,\n",
279-
" \"min_number_of_allocations\": 1,\n",
280-
" \"max_number_of_allocations\": 4,\n",
281-
" },\n",
282-
" },\n",
283-
" },\n",
284-
" )\n",
285-
" print(\"Inference endpoint created successfully\")\n",
286-
"except exceptions.BadRequestError as e:\n",
287-
" if e.error == \"resource_already_exists_exception\":\n",
288-
" print(\"Inference endpoint created successfully\")\n",
289-
" else:\n",
290-
" raise e"
291-
]
292-
},
293-
{
294-
"cell_type": "markdown",
295-
"metadata": {},
296-
"source": [
297-
"Run the following command to confirm your inference endpoint is deployed."
298-
]
299-
},
300-
{
301-
"cell_type": "code",
302-
"execution_count": null,
303-
"metadata": {},
304-
"outputs": [],
305-
"source": [
306-
"client.inference.get().body"
307-
]
308-
},
309-
{
310-
"cell_type": "markdown",
311-
"metadata": {},
312-
"source": [
313-
"\n",
314-
"⚠️ When you deploy your model, you might need to sync your ML saved objects in the Kibana (or Serverless) UI.\n",
315-
"Go to **Trained Models** and select **Synchronize saved objects**."
316-
]
317-
},
318234
{
319235
"cell_type": "markdown",
320236
"metadata": {
@@ -465,7 +381,7 @@
465381
"source": [
466382
"## Semantic reranker\n",
467383
"\n",
468-
"In the following `retriever` syntax, we wrap our standard `match` query retriever in a `text_similarity_reranker`. This allows us to leverage the NLP model we deployed to Elasticsearch to rerank the results based on the phrase \"flesh-eating bad guy\"."
384+
"In the following `retriever` syntax, we wrap our standard `match` query retriever in a `text_similarity_reranker`. This allows us to leverage the [Elastic rerank model](https://www.elastic.co/guide/en/machine-learning/current/ml-nlp-rerank.html) to rerank the results based on the phrase \"flesh-eating bad guy\"."
469385
]
470386
},
471387
{
@@ -523,7 +439,6 @@
523439
" }\n",
524440
" },\n",
525441
" \"field\": \"plot\",\n",
526-
" \"inference_id\": \"my-elastic-reranker\",\n",
527442
" \"inference_text\": \"flesh-eating bad guy\",\n",
528443
" }\n",
529444
" },\n",
@@ -543,7 +458,9 @@
543458
"source": [
544459
"Success! \"The Silence of the Lambs\" is our top result. Semantic reranking helped us find the most relevant result by parsing a natural language query, overcoming the limitations of lexical search that relies on keyword matching.\n",
545460
"\n",
546-
"Semantic reranking enables semantic search in a few steps, without the need for generating and storing embeddings. This a great tool for testing and building hybrid search systems in Elasticsearch."
461+
"Semantic reranking enables semantic search in a few steps, without the need for generating and storing embeddings. This a great tool for testing and building hybrid search systems in Elasticsearch.\n",
462+
"\n",
463+
"*Note* Starting with Elasticsearch version `8.18`, The `inference_id` field is optional. If not specified, it defaults to `.rerank-v1-elasticsearch`. If you are using an earlier version or prefer to manage your own endpoint, you can set up a custom `rerank` inference endpoint using the [create inference API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put)."
547464
]
548465
},
549466
{

0 commit comments

Comments
 (0)