-
Notifications
You must be signed in to change notification settings - Fork 228
[Search] Updating Notebook to address inference_id is not required #437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a8e3f22
Adding notes for inference_id is not required
Samiul-TheSoccerFan 0297029
Refactoring the wordings to include elastic rerank and redundancy
Samiul-TheSoccerFan 8b7edf0
Update rerrank link
Samiul-TheSoccerFan 831a1d7
Updating notebook to address version differences for rerank endpoint
Samiul-TheSoccerFan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,7 @@ | |
"\n", | ||
"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", | ||
"\n", | ||
"You will:\n", | ||
"\n", | ||
"- Create an inference endpoint to manage your `rerank` task. This will download and deploy the Elastic Rerank model.\n", | ||
"- Query your data using the `text_similarity_rerank` retriever, leveraging the Elastic Rerank model." | ||
"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." | ||
] | ||
}, | ||
{ | ||
|
@@ -234,87 +231,6 @@ | |
"time.sleep(3)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "DRIABkGAgV_Q" | ||
}, | ||
"source": [ | ||
"## Create inference endpoint\n", | ||
"\n", | ||
"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." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "DiKsd3YygV_Q", | ||
"outputId": "c3c46c6b-b502-4167-c98c-d2e2e0a4613c" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"try:\n", | ||
" client.inference.delete(inference_id=\"my-elastic-reranker\")\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=\"rerank\",\n", | ||
" inference_id=\"my-elastic-reranker\",\n", | ||
" inference_config={\n", | ||
" \"service\": \"elasticsearch\",\n", | ||
" \"service_settings\": {\n", | ||
" \"model_id\": \".rerank-v1\",\n", | ||
" \"num_threads\": 1,\n", | ||
" \"adaptive_allocations\": {\n", | ||
" \"enabled\": True,\n", | ||
" \"min_number_of_allocations\": 1,\n", | ||
" \"max_number_of_allocations\": 4,\n", | ||
" },\n", | ||
" },\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", | ||
"metadata": {}, | ||
"source": [ | ||
"Run the following command to confirm your inference endpoint is deployed." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"client.inference.get().body" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"\n", | ||
"⚠️ When you deploy your model, you might need to sync your ML saved objects in the Kibana (or Serverless) UI.\n", | ||
"Go to **Trained Models** and select **Synchronize saved objects**." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
|
@@ -465,7 +381,10 @@ | |
"source": [ | ||
"## Semantic reranker\n", | ||
"\n", | ||
"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\"." | ||
"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", | ||
Samiul-TheSoccerFan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"\n", | ||
"⚠️ When you deploy your model, you might need to sync your ML saved objects in the Kibana (or Serverless) UI.\n", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this step still necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I tested in both hosted and serverless and this step is not required for |
||
"Go to **Trained Models** and select **Synchronize saved objects**." | ||
] | ||
}, | ||
{ | ||
|
@@ -523,7 +442,6 @@ | |
" }\n", | ||
" },\n", | ||
" \"field\": \"plot\",\n", | ||
" \"inference_id\": \"my-elastic-reranker\",\n", | ||
" \"inference_text\": \"flesh-eating bad guy\",\n", | ||
" }\n", | ||
" },\n", | ||
|
@@ -543,7 +461,9 @@ | |
"source": [ | ||
"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", | ||
"\n", | ||
"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." | ||
"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", | ||
"\n", | ||
"*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, 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)." | ||
] | ||
}, | ||
{ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.