# これはシンガポールリージョンの URL です。WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
curl --request POST \
--url https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/reranks \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "qwen3-rerank",
"documents": [
"Rerank models are widely used in search engines and recommendation systems. They sort candidate documents based on text relevance.",
"Quantum computing is a cutting-edge field of computer science.",
"The development of pre-trained language models has brought new advancements to rerank models."
],
"query": "What is a rerank model?",
"top_n": 2,
"instruct": "Given a web search query, retrieve relevant passages that answer the query."
}'
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/rerank/text-rerank/text-rerank' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "qwen3-vl-rerank",
"input":{
"query": {"text": "What is a rerank model?"},
"documents": [
{"text": "Rerank models are widely used in search engines and recommendation systems. They sort candidate documents based on text relevance."},
{"image": "https://img.alicdn.com/imgextra/i3/O1CN01rdstgY1uiZWt8gqSL_!!6000000006071-0-tps-1970-356.jpg"},
{"video": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250107/lbcemt/new+video.mp4"}
]
},
"parameters": {
"return_documents": true,
"top_n": 2,
"fps": 1.0
}
}'
イメージクエリ
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/rerank/text-rerank/text-rerank' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "qwen3-vl-rerank",
"input":{
"query": {"image": "https://img.alicdn.com/imgextra/i3/O1CN01rdstgY1uiZWt8gqSL_!!6000000006071-0-tps-1970-356.jpg"},
"documents": [
{"text": "Text rerank models are widely used in search engines and recommendation systems to sort candidate captions based on text relevance."},
{"image": "https://img.alicdn.com/imgextra/i3/O1CN01rdstgY1uiZWt8gqSL_!!6000000006071-0-tps-1970-356.jpg"},
{"video": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250107/lbcemt/new+video.mp4"}
]
},
"parameters": {
"return_documents": true,
"top_n": 2,
"fps": 1.0
}
}'
gte-rerank-v2
curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/rerank/text-rerank/text-rerank' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "gte-rerank-v2",
"input":{
"query": "What is a rerank model?",
"documents": [
"Rerank models are widely used in search engines and recommendation systems. They sort candidate documents based on text relevance.",
"Quantum computing is a cutting-edge field of computer science.",
"The development of pre-trained language models has brought new advancements to rerank models."
]
},
"parameters": {
"return_documents": true,
"top_n": 2
}
}'
{
"output": {
"results": [
{
"document": {
"text": "Rerank models are widely used in search engines and recommendation systems. They sort candidate documents based on text relevance."
},
"index": 0,
"relevance_score": 0.9334521178273196
},
{
"document": {
"text": "The development of pre-trained language models has brought new advancements to rerank models."
},
"index": 2,
"relevance_score": 0.34100082626411193
}
]
},
"usage": {
"total_tokens": 79
},
"request_id": "85ba5752-1900-47d2-8896-23f99b13f6e1"
}
import dashscope
# 中国 (北京) リージョン。{WorkspaceId} を実際のワークスペース ID に置き換えてください。構成はリージョンによって異なります。
dashscope.base_http_api_url = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1"
def text_rerank():
resp = dashscope.TextReRank.call(
model="gte-rerank-v2",
query="What is a rerank model?",
documents=[
"Rerank models are widely used in search engines and recommendation systems. They sort candidate documents based on text relevance.",
"Quantum computing is a cutting-edge field of computer science.",
"The development of pre-trained language models has brought new advancements to rerank models."
],
top_n=2,
return_documents=True
)
print(resp)
if __name__ == '__main__':
text_rerank()
{
"status_code": 200,
"request_id": "4b0805c0-6b36-490d-8bc1-4365f4c89905",
"code": "",
"message": "",
"output": {
"results": [
{
"index": 0,
"relevance_score": 0.9334521178273196,
"document": {
"text": "Rerank models are widely used in search engines and recommendation systems. They sort candidate documents based on text relevance."
}
},
{
"index": 2,
"relevance_score": 0.34100082626411193,
"document": {
"text": "The development of pre-trained language models has brought new advancements to rerank models."
}
}
]
},
"usage": {
"total_tokens": 79
}
}