diff --git a/docs/remote_inference_blueprints/bedrock_connector_cohere_cohere.embed-v4.md b/docs/remote_inference_blueprints/bedrock_connector_cohere_cohere.embed-v4.md new file mode 100644 index 0000000000..2029925b35 --- /dev/null +++ b/docs/remote_inference_blueprints/bedrock_connector_cohere_cohere.embed-v4.md @@ -0,0 +1,340 @@ +# Connector blueprint examples for semantic search using Cohere Embed v4 model on Amazon Bedrock + +## 1. Add connector endpoint to trusted URLs: + +Note: no need to do this after 2.11.0 + +```json +PUT /_cluster/settings +{ + "persistent": { + "plugins.ml_commons.trusted_connector_endpoints_regex": [ + "^https://bedrock-runtime\\..*[a-z0-9-]\\.amazonaws\\.com/.*$" + ] + } +} +``` + +## 2. Create connector for Amazon Bedrock: + +If you are using self-managed Opensearch, you should supply AWS credentials: + +```json +POST /_plugins/_ml/connectors/_create +{ + "name": "Amazon Bedrock Connector: Cohere Embed v4", + "description": "Test connector for Amazon Bedrock Cohere Embed v4", + "version": 1, + "protocol": "aws_sigv4", + "credential": { + "access_key": "", + "secret_key": "", + "session_token": "" + }, + "parameters": { + "region": "", + "service_name": "bedrock", + "truncate": "", + "input_type": "", + "model": "cohere.embed-v4:0", + "embedding_types": [<"float"|"int8"|"binary">], + "output_dimension": <256 | 512 | 1024 | 1536> + }, + "actions": [ + { + "action_type": "predict", + "method": "POST", + "headers": { + "x-amz-content-sha256": "required", + "content-type": "application/json" + }, + "url": "https://bedrock-runtime.${parameters.region}.amazonaws.com/model/${parameters.model}/invoke", + "request_body": """ + { + "texts": ${parameters.texts}, + "truncate": "${parameters.truncate}", + "input_type": "${parameters.input_type}", + "embedding_types": ${parameters.embedding_types}, + "output_dimension": ${parameters.output_dimension} + } + """, + "pre_process_function": "connector.pre_process.cohere.embedding", + "post_process_function": """ + def name = "sentence_embedding"; + def data_type = "FLOAT32"; + def result; + if (params.embeddings.int8 != null) { + data_type = "INT8"; + result = params.embeddings.int8; + } + else if (params.embeddings.uint8 != null) { + data_type = "UINT8"; + result = params.embeddings.uint8; + } + if (params.embeddings.binary != null) { + data_type = "BINARY"; + result = params.embeddings.binary; + } + else if (params.embeddings.ubinary != null) { + data_type = "UBINARY"; + result = params.embeddings.ubinary; + } + else if (params.embeddings.float != null) { + data_type = "FLOAT32"; + result = params.embeddings.float; + } + if (result == null) { + return "Invalid embedding result"; + } + def embedding_list = new StringBuilder("["); + for (int m=0; m" + }, + "parameters": { + "region": "", + "service_name": "bedrock", + "truncate": "", + "input_type": "", + "model": "cohere.embed-v4:0", + "embedding_types": [<"float"|"int8"|"binary">], + "output_dimension": <256 | 512 | 1024 | 1536> + }, + "actions": [ + { + "action_type": "predict", + "method": "POST", + "headers": { + "x-amz-content-sha256": "required", + "content-type": "application/json" + }, + "url": "https://bedrock-runtime.${parameters.region}.amazonaws.com/model/${parameters.model}/invoke", + "request_body": """ + { + "texts": ${parameters.texts}, + "truncate": "${parameters.truncate}", + "input_type": "${parameters.input_type}", + "embedding_types": ${parameters.embedding_types}, + "output_dimension": ${parameters.output_dimension} + } + """, + "pre_process_function": "connector.pre_process.cohere.embedding", + "post_process_function": """ + def name = "sentence_embedding"; + def data_type = "FLOAT32"; + def result; + if (params.embeddings.int8 != null) { + data_type = "INT8"; + result = params.embeddings.int8; + } + else if (params.embeddings.uint8 != null) { + data_type = "UINT8"; + result = params.embeddings.uint8; + } + if (params.embeddings.binary != null) { + data_type = "BINARY"; + result = params.embeddings.binary; + } + else if (params.embeddings.ubinary != null) { + data_type = "UBINARY"; + result = params.embeddings.ubinary; + } + else if (params.embeddings.float != null) { + data_type = "FLOAT32"; + result = params.embeddings.float; + } + if (result == null) { + return "Invalid embedding result"; + } + def embedding_list = new StringBuilder("["); + for (int m=0; m