|
| 1 | +--- |
| 2 | +title: AWS OpenSearch embedding |
| 3 | +description: Step-by-step guide to deploying a Cohere embedding model on AWS OpenSearch for use with Plane AI semantic search. |
| 4 | +keywords: aws opensearch, embedding model, cohere, plane ai, semantic search, ml commons, opensearch connector |
| 5 | +--- |
| 6 | + |
| 7 | +# Deploy an embedding model on AWS OpenSearch |
| 8 | + |
| 9 | +This guide walks you through deploying a Cohere embedding model on AWS OpenSearch (managed) for Plane AI semantic search. |
| 10 | + |
| 11 | +For other connector blueprints and embedding model configurations, see the [OpenSearch ML Commons remote inference blueprints](https://github.com/opensearch-project/ml-commons/tree/2.x/docs/remote_inference_blueprints). |
| 12 | + |
| 13 | +## Before you begin |
| 14 | + |
| 15 | +Make sure you have: |
| 16 | + |
| 17 | +- An AWS OpenSearch domain with **fine-grained access control** enabled. |
| 18 | +- Admin access to OpenSearch Dashboards. |
| 19 | +- AWS CLI configured locally. |
| 20 | +- An IAM user with permissions to create roles, policies, and access Secrets Manager. |
| 21 | +- A Cohere API key. |
| 22 | + |
| 23 | +## Create an IAM policy |
| 24 | + |
| 25 | +1. Go to **IAM → Policies → Create Policy**. |
| 26 | +2. Select **JSON** and paste the following: |
| 27 | + |
| 28 | + ```json |
| 29 | + { |
| 30 | + "Version": "2012-10-17", |
| 31 | + "Statement": [ |
| 32 | + { |
| 33 | + "Sid": "PassRoleAccess", |
| 34 | + "Effect": "Allow", |
| 35 | + "Action": "iam:PassRole", |
| 36 | + "Resource": "arn:aws:iam::<aws-account-number>:role/plane-opensearch-access-role" |
| 37 | + }, |
| 38 | + { |
| 39 | + "Sid": "SecretManagerAccess", |
| 40 | + "Effect": "Allow", |
| 41 | + "Action": [ |
| 42 | + "secretsmanager:GetSecretValue", |
| 43 | + "secretsmanager:DescribeSecret", |
| 44 | + "secretsmanager:ListSecrets" |
| 45 | + ], |
| 46 | + "Resource": "*" |
| 47 | + } |
| 48 | + ] |
| 49 | + } |
| 50 | + ``` |
| 51 | + |
| 52 | +3. Click **Next**, name the policy `plane-opensearch-access-policy`, and click **Create Policy**. |
| 53 | + |
| 54 | +## Create an IAM role |
| 55 | + |
| 56 | +Create an IAM role that OpenSearch can assume to access Secrets Manager. |
| 57 | + |
| 58 | +1. Go to **IAM → Roles → Create Role**. |
| 59 | +2. Name the role `plane-opensearch-access-role`. |
| 60 | +3. Set this **Trust Relationship**: |
| 61 | + |
| 62 | + ```json |
| 63 | + { |
| 64 | + "Version": "2012-10-17", |
| 65 | + "Statement": [ |
| 66 | + { |
| 67 | + "Effect": "Allow", |
| 68 | + "Principal": { |
| 69 | + "Service": "ec2.amazonaws.com" |
| 70 | + }, |
| 71 | + "Action": "sts:AssumeRole" |
| 72 | + }, |
| 73 | + { |
| 74 | + "Effect": "Allow", |
| 75 | + "Principal": { |
| 76 | + "AWS": "arn:aws:iam::<aws-account-number>:user/<opensearch-user>" |
| 77 | + }, |
| 78 | + "Action": "sts:AssumeRole" |
| 79 | + } |
| 80 | + ] |
| 81 | + } |
| 82 | + ``` |
| 83 | + |
| 84 | +4. Attach the `plane-opensearch-access-policy` you created in Step 1. |
| 85 | +5. Click **Create Role** and note the role ARN. |
| 86 | + |
| 87 | +## Grant ML permissions to the IAM role |
| 88 | + |
| 89 | +1. Open **OpenSearch Dashboards**. |
| 90 | +2. Go to **Security → Roles → `ml_full_access`**. |
| 91 | +3. Open the **Mapped users** tab and click **Map users**. |
| 92 | +4. Under **Backend roles**, add the role ARN: |
| 93 | + |
| 94 | + ``` |
| 95 | + arn:aws:iam::<aws-account-number>:role/plane-opensearch-access-role |
| 96 | + ``` |
| 97 | + |
| 98 | +## Assume the role locally |
| 99 | + |
| 100 | +Run this command to get temporary credentials: |
| 101 | + |
| 102 | +```bash |
| 103 | +aws sts assume-role \ |
| 104 | + --role-arn arn:aws:iam::<aws-account-number>:role/plane-opensearch-access-role \ |
| 105 | + --role-session-name session |
| 106 | +``` |
| 107 | + |
| 108 | +Export the credentials from the response: |
| 109 | + |
| 110 | +```bash |
| 111 | +export AWS_ACCESS_KEY_ID=<AccessKeyId> |
| 112 | +export AWS_SECRET_ACCESS_KEY=<SecretAccessKey> |
| 113 | +export AWS_SESSION_TOKEN=<SessionToken> |
| 114 | +``` |
| 115 | + |
| 116 | +## Store the Cohere API key in Secrets Manager |
| 117 | + |
| 118 | +1. Go to **Secrets Manager → Store a new secret**. |
| 119 | +2. Select **Other type of secret**. |
| 120 | +3. Set the key to `azure_ai_foundry_key_cohere` and the value to your Cohere API key. |
| 121 | +4. Click **Next**, name the secret `plane-ai/cohere`, and click **Store**. |
| 122 | +5. Note the **Secret ARN** — you'll need it in the next step. |
| 123 | + |
| 124 | +## Create a Cohere connector in OpenSearch |
| 125 | + |
| 126 | +Using the temporary credentials from Step 4, send a `POST` request to your OpenSearch cluster. |
| 127 | + |
| 128 | +**Endpoint:** `POST https://<opensearch-domain>/_plugins/_ml/connectors/_create` |
| 129 | + |
| 130 | +**Request body:** |
| 131 | + |
| 132 | +```json |
| 133 | +{ |
| 134 | + "name": "Cohere", |
| 135 | + "description": "Cohere embedding connector", |
| 136 | + "version": "1", |
| 137 | + "protocol": "http", |
| 138 | + "parameters": { |
| 139 | + "endpoint": "https://azureaitrials-resource.services.ai.azure.com/models", |
| 140 | + "model": "embed-v-4-0", |
| 141 | + "api_version": "2024-05-01-preview", |
| 142 | + "input_type": "search_document", |
| 143 | + "truncate": "END" |
| 144 | + }, |
| 145 | + "credential": { |
| 146 | + "secretArn": "<cohere-secret-arn>", |
| 147 | + "roleArn": "arn:aws:iam::<aws-account-number>:role/plane-opensearch-access-role" |
| 148 | + }, |
| 149 | + "actions": [ |
| 150 | + { |
| 151 | + "action_type": "predict", |
| 152 | + "method": "POST", |
| 153 | + "url": "${parameters.endpoint}/embeddings?api-version=${parameters.api_version}", |
| 154 | + "headers": { |
| 155 | + "api-key": "${credential.secretArn.azure_ai_foundry_key_cohere}", |
| 156 | + "x-ms-model-mesh-model-name": "embed-v-4-0" |
| 157 | + }, |
| 158 | + "request_body": "{ \"texts\": ${parameters.texts}, \"truncate\": \"${parameters.truncate}\", \"model\": \"${parameters.model}\", \"input_type\": \"${parameters.input_type}\" }", |
| 159 | + "pre_process_function": "connector.pre_process.cohere.embedding", |
| 160 | + "post_process_function": "connector.post_process.cohere.embedding" |
| 161 | + } |
| 162 | + ] |
| 163 | +} |
| 164 | +``` |
| 165 | + |
| 166 | +Save the `connector_id` from the response. |
| 167 | + |
| 168 | +## Configure the OpenSearch cluster |
| 169 | + |
| 170 | +Run these commands in **Dev Tools** in OpenSearch Dashboards. |
| 171 | + |
| 172 | +### Allow the connector's external endpoints |
| 173 | + |
| 174 | +```json |
| 175 | +PUT /_cluster/settings |
| 176 | +{ |
| 177 | + "persistent": { |
| 178 | + "plugins.ml_commons.trusted_connector_endpoints_regex": [ |
| 179 | + "^https://api\\.cohere\\.ai(/.*)?$", |
| 180 | + "^https://azureaitrials-resource\\.services\\.ai\\.azure\\.com(/.*)?$" |
| 181 | + ] |
| 182 | + } |
| 183 | +} |
| 184 | +``` |
| 185 | + |
| 186 | +### Register the embedding model |
| 187 | + |
| 188 | +```json |
| 189 | +POST /_plugins/_ml/models/_register |
| 190 | +{ |
| 191 | + "name": "cohere_4_0_embed", |
| 192 | + "function_name": "remote", |
| 193 | + "connector_id": "<connector-id>", |
| 194 | + "description": "Cohere Embedding Model" |
| 195 | +} |
| 196 | +``` |
| 197 | + |
| 198 | +Save the `model_id` from the response. |
| 199 | + |
| 200 | +### Deploy the model |
| 201 | + |
| 202 | +``` |
| 203 | +POST /_plugins/_ml/models/<model_id>/_deploy |
| 204 | +``` |
| 205 | + |
| 206 | +### Verify deployment status |
| 207 | + |
| 208 | +``` |
| 209 | +GET /_plugins/_ml/models/<model_id> |
| 210 | +``` |
| 211 | + |
| 212 | +Wait until the response shows: |
| 213 | + |
| 214 | +```json |
| 215 | +"model_state": "DEPLOYED" |
| 216 | +``` |
| 217 | + |
| 218 | +### Test inference (optional) |
| 219 | + |
| 220 | +```json |
| 221 | +POST /_plugins/_ml/models/<model_id>/_predict |
| 222 | +{ |
| 223 | + "parameters": { |
| 224 | + "inputs": ["hello world"] |
| 225 | + } |
| 226 | +} |
| 227 | +``` |
| 228 | + |
| 229 | +## Configure Plane |
| 230 | + |
| 231 | +Add the deployed model ID to `/opt/plane/plane.env`: |
| 232 | + |
| 233 | +```bash |
| 234 | +EMBEDDING_MODEL_ID=<model_id> |
| 235 | +``` |
| 236 | + |
| 237 | +Restart Plane and complete the remaining steps in [Enable Plane AI](/self-hosting/govern/plane-ai#configure-an-embedding-model). |
0 commit comments