重排序模型
Rerank 用于文本重排序,通过接收用户的查询文本及候选文本列表,使用模型计算候选文本与查询文本的相关性得分并返回分数。适用于智能问答、信息检索等场景。
1.模型系列
智谱Rerank
Rerank系列 | 上下文长度 | 并发数 | Tokens计费 |
---|---|---|---|
GLM-Rerank | 4k | 300 | 输入:¥0.8/M Tokens 输出:¥0.8/M Tokens |
2.使用前提
您已创建大模型平台API_Key,用于模型调用。
- 若您还未申请,请前往 AI 智算云平台-大模型平台-模型广场
3.API接入方式
向量模型支持两种接入方式:本地客户端接入、代码接入。
3.1 本地客户端接入
支持 RAGFlow 接入
文档参考:【API接入-对话助手-RAGFlow】
3.2 代码接入
支持 curl、python、golang、java、nodejs
Rerank模型接口:https://$BASE_URL/v1/p002/rerank
BASE_URL:llmapi.blsc.cn
curl --location 'https://$BASE_URL/v1/p002/rerank' \
--header 'Authorization: Bearer 申请到的key' \
--header 'Content-Type: application/json' \
--data '{
"model": "GLM-Rerank",
"query": "What is the capital of the United States?",
"documents": [
"Carson City is the capital city of the American state of Nevada.",
"The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
"Washington, D.C. is the capital of the United States.",
"Capital punishment has existed in the United States since before it was a country."
],
"top_n": 3
}
import requests
BASE_URL = "your_base_url" # 替换为实际的BASE_URL
api_key = "申请到的key" # 替换为实际的API key
url = f"https://{BASE_URL}/v1/p002/rerank"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
data = {
"model": "GLM-Rerank",
"query": "What is the capital of the United States?",
"documents": [
"Carson City is the capital city of the American state of Nevada.",
"The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
"Washington, D.C. is the capital of the United States.",
"Capital punishment has existed in the United States since before it was a country."
],
"top_n": 3
}
response = requests.post(url, headers=headers, json=data)
# 打印响应
print(response.status_code)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
baseURL := "your_base_url" // 替换为实际的BASE_URL
apiKey := "申请到的key" // 替换为实际的API key
url := fmt.Sprintf("https://%s/v1/p002/rerank", baseURL)
// 准备请求数据
requestData := map[string]interface{}{
"model": "GLM-Rerank",
"query": "What is the capital of the United States?",
"documents": []string{
"Carson City is the capital city of the American state of Nevada.",
"The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
"Washington, D.C. is the capital of the United States.",
"Capital punishment has existed in the United States since before it was a country.",
},
"top_n": 3,
}
// 将请求数据编码为JSON
jsonData, err := json.Marshal(requestData)
if err != nil {
fmt.Println("Error encoding JSON:", err)
return
}
// 创建HTTP请求
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
if err != nil {
fmt.Println("Error creating request:", err)
return
}
// 设置请求头
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey))
req.Header.Set("Content-Type", "application/json")
// 发送请求
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error sending request:", err)
return
}
defer resp.Body.Close()
// 读取响应体
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return
}
// 打印响应
fmt.Println("Status Code:", resp.Status)
fmt.Println("Response Body:", string(body))
}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpRequest.BodyPublishers;
public class Main {
public static void main(String[] args) {
String baseUrl = "your_base_url"; // 替换为实际的BASE_URL
String apiKey = "申请到的key"; // 替换为实际的API key
String url = "https://" + baseUrl + "/v1/p002/rerank";
String requestBody = "{" +
"\"model\": \"GLM-Rerank\"," +
"\"query\": \"What is the capital of the United States?\"," +
"\"documents\": [" +
"\"Carson City is the capital city of the American state of Nevada.\"," +
"\"The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.\"," +
"\"Washington, D.C. is the capital of the United States.\"," +
"\"Capital punishment has existed in the United States since before it was a country.\"" +
"]," +
"\"top_n\": 3" +
"}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString(requestBody))
.build();
try {
HttpResponse<String> response = client.send(
request, HttpResponse.BodyHandlers.ofString());
System.out.println("Status Code: " + response.statusCode());
System.out.println("Response: " + response.body());
} catch (Exception e) {
e.printStackTrace();
}
}
}
const axios = require('axios');
const BASE_URL = 'your_base_url'; // 替换为实际的BASE_URL
const API_KEY = '申请到的key'; // 替换为实际的API key
axios.post(`https://${BASE_URL}/v1/p002/rerank`, {
model: "GLM-Rerank",
query: "What is the capital of the United States?",
documents: [
"Carson City is the capital city of the American state of Nevada.",
"The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
"Washington, D.C. is the capital of the United States.",
"Capital punishment has existed in the United States since before it was a country."
],
top_n: 3
}, {
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
}
})
.then(response => {
console.log('状态码:', response.status);
console.log('响应数据:', response.data);
})
.catch(error => {
console.error('请求出错:', error.response ? error.response.data : error.message);
});