Rerank documents¶
Rerank candidate documents against a query and return relevance scores and original positions.
POST https://token.moi.matrixorigin.cn/v1/rerank
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 Rerank.
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/rerank" \
-H "Authorization: Bearer $GENESIS_ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"model": "'"$MODEL_ID"'",
"query": "database",
"documents": [
"database transaction",
"weather forecast"
],
"top_n": 1,
"return_documents": true
}'
The fields below cover text queries and text candidates. Image or video reranking requires corresponding model capabilities and input configuration.
Parameter |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
Selected model ID from |
|
string or object |
Yes |
Nonempty query text used to assess relevance. Object fields are listed below. |
|
string or array of object |
Required for an object query |
Text or text blocks for an object input. |
|
string |
Required for a text block |
Use |
|
string |
Required for a text block |
Nonempty text content. |
|
array of string or array of object |
Yes |
Nonempty candidates; preserve their original order to identify returned results. |
|
string or array of object |
Required for an object document |
Text or text blocks for an object input. |
|
string |
Required for a text block |
Use |
|
string |
Required for a text block |
Nonempty text content. |
|
integer |
No |
Number of highest-ranked results to return; must be positive. |
|
boolean |
No |
Set to |
Successful response¶
A successful request returns candidate results ordered by relevance.
{
"id": "rerank-example",
"model": "MODEL_ID",
"results": [
{
"index": 0,
"relevance_score": 0.98,
"document": {
"text": "database transaction"
}
}
],
"usage": {
"prompt_tokens": 5,
"completion_tokens": 0,
"total_tokens": 5
}
}
Field |
Type |
Description |
|---|---|---|
|
string |
Rerank request identifier. |
|
string |
Model that processed the request. |
|
array of object |
Results ordered by relevance. |
|
integer |
Zero-based position in the original |
|
number |
Relevance score assigned by the model. |
|
string or object |
Included when candidate content is requested; text object fields are listed below. |
|
string |
Candidate text. |
|
object |
Token usage returned by the model. |
|
integer |
Input tokens. |
|
integer |
Generated tokens. |
|
integer |
Total input and generated 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. |