Skip to content

Commit 0297029

Browse files
Refactoring the wordings to include elastic rerank and redundancy
1 parent a8e3f22 commit 0297029

File tree

1 file changed

+6
-89
lines changed

1 file changed

+6
-89
lines changed

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

Lines changed: 6 additions & 89 deletions
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-
"- Use a preconfigured inference endpoint for `rerank` task, skipping the need to create one manually. Alternatively, you can create a new inference endpoint to 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, which leverages the Elastic Rerank model to boost the relevance of your search results."
1916
]
2017
},
2118
{
@@ -234,88 +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-
"*Note* You can use the preconfigured inference endpoint `.rerank-v1-elasticsearch`, which eliminates the need to create an inference endpoint manually. However, if you prefer to manage your own endpoint, follow the steps below.\n",
245-
"\n",
246-
"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. "
247-
]
248-
},
249-
{
250-
"cell_type": "code",
251-
"execution_count": null,
252-
"metadata": {
253-
"colab": {
254-
"base_uri": "https://localhost:8080/"
255-
},
256-
"id": "DiKsd3YygV_Q",
257-
"outputId": "c3c46c6b-b502-4167-c98c-d2e2e0a4613c"
258-
},
259-
"outputs": [],
260-
"source": [
261-
"try:\n",
262-
" client.inference.delete(inference_id=\"my-elastic-reranker\")\n",
263-
"except exceptions.NotFoundError:\n",
264-
" # Inference endpoint does not exist\n",
265-
" pass\n",
266-
"\n",
267-
"try:\n",
268-
" client.options(\n",
269-
" request_timeout=60, max_retries=3, retry_on_timeout=True\n",
270-
" ).inference.put(\n",
271-
" task_type=\"rerank\",\n",
272-
" inference_id=\"my-elastic-reranker\",\n",
273-
" inference_config={\n",
274-
" \"service\": \"elasticsearch\",\n",
275-
" \"service_settings\": {\n",
276-
" \"model_id\": \".rerank-v1\",\n",
277-
" \"num_threads\": 1,\n",
278-
" \"adaptive_allocations\": {\n",
279-
" \"enabled\": True,\n",
280-
" \"min_number_of_allocations\": 1,\n",
281-
" \"max_number_of_allocations\": 4,\n",
282-
" },\n",
283-
" },\n",
284-
" },\n",
285-
" )\n",
286-
" print(\"Inference endpoint created successfully\")\n",
287-
"except exceptions.BadRequestError as e:\n",
288-
" if e.error == \"resource_already_exists_exception\":\n",
289-
" print(\"Inference endpoint created successfully\")\n",
290-
" else:\n",
291-
" raise e"
292-
]
293-
},
294-
{
295-
"cell_type": "markdown",
296-
"metadata": {},
297-
"source": [
298-
"Run the following command to confirm your inference endpoint is deployed."
299-
]
300-
},
301-
{
302-
"cell_type": "code",
303-
"execution_count": null,
304-
"metadata": {},
305-
"outputs": [],
306-
"source": [
307-
"client.inference.get().body"
308-
]
309-
},
310-
{
311-
"cell_type": "markdown",
312-
"metadata": {},
313-
"source": [
314-
"\n",
315-
"⚠️ When you deploy your model, you might need to sync your ML saved objects in the Kibana (or Serverless) UI.\n",
316-
"Go to **Trained Models** and select **Synchronize saved objects**."
317-
]
318-
},
319234
{
320235
"cell_type": "markdown",
321236
"metadata": {
@@ -466,7 +381,10 @@
466381
"source": [
467382
"## Semantic reranker\n",
468383
"\n",
469-
"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) we deployed to Elasticsearch to rerank the results based on the phrase \"flesh-eating bad guy\".\n",
385+
"\n",
386+
"⚠️ When you deploy your model, you might need to sync your ML saved objects in the Kibana (or Serverless) UI.\n",
387+
"Go to **Trained Models** and select **Synchronize saved objects**."
470388
]
471389
},
472390
{
@@ -524,7 +442,6 @@
524442
" }\n",
525443
" },\n",
526444
" \"field\": \"plot\",\n",
527-
" \"inference_id\": \"my-elastic-reranker\",\n",
528445
" \"inference_text\": \"flesh-eating bad guy\",\n",
529446
" }\n",
530447
" },\n",
@@ -546,7 +463,7 @@
546463
"\n",
547464
"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",
548465
"\n",
549-
"*Note* The `inference_id` field is now optional. If not provided, it defaults to `.rerank-v1-elasticsearch`."
466+
"*Note* The `inference_id` field is optional and if not provided, it defaults to `.rerank-v1-elasticsearch`. However, If you prefer to manage your own endpoint, follow the instrictions provided in the [docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/infer-service-elasticsearch.html#inference-example-elastic-reranker)."
550467
]
551468
},
552469
{

0 commit comments

Comments
 (0)