You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/remote_inference_blueprints/standard_blueprints/sagemaker_semantic_highlighter_standard_blueprint.md
+74-4Lines changed: 74 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# AWS SageMaker Semantic Highlighter Model Standard Blueprint
2
2
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).
4
4
5
5
## Overview
6
6
@@ -11,6 +11,8 @@ The semantic highlighter model helps identify and highlight the most relevant pa
11
11
3. Register and deploy the model
12
12
4. Test the model inference
13
13
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
+
14
16
## Prerequisites
15
17
16
18
1. AWS account with SageMaker access
@@ -19,6 +21,8 @@ The semantic highlighter model helps identify and highlight the most relevant pa
19
21
20
22
## Steps
21
23
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
+
22
26
### 1. Create SageMaker Connector
23
27
24
28
```json
@@ -47,8 +51,8 @@ POST /_plugins/_ml/connectors/_create
"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\nreturn '{\"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 {\nthrow new IllegalArgumentException(\"Invalid input format: must provide either (question and context) or (inputs)\");\n}"
52
56
}
53
57
]
54
58
}
@@ -102,8 +106,36 @@ POST /_plugins/_ml/models/<MODEL_ID>/_predict
102
106
103
107
Replace `<MODEL_ID>` with your deployed model ID.
104
108
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
+
105
135
## Example Response
106
136
137
+
### Single Document Response
138
+
107
139
```json
108
140
{
109
141
"inference_results": [
@@ -126,8 +158,46 @@ Replace `<MODEL_ID>` with your deployed model ID.
126
158
}
127
159
```
128
160
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
+
129
199
## 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)
0 commit comments