forked from opensearch-project/ml-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cohere version 3 embedding model (opensearch-project#1721)
Signed-off-by: Xun Zhang <[email protected]>
- Loading branch information
1 parent
f46d258
commit b131f1e
Showing
2 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...s/cohere_connector_embedding_blueprint.md → ...ohere_v2_connector_embedding_blueprint.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
docs/remote_inference_blueprints/cohere_v3_connector_embedding_blueprint.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
### Cohere connector blueprint version 3.0 example for embedding: | ||
|
||
#### this blueprint is created from Cohere doc: https://docs.cohere.com/reference/embed | ||
|
||
```json | ||
POST /_plugins/_ml/connectors/_create | ||
{ | ||
"name": "cohere-embed-v3", | ||
"description": "The connector to public Cohere model service for embed", | ||
"version": "1", | ||
"protocol": "http", | ||
"credential": { | ||
"cohere_key": "<Your_API_Key>" | ||
}, | ||
"parameters": { | ||
"model": "embed-english-v3.0", | ||
"input_type":"search_document", | ||
"truncate": "END" | ||
}, | ||
"actions": [ | ||
{ | ||
"action_type": "predict", | ||
"method": "POST", | ||
"url": "https://api.cohere.ai/v1/embed", | ||
"headers": { | ||
"Authorization": "Bearer ${credential.cohere_key}" | ||
}, | ||
"request_body": "{ \"texts\": ${parameters.texts}, \"truncate\": \"${parameters.truncate}\", \"model\": \"${parameters.model}\", \"input_type\": \"${parameters.input_type}\" }", | ||
"pre_process_function": "connector.pre_process.cohere.embedding", | ||
"post_process_function": "connector.post_process.cohere.embedding" | ||
} | ||
] | ||
} | ||
``` | ||
#### Sample response | ||
```json | ||
{ | ||
"connector_id": "5tkeI4wBOQCMt0W51p18" | ||
} | ||
``` | ||
|
||
### Register and deploy an ML model before predicting: | ||
```json | ||
POST /_plugins/_ml/models/_register | ||
{ | ||
"name": "cohere embedding model v3", | ||
"function_name": "remote", | ||
"version": "1.0.0", | ||
"description": "test embedding model", | ||
"connector_id": "5tkeI4wBOQCMt0W51p18" | ||
} | ||
``` | ||
|
||
```json | ||
POST /_plugins/_ml/models/7dkfI4wBOQCMt0W5Sp3F/_deploy | ||
``` | ||
### Corresponding Predict request example: | ||
|
||
```json | ||
POST /_plugins/_ml/models/<ENTER ML MODEL ID HERE>/_predict | ||
{ | ||
"parameters": { | ||
"texts": ["Say this is a test"] | ||
} | ||
} | ||
``` | ||
|
||
#### Sample response | ||
```json | ||
{ | ||
"inference_results": [ | ||
{ | ||
"output": [ | ||
{ | ||
"name": "sentence_embedding", | ||
"data_type": "FLOAT32", | ||
"shape": [ | ||
1024 | ||
], | ||
"data": [ | ||
-0.0024547577, | ||
0.0062217712, | ||
-0.01675415, | ||
-0.020736694, | ||
-0.020263672, | ||
... ... | ||
0.038635254 | ||
] | ||
} | ||
], | ||
"status_code": 200 | ||
} | ||
] | ||
} | ||
``` |