向量相似比對
根據提供的查詢內容或關鍵詞,從 Agent/Workflow 知識庫中檢索並提取知識片段。開發者可以透過指定 group_ids 或 data_ids 設定檢索範圍,並設置 top_k 參數。還可利用知識相關性評分與重排序,個性化檢索流程,實現客製化的檢索增強生成(RAG)能力。
請求方法
POST
接口位址
https://api-${endpoint}.gptbots.ai/v1/vector/match
認證方式
詳情請參閱 API 概覽中的認證說明。
請求
請求範例
curl -X POST 'https://api-${endpoint}.gptbots.ai/v1/vector/match' \
-H 'Authorization: Bearer ${API Key}' \
-H 'Content-Type: application/json' \
-d '{
"embedding_rate": 0.9 ,
"prompt": "GPTBots 提供哪些 API?",
"group_ids": ["1234567890","1230987654"],
"data_ids": ["1234567890","1230987654"],
"top_k": 10 ,
"rerank_version": "Jina-reranker-v2-base-multilingual",
"doc_correlation": 0.70
}'
curl -X POST 'https://api-${endpoint}.gptbots.ai/v1/vector/match' \
-H 'Authorization: Bearer ${API Key}' \
-H 'Content-Type: application/json' \
-d '{
"embedding_rate": 0.9 ,
"prompt": "GPTBots 提供哪些 API?",
"group_ids": ["1234567890","1230987654"],
"data_ids": ["1234567890","1230987654"],
"top_k": 10 ,
"rerank_version": "Jina-reranker-v2-base-multilingual",
"doc_correlation": 0.70
}'
此代碼塊在浮窗中顯示
請求標頭
| 欄位 | 類型 | 描述 |
|---|---|---|
| Authorization | Bearer ${API Key} | 使用 Authorization: Bearer ${API Key} 進行認證。API 金鑰可於 API Key 頁面取得。 |
| Content-Type | application/json | 內容類型,值為 application/json。 |
請求參數
| 欄位 | 類型 | 必填 | 描述 |
|---|---|---|---|
| embedding_rate | float | 否 | 指定關鍵詞檢索與語意檢索的權重比例。範圍:[0,1],預設為 1。例如:0 = 僅關鍵詞;1 = 僅語意;0.4 = 40% 關鍵詞、60% 語意。 |
| prompt | string | 是 | 用於與 Agent/Workflow 中文檔進行向量相似性匹配的關鍵詞或查詢內容。 |
| group_ids | array | 否 | 指定知識庫 ID 的向量檢索範圍。若提供一個或多個知識庫 ID,則於其聯集範圍內檢索。若為 null 或未提供,預設檢索所有知識庫。若為 [],則不檢索任何知識庫。 |
| data_ids | array | 否 | 指定文檔 ID 的向量檢索範圍。若提供一個或多個文檔 ID,則於其聯集範圍內檢索。若為 null 或未提供,預設檢索所有文檔。若為 [],則不檢索任何文檔。 |
| top_k | int | 是 | 向量相似性匹配後,返回前 K 筆結果。有效範圍:[1,50]。 |
| rerank_version | string | 否 | 精確檢索用的知識重排序模型名稱。可選:BGE-Rerank、Jina-reranker-v2-base-multilingual、Jina-colbert-v2、BCE-Rerank。 |
| doc_correlation | float | 否 | 知識相關性分數,代表用戶問題與知識片段的相似度。分數越高,相關性越大,但過高可能導致無可用知識片段。範圍:[0.1,0.95]。 |
當同時提供
group_ids與data_ids時,檢索會在兩者聯集的知識範圍內進行。若兩者皆為 null 或未提供,則預設檢索所有知識庫。若兩者皆為空陣列([]),則不檢索任何知識。
回應
回應範例
{
"total": 2,
"list": [
{
"content": "測試資料",
"data_id": "aS1CNvPK4XCckDKQNj7azC9a",
"document_name": "demo.md",
"score": 0.75
},
{
"content": "測試資料",
"data_id": "aS1CNvPK4XCckDKQNj7azC9a",
"document_name": "demo.md",
"score": 0.75
}
]
}
{
"total": 2,
"list": [
{
"content": "測試資料",
"data_id": "aS1CNvPK4XCckDKQNj7azC9a",
"document_name": "demo.md",
"score": 0.75
},
{
"content": "測試資料",
"data_id": "aS1CNvPK4XCckDKQNj7azC9a",
"document_name": "demo.md",
"score": 0.75
}
]
}
此代碼塊在浮窗中顯示
成功回應
| 欄位 | 類型 | 描述 |
|---|---|---|
| total | int | 返回的知識片段總數。 |
| list | JSON Array | 知識片段清單。 |
| content | string | 知識片段內容。 |
| data_id | string | 來源文檔 ID。 |
| score | float | 相似度分數。 |
失敗回應
| 欄位 | 類型 | 描述 |
|---|---|---|
| code | int | 錯誤代碼。 |
| message | string | 錯誤詳情。 |
錯誤代碼
| 代碼 | 訊息 |
|---|---|
| 40000 | 參數錯誤 |
| 40127 | 開發者認證失敗 |
| 20059 | Agent/Workflow 已刪除 |
