Skip to content

Commit 66bcde7

Browse files
junqiu-leimingshl
andauthored
Update blueprint doc for remote model batch semantic highlighting (opensearch-project#4309)
Signed-off-by: Junqiu Lei <[email protected]> Co-authored-by: Mingshi Liu <[email protected]>
1 parent f5510c9 commit 66bcde7

File tree

1 file changed

+74
-4
lines changed

1 file changed

+74
-4
lines changed

docs/remote_inference_blueprints/standard_blueprints/sagemaker_semantic_highlighter_standard_blueprint.md

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# AWS SageMaker Semantic Highlighter Model Standard Blueprint
22

3-
This blueprint demonstrates how to deploy a semantic highlighter model using AWS SageMaker and integrate it with OpenSearch. For a detailed Python-based tutorial on deploying the model to SageMaker, please refer to the [Deploying OpenSearch Sentence Highlighter Model To AWS SageMaker Guide](https://github.com/opensearch-project/opensearch-py-ml/blob/main/docs/source/examples/aws_sagemaker_sentence_highlighter_model/README.md).
3+
This blueprint demonstrates how to deploy a semantic highlighter model using AWS SageMaker and integrate it with OpenSearch. For a detailed Python-based tutorial on deploying the model to SageMaker, please refer to the [Deploying OpenSearch Sentence Highlighter Model To AWS SageMaker Guide](https://github.com/opensearch-project/opensearch-py-ml/blob/main/docs/source/examples/semantic_highlighting/README.md).
44

55
## Overview
66

@@ -11,6 +11,8 @@ The semantic highlighter model helps identify and highlight the most relevant pa
1111
3. Register and deploy the model
1212
4. Test the model inference
1313

14+
**Note:** Batch inference semantic highlighting support requires OpenSearch 3.3 or later. For OpenSearch 3.0-3.2, only single document inference is supported.
15+
1416
## Prerequisites
1517

1618
1. AWS account with SageMaker access
@@ -19,6 +21,8 @@ The semantic highlighter model helps identify and highlight the most relevant pa
1921

2022
## Steps
2123

24+
> **Note:** This connector supports both single document inference (OpenSearch 3.0+) and batch inference (OpenSearch 3.3+). The unified pre-process function automatically handles both formats for backward compatibility.
25+
2226
### 1. Create SageMaker Connector
2327

2428
```json
@@ -47,8 +51,8 @@ POST /_plugins/_ml/connectors/_create
4751
"content-type": "application/json"
4852
},
4953
"url": "https://runtime.sagemaker.${parameters.region}.amazonaws.com/endpoints/${parameters.model}/invocations",
50-
"request_body": "{ \"question\": \"${parameters.question}\", \"context\": \"${parameters.context}\" }",
51-
"pre_process_function": "// Extract question and context directly from params\nif (params.question != null && params.context != null) {\n return '{\"parameters\":{\"question\":\"' + params.question + '\",\"context\":\"' + params.context + '\"}}'; \n} \nelse {\n throw new IllegalArgumentException(\"Missing required parameters: question and context\");\n}"
54+
"request_body": "{ \"question\": \"${parameters.question:-}\", \"context\": \"${parameters.context:-}\", \"inputs\": ${parameters.inputs:-[]} }",
55+
"pre_process_function": "// Unified pre-process function for backward compatibility\nif (params.question != null && params.context != null && params.inputs == null) {\n // Single document format from older versions\n return '{\"parameters\":{\"question\":\"' + params.question + '\",\"context\":\"' + params.context + '\"}}';\n}\nelse if (params.inputs != null) {\n // Batch format from newer versions - pass inputs as JSON string\n String inputsJson = params.inputs.toString();\n return '{\"parameters\":{\"inputs\":' + inputsJson + '}}';\n}\nelse {\n throw new IllegalArgumentException(\"Invalid input format: must provide either (question and context) or (inputs)\");\n}"
5256
}
5357
]
5458
}
@@ -102,8 +106,36 @@ POST /_plugins/_ml/models/<MODEL_ID>/_predict
102106

103107
Replace `<MODEL_ID>` with your deployed model ID.
104108

109+
### 5. Test Batch Inference (OpenSearch 3.3+)
110+
111+
```json
112+
POST /_plugins/_ml/models/<MODEL_ID>/_predict
113+
{
114+
"parameters": {
115+
"inputs": [
116+
{
117+
"question": "What are the symptoms of heart failure?",
118+
"context": "Heart failure symptoms include shortness of breath, swelling in the feet and ankles, fatigue, and irregular pulse. Patients may also experience difficulty sleeping flat in bed."
119+
},
120+
{
121+
"question": "What causes high blood pressure?",
122+
"context": "High blood pressure can be caused by various factors including genetics, poor diet, lack of exercise, and stress. Sodium intake and obesity are major contributors."
123+
},
124+
{
125+
"question": "How is diabetes managed?",
126+
"context": "Diabetes management involves monitoring blood sugar levels, maintaining a healthy diet, regular exercise, and medication when necessary. Insulin therapy may be required for some patients."
127+
}
128+
]
129+
}
130+
}
131+
```
132+
133+
Replace `<MODEL_ID>` with your deployed model ID.
134+
105135
## Example Response
106136

137+
### Single Document Response
138+
107139
```json
108140
{
109141
"inference_results": [
@@ -126,8 +158,46 @@ Replace `<MODEL_ID>` with your deployed model ID.
126158
}
127159
```
128160

161+
### Batch Inference Response
162+
163+
```json
164+
{
165+
"inference_results": [
166+
{
167+
"output": [
168+
{
169+
"highlights": [
170+
{
171+
"start": 0,
172+
"end": 145
173+
}
174+
]
175+
},
176+
{
177+
"highlights": [
178+
{
179+
"start": 62,
180+
"end": 134
181+
}
182+
]
183+
},
184+
{
185+
"highlights": [
186+
{
187+
"start": 0,
188+
"end": 108
189+
}
190+
]
191+
}
192+
],
193+
"status_code": 200
194+
}
195+
]
196+
}
197+
```
198+
129199
## References
130-
- [Deploying OpenSearch Sentence Highlighter Model To AWS SageMaker Guide](https://github.com/opensearch-project/opensearch-py-ml/docs/source/examples/aws_sagemaker_sentence_highlighter_model/README.md)
200+
- [Deploying OpenSearch Sentence Highlighter Model To AWS SageMaker Guide](https://github.com/opensearch-project/opensearch-py-ml/docs/source/examples/semantic_highlighting/README.md)
131201
- [Using OpenSearch Semantic Highlighting Guide](https://docs.opensearch.org/docs/latest/tutorials/vector-search/semantic-highlighting-tutorial/)
132202
- [OpenSearch ML Commons Documentation](https://opensearch.org/docs/latest/ml-commons-plugin/remote-models/index/)
133203
- [SageMaker Endpoints Documentation](https://docs.aws.amazon.com/sagemaker/latest/dg/deploy-model.html)

0 commit comments

Comments
 (0)