Skip to content

Commit 41dae61

Browse files
tune titan embedding model blueprint for v2 (#3094) (#3099)
Signed-off-by: Yaliang Wu <[email protected]> (cherry picked from commit 5682d11) Co-authored-by: Yaliang Wu <[email protected]>
1 parent 6c69f79 commit 41dae61

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

docs/remote_inference_blueprints/bedrock_connector_titan_embedding_blueprint.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ PUT /_cluster/settings
1616
```
1717

1818
## 2. Create connector for Amazon Bedrock:
19-
19+
### 2.1 Titan text embedding model v1
2020
If you are using self-managed Opensearch, you should supply AWS credentials:
2121

22-
If you are using Titan Text Embedding V2, change "model" to `amazon.titan-embed-text-v2:0`
2322
```json
2423
POST /_plugins/_ml/connectors/_create
2524
{
@@ -131,6 +130,55 @@ Sample response:
131130
"connector_id": "nzh9PIsBnGXNcxYpPEcv"
132131
}
133132
```
133+
### 2.2 Titan text embedding model v2
134+
135+
Follow Titan text embedding model v1, just change "model" to `amazon.titan-embed-text-v2:0` and configure extra parameters and request body as:
136+
137+
138+
```
139+
POST /_plugins/_ml/connectors/_create
140+
{
141+
"name": "Amazon Bedrock Connector: embedding",
142+
"description": "The connector to bedrock Titan embedding model",
143+
"version": 1,
144+
"protocol": "aws_sigv4",
145+
"parameters": {
146+
"region": "<PLEASE ADD YOUR AWS REGION HERE>",
147+
"service_name": "bedrock",
148+
"model": "amazon.titan-embed-text-v2:0",
149+
"dimensions": 1024,
150+
"normalize": true,
151+
"embeddingTypes": ["float"]
152+
},
153+
"credential": {
154+
"access_key": "<PLEASE ADD YOUR AWS ACCESS KEY HERE>",
155+
"secret_key": "<PLEASE ADD YOUR AWS SECRET KEY HERE>",
156+
"session_token": "<PLEASE ADD YOUR AWS SECURITY TOKEN HERE>"
157+
},
158+
"actions": [
159+
{
160+
"action_type": "predict",
161+
"method": "POST",
162+
"url": "https://bedrock-runtime.${parameters.region}.amazonaws.com/model/${parameters.model}/invoke",
163+
"headers": {
164+
"content-type": "application/json",
165+
"x-amz-content-sha256": "required"
166+
},
167+
"request_body": "{ \"inputText\": \"${parameters.inputText}\", \"dimensions\": ${parameters.dimensions}, \"normalize\": ${parameters.normalize}, \"embeddingTypes\": ${parameters.embeddingTypes} }",
168+
"pre_process_function": "connector.pre_process.bedrock.embedding",
169+
"post_process_function": "connector.post_process.bedrock.embedding"
170+
}
171+
]
172+
}
173+
```
174+
175+
Note:
176+
1. neural-search plugin only support one embedding for one document now. So you should configure one embedding type in `embeddingTypes`
177+
2. similar to v1, you should use `roleArn` in credential part on AWS OpenSearch Service
178+
3. `binary` type not supported yet in built-in post process function `connector.post_process.bedrock.embedding`. You can use this painless script
179+
```
180+
"post_process_function":"\n def name = \"sentence_embedding\";\n def dataType = \"FLOAT32\";\n if (params.embeddingsByType == null || params.embeddingsByType.length == 0) {\n return params.message;\n }\n def shape = [params.embeddingsByType.length];\n def json = \"{\" +\n \"\\\"name\\\":\\\"\" + name + \"\\\",\" +\n \"\\\"data_type\\\":\\\"\" + dataType + \"\\\",\" +\n \"\\\"shape\\\":\" + shape + \",\" +\n \"\\\"data\\\":\" + params.embeddingsByType +\n \"}\";\n return json;\n "
181+
```
134182

135183
## 3. Create model group:
136184

0 commit comments

Comments
 (0)