Create an Embedding¶
Convert input content into vectors for retrieval or similarity calculations.
POST https://token.moi.matrixorigin.cn/v1/embeddings
Before you begin¶
Prepare a personal access token or service account API key for Genesis. See Access credentials for credential selection and permissions.
Use List callable models to select a model that supports Embeddings.
Request body¶
Replace $GENESIS_ACCESS_TOKEN and $MODEL_ID with your credential and the selected model ID.
curl -X POST \
"https://token.moi.matrixorigin.cn/v1/embeddings" \
-H "Authorization: Bearer $GENESIS_ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"model": "'"$MODEL_ID"'",
"input": [
"database",
"search"
],
"encoding_format": "float"
}'
The fields below cover text input. Images, videos, and multi-content vector output require corresponding model capabilities and input configuration.
Parameter |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
Selected model ID from |
|
string or array of string or array of object |
Yes |
Nonempty text input. Object fields are listed below. |
|
string or array of object |
Required for object input |
Text or text blocks for an object input. |
|
string |
Required for a text block |
Use |
|
string |
Required for a text block |
Nonempty text content. |
|
string |
No |
Vector encoding. The text example uses |
|
integer |
No |
Requested positive vector dimension; set only when supported by the selected model. |
Successful response¶
A successful request returns the vector for each input and token usage.
{
"object": "list",
"model": "MODEL_ID",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [
0.018,
-0.042,
0.337
]
},
{
"object": "embedding",
"index": 1,
"embedding": [
0.032,
0.011,
0.296
]
}
],
"usage": {
"prompt_tokens": 2,
"total_tokens": 2
}
}
Field |
Type |
Description |
|---|---|---|
|
string |
Object type |
|
string |
Model that processed the request. |
|
array of object |
Vectors for the input texts. |
|
string |
Result type |
|
integer |
Zero-based position in the input. |
|
array of number or string |
Vector values; |
|
object |
Token usage returned by the model. |
|
integer |
Input tokens. |
|
integer |
Total tokens. |
Error response¶
A missing model ID returns HTTP 400. Supply the model ID before sending the request again.
{
"error": {
"message": "missing required parameter: model",
"type": "invalid_request",
"code": "invalid_request"
}
}
Field |
Type |
Description |
|---|---|---|
|
object |
Error details. |
|
string |
Error description; the example indicates a missing model ID. |
|
string |
Error type; may be omitted by a model service. |
|
string or null |
Error code; may be omitted by a model service. |