知识库检索
curl --request POST \
--url https://open.bigmodel.cn/api/llm-application/open/knowledge/retrieve \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"query": "<string>",
"knowledge_ids": [
"<string>"
],
"request_id": "<string>",
"document_ids": [
"<string>"
],
"top_k": 123,
"top_n": 123,
"recall_method": "mixed",
"recall_ratio": 80,
"fractional_threshold": 123
}
'import requests
url = "https://open.bigmodel.cn/api/llm-application/open/knowledge/retrieve"
payload = {
"query": "<string>",
"knowledge_ids": ["<string>"],
"request_id": "<string>",
"document_ids": ["<string>"],
"top_k": 123,
"top_n": 123,
"recall_method": "mixed",
"recall_ratio": 80,
"fractional_threshold": 123
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
query: '<string>',
knowledge_ids: ['<string>'],
request_id: '<string>',
document_ids: ['<string>'],
top_k: 123,
top_n: 123,
recall_method: 'mixed',
recall_ratio: 80,
fractional_threshold: 123
})
};
fetch('https://open.bigmodel.cn/api/llm-application/open/knowledge/retrieve', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://open.bigmodel.cn/api/llm-application/open/knowledge/retrieve")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"<string>\",\n \"knowledge_ids\": [\n \"<string>\"\n ],\n \"request_id\": \"<string>\",\n \"document_ids\": [\n \"<string>\"\n ],\n \"top_k\": 123,\n \"top_n\": 123,\n \"recall_method\": \"mixed\",\n \"recall_ratio\": 80,\n \"fractional_threshold\": 123\n}")
.asString();package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://open.bigmodel.cn/api/llm-application/open/knowledge/retrieve"
payload := strings.NewReader("{\n \"query\": \"<string>\",\n \"knowledge_ids\": [\n \"<string>\"\n ],\n \"request_id\": \"<string>\",\n \"document_ids\": [\n \"<string>\"\n ],\n \"top_k\": 123,\n \"top_n\": 123,\n \"recall_method\": \"mixed\",\n \"recall_ratio\": 80,\n \"fractional_threshold\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://open.bigmodel.cn/api/llm-application/open/knowledge/retrieve",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'query' => '<string>',
'knowledge_ids' => [
'<string>'
],
'request_id' => '<string>',
'document_ids' => [
'<string>'
],
'top_k' => 123,
'top_n' => 123,
'recall_method' => 'mixed',
'recall_ratio' => 80,
'fractional_threshold' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}{
"data": [
{
"text": "<string>",
"score": 123,
"metadata": {
"_id": "<string>",
"knowledge_id": "<string>",
"doc_id": "<string>",
"doc_name": "<string>",
"doc_url": "<string>",
"contextual_text": "<string>"
}
}
],
"code": 123,
"message": "<string>",
"timestamp": 123
}{
"code": 123,
"message": "<string>"
}知识库 API
知识库检索
用于检索个人知识库,支持向量检索、关键词检索、混合检索,支持自定义重排模型。点击 Try it 按钮可快速试用。
POST
/
llm-application
/
open
/
knowledge
/
retrieve
知识库检索
curl --request POST \
--url https://open.bigmodel.cn/api/llm-application/open/knowledge/retrieve \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"query": "<string>",
"knowledge_ids": [
"<string>"
],
"request_id": "<string>",
"document_ids": [
"<string>"
],
"top_k": 123,
"top_n": 123,
"recall_method": "mixed",
"recall_ratio": 80,
"fractional_threshold": 123
}
'import requests
url = "https://open.bigmodel.cn/api/llm-application/open/knowledge/retrieve"
payload = {
"query": "<string>",
"knowledge_ids": ["<string>"],
"request_id": "<string>",
"document_ids": ["<string>"],
"top_k": 123,
"top_n": 123,
"recall_method": "mixed",
"recall_ratio": 80,
"fractional_threshold": 123
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
query: '<string>',
knowledge_ids: ['<string>'],
request_id: '<string>',
document_ids: ['<string>'],
top_k: 123,
top_n: 123,
recall_method: 'mixed',
recall_ratio: 80,
fractional_threshold: 123
})
};
fetch('https://open.bigmodel.cn/api/llm-application/open/knowledge/retrieve', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://open.bigmodel.cn/api/llm-application/open/knowledge/retrieve")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"<string>\",\n \"knowledge_ids\": [\n \"<string>\"\n ],\n \"request_id\": \"<string>\",\n \"document_ids\": [\n \"<string>\"\n ],\n \"top_k\": 123,\n \"top_n\": 123,\n \"recall_method\": \"mixed\",\n \"recall_ratio\": 80,\n \"fractional_threshold\": 123\n}")
.asString();package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://open.bigmodel.cn/api/llm-application/open/knowledge/retrieve"
payload := strings.NewReader("{\n \"query\": \"<string>\",\n \"knowledge_ids\": [\n \"<string>\"\n ],\n \"request_id\": \"<string>\",\n \"document_ids\": [\n \"<string>\"\n ],\n \"top_k\": 123,\n \"top_n\": 123,\n \"recall_method\": \"mixed\",\n \"recall_ratio\": 80,\n \"fractional_threshold\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://open.bigmodel.cn/api/llm-application/open/knowledge/retrieve",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'query' => '<string>',
'knowledge_ids' => [
'<string>'
],
'request_id' => '<string>',
'document_ids' => [
'<string>'
],
'top_k' => 123,
'top_n' => 123,
'recall_method' => 'mixed',
'recall_ratio' => 80,
'fractional_threshold' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}{
"data": [
{
"text": "<string>",
"score": 123,
"metadata": {
"_id": "<string>",
"knowledge_id": "<string>",
"doc_id": "<string>",
"doc_name": "<string>",
"doc_url": "<string>",
"contextual_text": "<string>"
}
}
],
"code": 123,
"message": "<string>",
"timestamp": 123
}{
"code": 123,
"message": "<string>"
}Body
application/json
查询内容,限制在1000字以内
知识库ID列表
请求唯一id,用于定位日志
文档ID列表
最终召回数量,取值范围为[1~20],默认为8
初始召回数量,取值范围为[1~100],默认为10
检索类型
- embedding: 向量化检索
- keyword:关键词检索
- mixed: 混合检索(默认)
Available options:
embedding, keyword, mixed 混合检索中向量检索的权重,取值范围(0~100),默认为80
是否开启重排,0: 不开启,1: 开启,默认不开启
Available options:
0, 1 重排模型,支持rerank、rerank-pro
Available options:
rerank, rerank-pro 相似度阈值,低于该阈值的切片会被过滤,取值范围为(0~1)
Was this page helpful?
⌘I