Skip to content

Commit b59f009

Browse files
committed
fix: grammar and simplifying tutorial
Signed-off-by: Brian Flores <[email protected]>
1 parent c6b85ce commit b59f009

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

_search-plugins/search-relevance/ml-inference-rerank-by-field.md

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ grand_parent: Search relevance
66
has_children: false
77
nav_order: 20
88
---
9-
# ML Inference Processor with By Field Rerank type
9+
# ML Inference processor with By Field rerank type
1010
Introduced 2.18
1111
{: .label .label-purple }
1212

13-
You can use the results of a remote model via the [ml_inference]({{site.url}}{{site.baseurl}}/_ingest-pipelines/processors/ml-inference.md) processor, with a [by_field]({{site.url}}{{site.baseurl}}/search-plugins/search-relevance/rerank-by-field/) rerank type to get better search results.
13+
You can use the results of a ml model using the [ml_inference]({{site.url}}{{site.baseurl}}/_ingest-pipelines/processors/ml-inference.md) processor, with a [by_field]({{site.url}}{{site.baseurl}}/search-plugins/search-relevance/rerank-by-field/) rerank type to get better search results.
1414
In order to do this you need to configure a search pipeline that runs at search time. The search pipeline will intercept search results
1515
pass them to the ml_inference processor which will apply a remote cross encoder model. Then once the results are returned it will apply the
1616
reranker to use that metric in order to rerank your documents.
1717

1818
In this tutorial we will showcase a scenario with documents related to New York City areas with emphasis on finding better search results based
19-
on the provided search query. We will use [Huggingface cross-encoder/ms-marco-MiniLM-L-6-v2](https://huggingface.co/cross-encoder/ms-marco-MiniLM-L-6-v2)
19+
on the provided search query. We will use [HuggingFace cross-encoder/ms-marco-MiniLM-L-6-v2](https://huggingface.co/cross-encoder/ms-marco-MiniLM-L-6-v2)
2020
hosted on Amazon SageMaker.
2121

2222
## Running a search with both processors
2323

2424
To run a search with reranking, follow these steps:
2525

26-
0. [Deploy the model on Amazon SageMaker](#0-deploy-the-model-on-amazon-sagemaker)
26+
0. [Deploy the model on Amazon SageMaker.](#0-deploy-the-model-on-amazon-sagemaker)
2727
1. [Create an index for ingestion](#step-1-create-an-index-for-ingestion).
2828
2. [Create a connector](#step-2-create-a-connector).
2929
3. [Create a model](#step-3-create-a-model).
3030
4. [Create the Search pipeline](#step-4-create-the-search-pipeline).
3131
5. [apply the pipeline on a search query](#step-5-apply-the-pipeline-on-a-search-query).
3232

33-
## 0. Deploy the model on Amazon Sagemaker
34-
Use the following code to deploy the model on Amazon Sagemaker.
35-
You can find all supported instance type and price on [Amazon Sagemaker Pricing document](https://aws.amazon.com/sagemaker/pricing/). Suggest to use GPU for better performance.
33+
## 0. Deploy the model on Amazon SageMaker
34+
Use the following code to deploy the model on Amazon SageMaker.
35+
You can find all supported instance type and price on [Amazon SageMaker Pricing document](https://aws.amazon.com/sagemaker/pricing/). Suggest to use GPU for better performance.
3636
```python
3737
import sagemaker
3838
import boto3
@@ -59,7 +59,7 @@ predictor = huggingface_model.deploy(
5959
```
6060
To find the endpoint make sure to the SageMaker homepage and navigate in the left tab **Inference > Endpoints** make note of the url specific to the model created it will be used when creating the connector.
6161

62-
## Step 1: Create an Index for Ingestion
62+
## Step 1: Create an index for ingestion
6363
Create an index called nyc_areas
6464
```json
6565
POST /nyc_areas/_bulk
@@ -80,13 +80,13 @@ POST /nyc_areas/_bulk
8080
{% include copy-curl.html %}
8181

8282
## Step 2: Create a connector
83-
Create a conector assuming you have created a sagemaker model with a cross encoder
83+
Create a connector assuming you have created a SageMaker model with a cross encoder
8484

8585
```json
8686
POST /_plugins/_ml/connectors/_create
8787
{
8888
"name": "SageMaker cross-encoder model",
89-
"description": "Test connector for Sagemaker cross-encoder model",
89+
"description": "Test connector for SageMaker cross-encoder hosted model",
9090
"version": 1,
9191
"protocol": "aws_sigv4",
9292
"credential": {
@@ -95,7 +95,7 @@ POST /_plugins/_ml/connectors/_create
9595
"session_token": "<Session token>"
9696
},
9797
"parameters": {
98-
"region": "us-east-1",
98+
"region": "<region>",
9999
"service_name": "sagemaker"
100100
},
101101
"actions": [
@@ -106,18 +106,7 @@ POST /_plugins/_ml/connectors/_create
106106
"headers": {
107107
"content-type": "application/json"
108108
},
109-
"request_body": "{ \"inputs\":${parameters.inputs}}" ,
110-
"pre_process_function":
111-
"""
112-
def json = params.json;
113-
def inputs = json.parameters.inputs;
114-
115-
def result = [:];
116-
result.query_text = inputs.text;
117-
result.text_docs = [inputs.text_pair];
118-
119-
return result;
120-
"""
109+
"request_body": "{ \"inputs\": { \"text\": \"${parameters.text}\", \"text_pair\": \"${parameters.text_pair}\" }}"
121110
}
122111
]
123112
}
@@ -129,10 +118,10 @@ POST /_plugins/_ml/connectors/_create
129118
```json
130119
POST /_plugins/_ml/models/_register
131120
{
132-
"name": "text classification model",
121+
"name": "Cross encoder model",
133122
"version": "1.0.1",
134123
"function_name": "remote",
135-
"description": "Text Classification",
124+
"description": "Using a SageMaker to apply a cross encoder model",
136125
"connector_id": "<connector_id_from_step_2>"
137126
}
138127

@@ -157,7 +146,6 @@ PUT /_search/pipeline/my_pipeline
157146
"tag": "ml_inference",
158147
"description": "This processor runs ml inference during search response",
159148
"model_id": "<model_id_from_step_3>",
160-
"model_input":"""{"parameters":{"inputs":{"text":"${input_map.text}","text_pair":"${input_map.text_pair}"}}}""",
161149
"function_name": "REMOTE",
162150
"input_map": [
163151
{

0 commit comments

Comments
 (0)