@@ -17,8 +17,11 @@ PUT /_cluster/settings
1717
1818## 2. Create connector for Amazon Bedrock:
1919
20- If you are using self-managed Opensearch, you should supply AWS credentials:
20+ If you are using self-managed Opensearch, you should supply AWS credentials.
21+ You have two different approaches to specify the pre&post process function and request body in the API:
2122
23+ ** Use build-in function**
24+ > You can use this starting from OpenSearch 2.16
2225``` json
2326POST /_plugins/_ml/connectors/_create
2427{
@@ -46,6 +49,21 @@ POST /_plugins/_ml/connectors/_create
4649 "content-type" : " application/json" ,
4750 "x-amz-content-sha256" : " required"
4851 },
52+ "request_body" : " {\" inputText\" : \" ${parameters.inputText:-null}\" , \" inputImage\" : \" ${parameters.inputImage:-null}\" }" ,
53+ "pre_process_function" : " connector.pre_process.bedrock.multimodal_embedding" ,
54+ "post_process_function" : " connector.post_process.bedrock.embedding"
55+ }
56+ ]
57+ }
58+ ```
59+ ** Use painless script**
60+ ``` json
61+ POST /_plugins/_ml/connectors/_create
62+ {
63+ ... //same above
64+ "actions" : [
65+ {
66+ ... // same above
4967 "request_body" : " { \" inputText\" : \" ${parameters.inputText:-null}\" , \" inputImage\" : \" ${parameters.inputImage:-null}\" }" ,
5068 "pre_process_function" : " \n StringBuilder parametersBuilder = new StringBuilder(\" {\" );\n if (params.text_docs.length > 0 && params.text_docs[0] != null) {\n parametersBuilder.append(\"\\\" inputText\\\" :\" );\n parametersBuilder.append(\"\\\"\" );\n parametersBuilder.append(params.text_docs[0]);\n parametersBuilder.append(\"\\\"\" );\n \n if (params.text_docs.length > 1 && params.text_docs[1] != null) {\n parametersBuilder.append(\" ,\" );\n }\n }\n \n \n if (params.text_docs.length > 1 && params.text_docs[1] != null) {\n parametersBuilder.append(\"\\\" inputImage\\\" :\" );\n parametersBuilder.append(\"\\\"\" );\n parametersBuilder.append(params.text_docs[1]);\n parametersBuilder.append(\"\\\"\" );\n }\n parametersBuilder.append(\" }\" );\n \n return \" {\" +\"\\\" parameters\\\" :\" + parametersBuilder + \" }\" ;" ,
5169 "post_process_function" : " \n def name = \" sentence_embedding\" ;\n def dataType = \" FLOAT32\" ;\n if (params.embedding == null || params.embedding.length == 0) {\n return null;\n }\n def shape = [params.embedding.length];\n def json = \" {\" +\n \"\\\" name\\\" :\\\"\" + name + \"\\\" ,\" +\n \"\\\" data_type\\\" :\\\"\" + dataType + \"\\\" ,\" +\n \"\\\" shape\\\" :\" + shape + \" ,\" +\n \"\\\" data\\\" :\" + params.embedding +\n \" }\" ;\n return json;\n "
@@ -55,8 +73,11 @@ POST /_plugins/_ml/connectors/_create
5573```
5674
5775If using the AWS Opensearch Service, you can provide an IAM role arn that allows access to the bedrock service.
58- Refer to this [ AWS doc] ( https://docs.aws.amazon.com/opensearch-service/latest/developerguide/ml-amazon-connector.html )
76+ Refer to this [ AWS doc] ( https://docs.aws.amazon.com/opensearch-service/latest/developerguide/ml-amazon-connector.html )
77+ You have two different approaches to specify the pre&post process function and request body in the API:
5978
79+ ** Use build-in function**
80+ > You can use this starting from OpenSearch 2.16
6081``` json
6182POST /_plugins/_ml/connectors/_create
6283{
@@ -82,6 +103,21 @@ POST /_plugins/_ml/connectors/_create
82103 "content-type" : " application/json" ,
83104 "x-amz-content-sha256" : " required"
84105 },
106+ "request_body" : " {\" inputText\" : \" ${parameters.inputText:-null}\" , \" inputImage\" : \" ${parameters.inputImage:-null}\" }" ,
107+ "pre_process_function" : " connector.pre_process.bedrock.multimodal_embedding" ,
108+ "post_process_function" : " connector.post_process.bedrock.embedding"
109+ }
110+ ]
111+ }
112+ ```
113+ ** Use painless script**
114+ ``` json
115+ POST /_plugins/_ml/connectors/_create
116+ {
117+ ... //same above
118+ "actions" : [
119+ {
120+ ... //same above
85121 "request_body" : " { \" inputText\" : \" ${parameters.inputText:-null}\" , \" inputImage\" : \" ${parameters.inputImage:-null}\" }" ,
86122 "pre_process_function" : " \n StringBuilder parametersBuilder = new StringBuilder(\" {\" );\n if (params.text_docs.length > 0 && params.text_docs[0] != null) {\n parametersBuilder.append(\"\\\" inputText\\\" :\" );\n parametersBuilder.append(\"\\\"\" );\n parametersBuilder.append(params.text_docs[0]);\n parametersBuilder.append(\"\\\"\" );\n \n if (params.text_docs.length > 1 && params.text_docs[1] != null) {\n parametersBuilder.append(\" ,\" );\n }\n }\n \n \n if (params.text_docs.length > 1 && params.text_docs[1] != null) {\n parametersBuilder.append(\"\\\" inputImage\\\" :\" );\n parametersBuilder.append(\"\\\"\" );\n parametersBuilder.append(params.text_docs[1]);\n parametersBuilder.append(\"\\\"\" );\n }\n parametersBuilder.append(\" }\" );\n \n return \" {\" +\"\\\" parameters\\\" :\" + parametersBuilder + \" }\" ;" ,
87123 "post_process_function" : " \n def name = \" sentence_embedding\" ;\n def dataType = \" FLOAT32\" ;\n if (params.embedding == null || params.embedding.length == 0) {\n return null;\n }\n def shape = [params.embedding.length];\n def json = \" {\" +\n \"\\\" name\\\" :\\\"\" + name + \"\\\" ,\" +\n \"\\\" data_type\\\" :\\\"\" + dataType + \"\\\" ,\" +\n \"\\\" shape\\\" :\" + shape + \" ,\" +\n \"\\\" data\\\" :\" + params.embedding +\n \" }\" ;\n return json;\n "
0 commit comments