RAGflow對(duì)外API接口
發(fā)布日期:2025/8/23 22:28:39 瀏覽量:
RAGflow 的 API 接口,向知識(shí)庫(kù)提供內(nèi)容并進(jìn)行 RAG 處理,通常需要調(diào)用以下相關(guān)接口:
1. 創(chuàng)建數(shù)據(jù)集 (Create dataset)
接口 :POST /api/v1/datasets
作用 :在向知識(shí)庫(kù)提供內(nèi)容之前,需要先創(chuàng)建一個(gè)數(shù)據(jù)集(知識(shí)庫(kù))。這個(gè)接口允許你指定數(shù)據(jù)集的名稱、語(yǔ)言、嵌入模型等參數(shù)。
示例 :
--url http://{address}/api/v1/datasets \
--header ’Content-Type: application/json’ \
--header ’Authorization: Bearer <YOUR_API_KEY>’ \
--data ’{
"name": "test_1"
}’
2. 上傳文檔 (Upload documents)
接口 :POST /api/v1/datasets/{dataset_id}/documents
作用 :將文檔(如文本文件、PDF 等)上傳到指定的數(shù)據(jù)集(知識(shí)庫(kù))中。這是將內(nèi)容導(dǎo)入知識(shí)庫(kù)的關(guān)鍵步驟。
示例 :
curl --request POST \
--url http://{address}/api/v1/datasets/{dataset_id}/documents \
--header ’Content-Type: multipart/form-data’ \
--header ’Authorization: Bearer <YOUR_API_KEY>’ \
--form ’file=@./test1.txt’ \
--form ’file=@./test2.pdf’
3. 解析文檔 (Parse documents)
接口 :POST /api/v1/datasets/{dataset_id}/chunks
作用 :對(duì)上傳的文檔進(jìn)行解析,將其內(nèi)容轉(zhuǎn)換為適合 RAG 處理的格式。這個(gè)過程會(huì)根據(jù)文檔的類型和內(nèi)容進(jìn)行相應(yīng)的處理,如文本提取、分詞等。
示例 :
curl --request POST \
--url http://{address}/api/v1/datasets/{dataset_id}/chunks \
--header ’Content-Type: application/json’ \
--header ’Authorization: Bearer <YOUR_API_KEY>’ \
--data ’
{
"document_ids": ["97a5f1c2759811efaa500242ac120004","97ad64b6759811ef9fc30242ac120004"]
}’
4. 檢索內(nèi)容 (Retrieve chunks)
接口 :POST /api/v1/retrieval
作用 :在完成文檔解析后,如果需要從知識(shí)庫(kù)中檢索特定內(nèi)容,可以使用此接口。它會(huì)根據(jù)用戶的問題或關(guān)鍵詞,在知識(shí)庫(kù)中查找相關(guān)的文檔片段(chunks)。
示例 :
curl --request POST \
--url http://{address}/api/v1/retrieval \
--header ’Content-Type: application/json’ \
--header ’Authorization: Bearer <YOUR_API_KEY>’ \
--data ’
{
"question": "What is advantage of ragflow?",
"dataset_ids": ["b2a62730759d11ef987d0242ac120004"],
"document_ids": ["77df9ef4759a11ef8bdd0242ac120004"]
}’
5. 創(chuàng)建聊天會(huì)話 (Create session with chat assistant)
接口 :POST /api/v1/chats/{chat_id}/sessions
作用 :如果希望與知識(shí)庫(kù)進(jìn)行交互式對(duì)話,需要先創(chuàng)建一個(gè)聊天會(huì)話。這個(gè)會(huì)話將用于后續(xù)的對(duì)話交互。
示例 :
curl --request POST \
--url http://{address}/api/v1/chats/{chat_id}/sessions \
--header ’Content-Type: application/json’ \
--header ’Authorization: Bearer <YOUR_API_KEY>’ \
--data ’
{
"name": "new session"
}’
6. 與聊天助手對(duì)話 (Converse with chat assistant)
接口 :POST /api/v1/chats/{chat_id}/completions
作用 :在創(chuàng)建會(huì)話后,可以使用此接口向聊天助手提問,開啟基于知識(shí)庫(kù)的 AI 對(duì)話。聊天助手會(huì)根據(jù)知識(shí)庫(kù)中的內(nèi)容生成回答。
示例 :
curl --request POST \
--url http://{address}/api/v1/chats/{chat_id}/completions \
--header ’Content-Type: application/json’ \
--header ’Authorization: Bearer <YOUR_API_KEY>’ \
--data-binary ’
{
"question": "Who are you",
"stream": true,
"session_id":"9fa7691cb85c11ef9c5f0242ac120005"
}’
馬上咨詢: 如果您有業(yè)務(wù)方面的問題或者需求,歡迎您咨詢!我們帶來的不僅僅是技術(shù),還有行業(yè)經(jīng)驗(yàn)積累。
QQ: 39764417/308460098 Phone: 13 9800 1 9844 / 135 6887 9550 聯(lián)系人:石先生/雷先生