Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

http_api_reference.md 63KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342
  1. ---
  2. sidebar_position: 1
  3. slug: /http_api_reference
  4. ---
  5. # HTTP API Reference
  6. A complete reference for RAGFlow's RESTful API. Before proceeding, please ensure you [have your RAGFlow API key ready for authentication](../guides/develop/acquire_ragflow_api_key.md).
  7. ---
  8. :::tip API GROUPING
  9. Dataset Management
  10. :::
  11. ---
  12. ## Create dataset
  13. **POST** `/api/v1/datasets`
  14. Creates a dataset.
  15. ### Request
  16. - Method: POST
  17. - URL: `/api/v1/datasets`
  18. - Headers:
  19. - `'content-Type: application/json'`
  20. - `'Authorization: Bearer <YOUR_API_KEY>'`
  21. - Body:
  22. - `"name"`: `string`
  23. - `"avatar"`: `string`
  24. - `"description"`: `string`
  25. - `"language"`: `string`
  26. - `"embedding_model"`: `string`
  27. - `"permission"`: `string`
  28. - `"chunk_method"`: `string`
  29. - `"parser_config"`: `object`
  30. #### Request example
  31. ```bash
  32. curl --request POST \
  33. --url http://{address}/api/v1/datasets \
  34. --header 'Content-Type: application/json' \
  35. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  36. --data '{
  37. "name": "test_1"
  38. }'
  39. ```
  40. #### Request parameters
  41. - `"name"`: (*Body parameter*), `string`, *Required*
  42. The unique name of the dataset to create. It must adhere to the following requirements:
  43. - Permitted characters include:
  44. - English letters (a-z, A-Z)
  45. - Digits (0-9)
  46. - "_" (underscore)
  47. - Must begin with an English letter or underscore.
  48. - Maximum 65,535 characters.
  49. - Case-insensitive.
  50. - `"avatar"`: (*Body parameter*), `string`
  51. Base64 encoding of the avatar.
  52. - `"description"`: (*Body parameter*), `string`
  53. A brief description of the dataset to create.
  54. - `"language"`: (*Body parameter*), `string`
  55. The language setting of the dataset to create. Available options:
  56. - `"English"` (default)
  57. - `"Chinese"`
  58. - `"embedding_model"`: (*Body parameter*), `string`
  59. The name of the embedding model to use. For example: `"BAAI/bge-zh-v1.5"`
  60. - `"permission"`: (*Body parameter*), `string`
  61. Specifies who can access the dataset to create. You can set it only to `"me"` for now.
  62. - `"chunk_method"`: (*Body parameter*), `enum<string>`
  63. The chunking method of the dataset to create. Available options:
  64. - `"naive"`: General (default)
  65. - `"manual"`: Manual
  66. - `"qa"`: Q&A
  67. - `"table"`: Table
  68. - `"paper"`: Paper
  69. - `"book"`: Book
  70. - `"laws"`: Laws
  71. - `"presentation"`: Presentation
  72. - `"picture"`: Picture
  73. - `"one"`: One
  74. - `"knowledge_graph"`: Knowledge Graph
  75. Ensure your LLM is properly configured on the **Settings** page before selecting this. Please also note that Knowledge Graph consumes a large number of Tokens!
  76. - `"email"`: Email
  77. - `"parser_config"`: (*Body parameter*), `object`
  78. The configuration settings for the dataset parser. The attributes in this JSON object vary with the selected `"chunk_method"`:
  79. - If `"chunk_method"` is `"naive"`, the `"parser_config"` object contains the following attributes:
  80. - `"chunk_token_count"`: Defaults to `128`.
  81. - `"layout_recognize"`: Defaults to `true`.
  82. - `"html4excel"`: Indicates whether to convert Excel documents into HTML format. Defaults to `false`.
  83. - `"delimiter"`: Defaults to `"\n!?。;!?"`.
  84. - `"task_page_size"`: Defaults to `12`. For PDF only.
  85. - `"raptor"`: Raptor-specific settings. Defaults to: `{"use_raptor": false}`.
  86. - If `"chunk_method"` is `"qa"`, `"manuel"`, `"paper"`, `"book"`, `"laws"`, or `"presentation"`, the `"parser_config"` object contains the following attribute:
  87. - `"raptor"`: Raptor-specific settings. Defaults to: `{"use_raptor": false}`.
  88. - If `"chunk_method"` is `"table"`, `"picture"`, `"one"`, or `"email"`, `"parser_config"` is an empty JSON object.
  89. - If `"chunk_method"` is `"knowledge_graph"`, the `"parser_config"` object contains the following attributes:
  90. - `"chunk_token_count"`: Defaults to `128`.
  91. - `"delimiter"`: Defaults to `"\n!?。;!?"`.
  92. - `"entity_types"`: Defaults to `["organization","person","location","event","time"]`
  93. ### Response
  94. Success:
  95. ```json
  96. {
  97. "code": 0,
  98. "data": {
  99. "avatar": null,
  100. "chunk_count": 0,
  101. "chunk_method": "naive",
  102. "create_date": "Thu, 24 Oct 2024 09:14:07 GMT",
  103. "create_time": 1729761247434,
  104. "created_by": "69736c5e723611efb51b0242ac120007",
  105. "description": null,
  106. "document_count": 0,
  107. "embedding_model": "BAAI/bge-large-zh-v1.5",
  108. "id": "527fa74891e811ef9c650242ac120006",
  109. "language": "English",
  110. "name": "test_1",
  111. "parser_config": {
  112. "chunk_token_num": 128,
  113. "delimiter": "\\n!?;。;!?",
  114. "html4excel": false,
  115. "layout_recognize": true,
  116. "raptor": {
  117. "user_raptor": false
  118. }
  119. },
  120. "permission": "me",
  121. "similarity_threshold": 0.2,
  122. "status": "1",
  123. "tenant_id": "69736c5e723611efb51b0242ac120007",
  124. "token_num": 0,
  125. "update_date": "Thu, 24 Oct 2024 09:14:07 GMT",
  126. "update_time": 1729761247434,
  127. "vector_similarity_weight": 0.3
  128. }
  129. }
  130. ```
  131. Failure:
  132. ```json
  133. {
  134. "code": 102,
  135. "message": "Duplicated knowledgebase name in creating dataset."
  136. }
  137. ```
  138. ---
  139. ## Delete datasets
  140. **DELETE** `/api/v1/datasets`
  141. Deletes datasets by ID.
  142. ### Request
  143. - Method: DELETE
  144. - URL: `/api/v1/datasets`
  145. - Headers:
  146. - `'content-Type: application/json'`
  147. - `'Authorization: Bearer <YOUR_API_KEY>'`
  148. - Body:
  149. - `"ids"`: `list[string]`
  150. #### Request example
  151. ```bash
  152. curl --request DELETE \
  153. --url http://{address}/api/v1/datasets \
  154. --header 'Content-Type: application/json' \
  155. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  156. --data '{
  157. "ids": ["test_1", "test_2"]
  158. }'
  159. ```
  160. #### Request parameters
  161. - `"ids"`: (*Body parameter*), `list[string]`
  162. The IDs of the datasets to delete. If it is not specified, all datasets will be deleted.
  163. ### Response
  164. Success:
  165. ```json
  166. {
  167. "code": 0
  168. }
  169. ```
  170. Failure:
  171. ```json
  172. {
  173. "code": 102,
  174. "message": "You don't own the dataset."
  175. }
  176. ```
  177. ---
  178. ## Update dataset
  179. **PUT** `/api/v1/datasets/{dataset_id}`
  180. Updates configurations for a specified dataset.
  181. ### Request
  182. - Method: PUT
  183. - URL: `/api/v1/datasets/{dataset_id}`
  184. - Headers:
  185. - `'content-Type: application/json'`
  186. - `'Authorization: Bearer <YOUR_API_KEY>'`
  187. - Body:
  188. - `"name"`: `string`
  189. - `"embedding_model"`: `string`
  190. - `"chunk_method"`: `enum<string>`
  191. #### Request example
  192. ```bash
  193. curl --request PUT \
  194. --url http://{address}/api/v1/datasets/{dataset_id} \
  195. --header 'Content-Type: application/json' \
  196. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  197. --data '
  198. {
  199. "name": "updated_dataset"
  200. }'
  201. ```
  202. #### Request parameters
  203. - `dataset_id`: (*Path parameter*)
  204. The ID of the dataset to update.
  205. - `"name"`: (*Body parameter*), `string`
  206. The revised name of the dataset.
  207. - `"embedding_model"`: (*Body parameter*), `string`
  208. The updated embedding model name.
  209. - Ensure that `"chunk_count"` is `0` before updating `"embedding_model"`.
  210. - `"chunk_method"`: (*Body parameter*), `enum<string>`
  211. The chunking method for the dataset. Available options:
  212. - `"naive"`: General
  213. - `"manual`: Manual
  214. - `"qa"`: Q&A
  215. - `"table"`: Table
  216. - `"paper"`: Paper
  217. - `"book"`: Book
  218. - `"laws"`: Laws
  219. - `"presentation"`: Presentation
  220. - `"picture"`: Picture
  221. - `"one"`:One
  222. - `"email"`: Email
  223. - `"knowledge_graph"`: Knowledge Graph
  224. Ensure your LLM is properly configured on the **Settings** page before selecting this. Please also note that Knowledge Graph consumes a large number of Tokens!
  225. ### Response
  226. Success:
  227. ```json
  228. {
  229. "code": 0
  230. }
  231. ```
  232. Failure:
  233. ```json
  234. {
  235. "code": 102,
  236. "message": "Can't change tenant_id."
  237. }
  238. ```
  239. ---
  240. ## List datasets
  241. **GET** `/api/v1/datasets?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
  242. Lists datasets.
  243. ### Request
  244. - Method: GET
  245. - URL: `/api/v1/datasets?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
  246. - Headers:
  247. - `'Authorization: Bearer <YOUR_API_KEY>'`
  248. #### Request example
  249. ```bash
  250. curl --request GET \
  251. --url http://{address}/api/v1/datasets?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id} \
  252. --header 'Authorization: Bearer <YOUR_API_KEY>'
  253. ```
  254. #### Request parameters
  255. - `page`: (*Filter parameter*)
  256. Specifies the page on which the datasets will be displayed. Defaults to `1`.
  257. - `page_size`: (*Filter parameter*)
  258. The number of datasets on each page. Defaults to `30`.
  259. - `orderby`: (*Filter parameter*)
  260. The field by which datasets should be sorted. Available options:
  261. - `create_time` (default)
  262. - `update_time`
  263. - `desc`: (*Filter parameter*)
  264. Indicates whether the retrieved datasets should be sorted in descending order. Defaults to `true`.
  265. - `name`: (*Filter parameter*)
  266. The name of the dataset to retrieve.
  267. - `id`: (*Filter parameter*)
  268. The ID of the dataset to retrieve.
  269. ### Response
  270. Success:
  271. ```json
  272. {
  273. "code": 0,
  274. "data": [
  275. {
  276. "avatar": "",
  277. "chunk_count": 59,
  278. "create_date": "Sat, 14 Sep 2024 01:12:37 GMT",
  279. "create_time": 1726276357324,
  280. "created_by": "69736c5e723611efb51b0242ac120007",
  281. "description": null,
  282. "document_count": 1,
  283. "embedding_model": "BAAI/bge-large-zh-v1.5",
  284. "id": "6e211ee0723611efa10a0242ac120007",
  285. "language": "English",
  286. "name": "mysql",
  287. "chunk_method": "knowledge_graph",
  288. "parser_config": {
  289. "chunk_token_num": 8192,
  290. "delimiter": "\\n!?;。;!?",
  291. "entity_types": [
  292. "organization",
  293. "person",
  294. "location",
  295. "event",
  296. "time"
  297. ]
  298. },
  299. "permission": "me",
  300. "similarity_threshold": 0.2,
  301. "status": "1",
  302. "tenant_id": "69736c5e723611efb51b0242ac120007",
  303. "token_num": 12744,
  304. "update_date": "Thu, 10 Oct 2024 04:07:23 GMT",
  305. "update_time": 1728533243536,
  306. "vector_similarity_weight": 0.3
  307. }
  308. ]
  309. }
  310. ```
  311. Failure:
  312. ```json
  313. {
  314. "code": 102,
  315. "message": "The dataset doesn't exist"
  316. }
  317. ```
  318. ---
  319. :::tip API GROUPING
  320. File Management within Dataset
  321. :::
  322. ---
  323. ## Upload documents
  324. **POST** `/api/v1/datasets/{dataset_id}/documents`
  325. Uploads documents to a specified dataset.
  326. ### Request
  327. - Method: POST
  328. - URL: `/api/v1/datasets/{dataset_id}/documents`
  329. - Headers:
  330. - `'Content-Type: multipart/form-data'`
  331. - `'Authorization: Bearer <YOUR_API_KEY>'`
  332. - Form:
  333. - `'file=@{FILE_PATH}'`
  334. #### Request example
  335. ```bash
  336. curl --request POST \
  337. --url http://{address}/api/v1/datasets/{dataset_id}/documents \
  338. --header 'Content-Type: multipart/form-data' \
  339. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  340. --form 'file=@./test1.txt' \
  341. --form 'file=@./test2.pdf'
  342. ```
  343. #### Request parameters
  344. - `dataset_id`: (*Path parameter*)
  345. The ID of the dataset to which the documents will be uploaded.
  346. - `'file'`: (*Body parameter*)
  347. A document to upload.
  348. ### Response
  349. Success:
  350. ```json
  351. {
  352. "code": 0,
  353. "data": [
  354. {
  355. "chunk_method": "naive",
  356. "created_by": "69736c5e723611efb51b0242ac120007",
  357. "dataset_id": "527fa74891e811ef9c650242ac120006",
  358. "id": "b330ec2e91ec11efbc510242ac120004",
  359. "location": "1.txt",
  360. "name": "1.txt",
  361. "parser_config": {
  362. "chunk_token_num": 128,
  363. "delimiter": "\\n!?;。;!?",
  364. "html4excel": false,
  365. "layout_recognize": true,
  366. "raptor": {
  367. "user_raptor": false
  368. }
  369. },
  370. "run": "UNSTART",
  371. "size": 17966,
  372. "thumbnail": "",
  373. "type": "doc"
  374. }
  375. ]
  376. }
  377. ```
  378. Failure:
  379. ```json
  380. {
  381. "code": 101,
  382. "message": "No file part!"
  383. }
  384. ```
  385. ---
  386. ## Update document
  387. **PUT** `/api/v1/datasets/{dataset_id}/documents/{document_id}`
  388. Updates configurations for a specified document.
  389. ### Request
  390. - Method: PUT
  391. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}`
  392. - Headers:
  393. - `'content-Type: application/json'`
  394. - `'Authorization: Bearer <YOUR_API_KEY>'`
  395. - Body:
  396. - `"name"`:`string`
  397. - `"chunk_method"`:`string`
  398. - `"parser_config"`:`object`
  399. #### Request example
  400. ```bash
  401. curl --request PUT \
  402. --url http://{address}/api/v1/datasets/{dataset_id}/info/{document_id} \
  403. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  404. --header 'Content-Type: application/json' \
  405. --data '
  406. {
  407. "name": "manual.txt",
  408. "chunk_method": "manual",
  409. "parser_config": {"chunk_token_count": 128}
  410. }'
  411. ```
  412. #### Request parameters
  413. - `dataset_id`: (*Path parameter*)
  414. The ID of the associated dataset.
  415. - `document_id`: (*Path parameter*)
  416. The ID of the document to update.
  417. - `"name"`: (*Body parameter*), `string`
  418. - `"chunk_method"`: (*Body parameter*), `string`
  419. The parsing method to apply to the document:
  420. - `"naive"`: General
  421. - `"manual`: Manual
  422. - `"qa"`: Q&A
  423. - `"table"`: Table
  424. - `"paper"`: Paper
  425. - `"book"`: Book
  426. - `"laws"`: Laws
  427. - `"presentation"`: Presentation
  428. - `"picture"`: Picture
  429. - `"one"`: One
  430. - `"knowledge_graph"`: Knowledge Graph
  431. Ensure your LLM is properly configured on the **Settings** page before selecting this. Please also note that Knowledge Graph consumes a large number of Tokens!
  432. - `"email"`: Email
  433. - `"parser_config"`: (*Body parameter*), `object`
  434. The configuration settings for the dataset parser. The attributes in this JSON object vary with the selected `"chunk_method"`:
  435. - If `"chunk_method"` is `"naive"`, the `"parser_config"` object contains the following attributes:
  436. - `"chunk_token_count"`: Defaults to `128`.
  437. - `"layout_recognize"`: Defaults to `true`.
  438. - `"html4excel"`: Indicates whether to convert Excel documents into HTML format. Defaults to `false`.
  439. - `"delimiter"`: Defaults to `"\n!?。;!?"`.
  440. - `"task_page_size"`: Defaults to `12`. For PDF only.
  441. - `"raptor"`: Raptor-specific settings. Defaults to: `{"use_raptor": false}`.
  442. - If `"chunk_method"` is `"qa"`, `"manuel"`, `"paper"`, `"book"`, `"laws"`, or `"presentation"`, the `"parser_config"` object contains the following attribute:
  443. - `"raptor"`: Raptor-specific settings. Defaults to: `{"use_raptor": false}`.
  444. - If `"chunk_method"` is `"table"`, `"picture"`, `"one"`, or `"email"`, `"parser_config"` is an empty JSON object.
  445. - If `"chunk_method"` is `"knowledge_graph"`, the `"parser_config"` object contains the following attributes:
  446. - `"chunk_token_count"`: Defaults to `128`.
  447. - `"delimiter"`: Defaults to `"\n!?。;!?"`.
  448. - `"entity_types"`: Defaults to `["organization","person","location","event","time"]`
  449. ### Response
  450. Success:
  451. ```json
  452. {
  453. "code": 0
  454. }
  455. ```
  456. Failure:
  457. ```json
  458. {
  459. "code": 102,
  460. "message": "The dataset does not have the document."
  461. }
  462. ```
  463. ---
  464. ## Download document
  465. **GET** `/api/v1/datasets/{dataset_id}/documents/{document_id}`
  466. Downloads a document from a specified dataset.
  467. ### Request
  468. - Method: GET
  469. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}`
  470. - Headers:
  471. - `'Authorization: Bearer <YOUR_API_KEY>'`
  472. - Output:
  473. - `'{PATH_TO_THE_FILE}'`
  474. #### Request example
  475. ```bash
  476. curl --request GET \
  477. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id} \
  478. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  479. --output ./ragflow.txt
  480. ```
  481. #### Request parameters
  482. - `dataset_id`: (*Path parameter*)
  483. The associated dataset ID.
  484. - `documents_id`: (*Path parameter*)
  485. The ID of the document to download.
  486. ### Response
  487. Success:
  488. ```text
  489. This is a test to verify the file download feature.
  490. ```
  491. Failure:
  492. ```json
  493. {
  494. "code": 102,
  495. "message": "You do not own the dataset 7898da028a0511efbf750242ac1220005."
  496. }
  497. ```
  498. ---
  499. ## List documents
  500. **GET** `/api/v1/datasets/{dataset_id}/documents?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&keywords={keywords}&id={document_id}&name={document_name}`
  501. Lists documents in a specified dataset.
  502. ### Request
  503. - Method: GET
  504. - URL: `/api/v1/datasets/{dataset_id}/documents?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&keywords={keywords}&id={document_id}&name={document_name}`
  505. - Headers:
  506. - `'content-Type: application/json'`
  507. - `'Authorization: Bearer <YOUR_API_KEY>'`
  508. #### Request example
  509. ```bash
  510. curl --request GET \
  511. --url http://{address}/api/v1/datasets/{dataset_id}/documents?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&keywords={keywords}&id={document_id}&name={document_name} \
  512. --header 'Authorization: Bearer <YOUR_API_KEY>'
  513. ```
  514. #### Request parameters
  515. - `dataset_id`: (*Path parameter*)
  516. The associated dataset ID.
  517. - `keywords`: (*Filter parameter*), `string`
  518. The keywords used to match document titles.
  519. - `page`: (*Filter parameter*), `integer`
  520. Specifies the page on which the documents will be displayed. Defaults to `1`.
  521. - `page_size`: (*Filter parameter*), `integer`
  522. The maximum number of documents on each page. Defaults to `30`.
  523. - `orderby`: (*Filter parameter*), `string`
  524. The field by which documents should be sorted. Available options:
  525. - `create_time` (default)
  526. - `update_time`
  527. - `desc`: (*Filter parameter*), `boolean`
  528. Indicates whether the retrieved documents should be sorted in descending order. Defaults to `true`.
  529. - `id`: (*Filter parameter*), `string`
  530. The ID of the document to retrieve.
  531. ### Response
  532. Success:
  533. ```json
  534. {
  535. "code": 0,
  536. "data": {
  537. "docs": [
  538. {
  539. "chunk_count": 0,
  540. "create_date": "Mon, 14 Oct 2024 09:11:01 GMT",
  541. "create_time": 1728897061948,
  542. "created_by": "69736c5e723611efb51b0242ac120007",
  543. "id": "3bcfbf8a8a0c11ef8aba0242ac120006",
  544. "knowledgebase_id": "7898da028a0511efbf750242ac120005",
  545. "location": "Test_2.txt",
  546. "name": "Test_2.txt",
  547. "parser_config": {
  548. "chunk_token_count": 128,
  549. "delimiter": "\n!?。;!?",
  550. "layout_recognize": true,
  551. "task_page_size": 12
  552. },
  553. "chunk_method": "naive",
  554. "process_begin_at": null,
  555. "process_duation": 0.0,
  556. "progress": 0.0,
  557. "progress_msg": "",
  558. "run": "0",
  559. "size": 7,
  560. "source_type": "local",
  561. "status": "1",
  562. "thumbnail": null,
  563. "token_count": 0,
  564. "type": "doc",
  565. "update_date": "Mon, 14 Oct 2024 09:11:01 GMT",
  566. "update_time": 1728897061948
  567. }
  568. ],
  569. "total": 1
  570. }
  571. }
  572. ```
  573. Failure:
  574. ```json
  575. {
  576. "code": 102,
  577. "message": "You don't own the dataset 7898da028a0511efbf750242ac1220005. "
  578. }
  579. ```
  580. ---
  581. ## Delete documents
  582. **DELETE** `/api/v1/datasets/{dataset_id}/documents`
  583. Deletes documents by ID.
  584. ### Request
  585. - Method: DELETE
  586. - URL: `/api/v1/datasets/{dataset_id}/documents`
  587. - Headers:
  588. - `'Content-Type: application/json'`
  589. - `'Authorization: Bearer <YOUR_API_KEY>'`
  590. - Body:
  591. - `"ids"`: `list[string]`
  592. #### Request example
  593. ```bash
  594. curl --request DELETE \
  595. --url http://{address}/api/v1/datasets/{dataset_id}/documents \
  596. --header 'Content-Type: application/json' \
  597. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  598. --data '
  599. {
  600. "ids": ["id_1","id_2"]
  601. }'
  602. ```
  603. #### Request parameters
  604. - `dataset_id`: (*Path parameter*)
  605. The associated dataset ID.
  606. - `"ids"`: (*Body parameter*), `list[string]`
  607. The IDs of the documents to delete. If it is not specified, all documents in the specified dataset will be deleted.
  608. ### Response
  609. Success:
  610. ```json
  611. {
  612. "code": 0
  613. }.
  614. ```
  615. Failure:
  616. ```json
  617. {
  618. "code": 102,
  619. "message": "You do not own the dataset 7898da028a0511efbf750242ac1220005."
  620. }
  621. ```
  622. ---
  623. ## Parse documents
  624. **POST** `/api/v1/datasets/{dataset_id}/chunks`
  625. Parses documents in a specified dataset.
  626. ### Request
  627. - Method: POST
  628. - URL: `/api/v1/datasets/{dataset_id}/chunks`
  629. - Headers:
  630. - `'content-Type: application/json'`
  631. - `'Authorization: Bearer <YOUR_API_KEY>'`
  632. - Body:
  633. - `"document_ids"`: `list[string]`
  634. #### Request example
  635. ```bash
  636. curl --request POST \
  637. --url http://{address}/api/v1/datasets/{dataset_id}/chunks \
  638. --header 'Content-Type: application/json' \
  639. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  640. --data '
  641. {
  642. "document_ids": ["97a5f1c2759811efaa500242ac120004","97ad64b6759811ef9fc30242ac120004"]
  643. }'
  644. ```
  645. #### Request parameters
  646. - `dataset_id`: (*Path parameter*)
  647. The dataset ID.
  648. - `"document_ids"`: (*Body parameter*), `list[string]`, *Required*
  649. The IDs of the documents to parse.
  650. ### Response
  651. Success:
  652. ```json
  653. {
  654. "code": 0
  655. }
  656. ```
  657. Failure:
  658. ```json
  659. {
  660. "code": 102,
  661. "message": "`document_ids` is required"
  662. }
  663. ```
  664. ---
  665. ## Stop parsing documents
  666. **DELETE** `/api/v1/datasets/{dataset_id}/chunks`
  667. Stops parsing specified documents.
  668. ### Request
  669. - Method: DELETE
  670. - URL: `/api/v1/datasets/{dataset_id}/chunks`
  671. - Headers:
  672. - `'content-Type: application/json'`
  673. - `'Authorization: Bearer <YOUR_API_KEY>'`
  674. - Body:
  675. - `"document_ids"`: `list[string]`
  676. #### Request example
  677. ```bash
  678. curl --request DELETE \
  679. --url http://{address}/api/v1/datasets/{dataset_id}/chunks \
  680. --header 'Content-Type: application/json' \
  681. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  682. --data '
  683. {
  684. "document_ids": ["97a5f1c2759811efaa500242ac120004","97ad64b6759811ef9fc30242ac120004"]
  685. }'
  686. ```
  687. #### Request parameters
  688. - `dataset_id`: (*Path parameter*)
  689. The associated dataset ID.
  690. - `"document_ids"`: (*Body parameter*), `list[string]`, *Required*
  691. The IDs of the documents for which the parsing should be stopped.
  692. ### Response
  693. Success:
  694. ```json
  695. {
  696. "code": 0
  697. }
  698. ```
  699. Failure:
  700. ```json
  701. {
  702. "code": 102,
  703. "message": "`document_ids` is required"
  704. }
  705. ```
  706. ---
  707. ## Add chunks
  708. **POST** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
  709. Adds a chunk to a specified document in a specified dataset.
  710. ### Request
  711. - Method: POST
  712. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
  713. - Headers:
  714. - `'content-Type: application/json'`
  715. - `'Authorization: Bearer <YOUR_API_KEY>'`
  716. - Body:
  717. - `"content"`: `string`
  718. - `"important_keywords"`: `list[string]`
  719. #### Request example
  720. ```bash
  721. curl --request POST \
  722. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks \
  723. --header 'Content-Type: application/json' \
  724. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  725. --data '
  726. {
  727. "content": "<SOME_CHUNK_CONTENT_HERE>"
  728. }'
  729. ```
  730. #### Request parameters
  731. - `dataset_id`: (*Path parameter*)
  732. The associated dataset ID.
  733. - `document_ids`: (*Path parameter*)
  734. The associated document ID.
  735. - `"content"`: (*Body parameter*), `string`, *Required*
  736. The text content of the chunk.
  737. - `"important_keywords`(*Body parameter*), `list[string]`
  738. The key terms or phrases to tag with the chunk.
  739. ### Response
  740. Success:
  741. ```json
  742. {
  743. "code": 0,
  744. "data": {
  745. "chunk": {
  746. "content": "ragflow content",
  747. "create_time": "2024-10-16 08:05:04",
  748. "create_timestamp": 1729065904.581025,
  749. "dataset_id": [
  750. "c7ee74067a2c11efb21c0242ac120006"
  751. ],
  752. "document_id": "5c5999ec7be811ef9cab0242ac120005",
  753. "id": "d78435d142bd5cf6704da62c778795c5",
  754. "important_keywords": []
  755. }
  756. }
  757. }
  758. ```
  759. Failure:
  760. ```json
  761. {
  762. "code": 102,
  763. "message": "`content` is required"
  764. }
  765. ```
  766. ---
  767. ## List chunks
  768. **GET** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks?keywords={keywords}&page={page}&page_size={page_size}&id={id}`
  769. Lists chunks in a specified document.
  770. ### Request
  771. - Method: GET
  772. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks?keywords={keywords}&page={page}&page_size={page_size}&id={chunk_id}`
  773. - Headers:
  774. - `'Authorization: Bearer <YOUR_API_KEY>'`
  775. #### Request example
  776. ```bash
  777. curl --request GET \
  778. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks?keywords={keywords}&page={page}&page_size={page_size}&id={chunk_id} \
  779. --header 'Authorization: Bearer <YOUR_API_KEY>'
  780. ```
  781. #### Request parameters
  782. - `dataset_id`: (*Path parameter*)
  783. The associated dataset ID.
  784. - `document_ids`: (*Path parameter*)
  785. The associated document ID.
  786. - `keywords`(*Filter parameter*), `string`
  787. The keywords used to match chunk content.
  788. - `page`(*Filter parameter*), `integer`
  789. Specifies the page on which the chunks will be displayed. Defaults to `1`.
  790. - `page_size`(*Filter parameter*), `integer`
  791. The maximum number of chunks on each page. Defaults to `1024`.
  792. - `id`(*Filter parameter*), `string`
  793. The ID of the chunk to retrieve.
  794. ### Response
  795. Success:
  796. ```json
  797. {
  798. "code": 0,
  799. "data": {
  800. "chunks": [
  801. {
  802. "available_int": 1,
  803. "content": "This is a test content.",
  804. "docnm_kwd": "1.txt",
  805. "document_id": "b330ec2e91ec11efbc510242ac120004",
  806. "id": "b48c170e90f70af998485c1065490726",
  807. "image_id": "",
  808. "important_keywords": "",
  809. "positions": [
  810. ""
  811. ]
  812. }
  813. ],
  814. "doc": {
  815. "chunk_count": 1,
  816. "chunk_method": "naive",
  817. "create_date": "Thu, 24 Oct 2024 09:45:27 GMT",
  818. "create_time": 1729763127646,
  819. "created_by": "69736c5e723611efb51b0242ac120007",
  820. "dataset_id": "527fa74891e811ef9c650242ac120006",
  821. "id": "b330ec2e91ec11efbc510242ac120004",
  822. "location": "1.txt",
  823. "name": "1.txt",
  824. "parser_config": {
  825. "chunk_token_num": 128,
  826. "delimiter": "\\n!?;。;!?",
  827. "html4excel": false,
  828. "layout_recognize": true,
  829. "raptor": {
  830. "user_raptor": false
  831. }
  832. },
  833. "process_begin_at": "Thu, 24 Oct 2024 09:56:44 GMT",
  834. "process_duation": 0.54213,
  835. "progress": 0.0,
  836. "progress_msg": "Task dispatched...",
  837. "run": "2",
  838. "size": 17966,
  839. "source_type": "local",
  840. "status": "1",
  841. "thumbnail": "",
  842. "token_count": 8,
  843. "type": "doc",
  844. "update_date": "Thu, 24 Oct 2024 11:03:15 GMT",
  845. "update_time": 1729767795721
  846. },
  847. "total": 1
  848. }
  849. }
  850. ```
  851. Failure:
  852. ```json
  853. {
  854. "code": 102,
  855. "message": "You don't own the document 5c5999ec7be811ef9cab0242ac12000e5."
  856. }
  857. ```
  858. ---
  859. ## Delete chunks
  860. **DELETE** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
  861. Deletes chunks by ID.
  862. ### Request
  863. - Method: DELETE
  864. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
  865. - Headers:
  866. - `'content-Type: application/json'`
  867. - `'Authorization: Bearer <YOUR_API_KEY>'`
  868. - Body:
  869. - `"chunk_ids"`: `list[string]`
  870. #### Request example
  871. ```bash
  872. curl --request DELETE \
  873. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks \
  874. --header 'Content-Type: application/json' \
  875. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  876. --data '
  877. {
  878. "chunk_ids": ["test_1", "test_2"]
  879. }'
  880. ```
  881. #### Request parameters
  882. - `dataset_id`: (*Path parameter*)
  883. The associated dataset ID.
  884. - `document_ids`: (*Path parameter*)
  885. The associated document ID.
  886. - `"chunk_ids"`: (*Body parameter*), `list[string]`
  887. The IDs of the chunks to delete. If it is not specified, all chunks of the specified document will be deleted.
  888. ### Response
  889. Success:
  890. ```json
  891. {
  892. "code": 0
  893. }
  894. ```
  895. Failure:
  896. ```json
  897. {
  898. "code": 102,
  899. "message": "`chunk_ids` is required"
  900. }
  901. ```
  902. ---
  903. ## Update chunk
  904. **PUT** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks/{chunk_id}`
  905. Updates content or configurations for a specified chunk.
  906. ### Request
  907. - Method: PUT
  908. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks/{chunk_id}`
  909. - Headers:
  910. - `'content-Type: application/json'`
  911. - `'Authorization: Bearer <YOUR_API_KEY>'`
  912. - Body:
  913. - `"content"`: `string`
  914. - `"important_keywords"`: `list[string]`
  915. - `"available"`: `boolean`
  916. #### Request example
  917. ```bash
  918. curl --request PUT \
  919. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks/{chunk_id} \
  920. --header 'Content-Type: application/json' \
  921. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  922. --data '
  923. {
  924. "content": "ragflow123",
  925. "important_keywords": []
  926. }'
  927. ```
  928. #### Request parameters
  929. - `dataset_id`: (*Path parameter*)
  930. The associated dataset ID.
  931. - `document_ids`: (*Path parameter*)
  932. The associated document ID.
  933. - `chunk_id`: (*Path parameter*)
  934. The ID of the chunk to update.
  935. - `"content"`: (*Body parameter*), `string`
  936. The text content of the chunk.
  937. - `"important_keywords"`: (*Body parameter*), `list[string]`
  938. A list of key terms or phrases to tag with the chunk.
  939. - `"available"`: (*Body parameter*) `boolean`
  940. The chunk's availability status in the dataset. Value options:
  941. - `true`: Available (default)
  942. - `false`: Unavailable
  943. ### Response
  944. Success:
  945. ```json
  946. {
  947. "code": 0
  948. }
  949. ```
  950. Failure:
  951. ```json
  952. {
  953. "code": 102,
  954. "message": "Can't find this chunk 29a2d9987e16ba331fb4d7d30d99b71d2"
  955. }
  956. ```
  957. ---
  958. ## Retrieve chunks
  959. **POST** `/api/v1/retrieval`
  960. Retrieves chunks from specified datasets.
  961. ### Request
  962. - Method: POST
  963. - URL: `/api/v1/retrieval`
  964. - Headers:
  965. - `'content-Type: application/json'`
  966. - `'Authorization: Bearer <YOUR_API_KEY>'`
  967. - Body:
  968. - `"question"`: `string`
  969. - `"dataset_ids"`: `list[string]`
  970. - `"document_ids"`: `list[string]`
  971. - `"page"`: `integer`
  972. - `"page_size"`: `integer`
  973. - `"similarity_threshold"`: `float`
  974. - `"vector_similarity_weight"`: `float`
  975. - `"top_k"`: `integer`
  976. - `"rerank_id"`: `string`
  977. - `"keyword"`: `boolean`
  978. - `"highlight"`: `boolean`
  979. #### Request example
  980. ```bash
  981. curl --request POST \
  982. --url http://{address}/api/v1/retrieval \
  983. --header 'Content-Type: application/json' \
  984. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  985. --data '
  986. {
  987. "question": "What is advantage of ragflow?",
  988. "dataset_ids": ["b2a62730759d11ef987d0242ac120004"],
  989. "document_ids": ["77df9ef4759a11ef8bdd0242ac120004"]
  990. }'
  991. ```
  992. #### Request parameter
  993. - `"question"`: (*Body parameter*), `string`, *Required*
  994. The user query or query keywords.
  995. - `"dataset_ids"`: (*Body parameter*) `list[string]`
  996. The IDs of the datasets to search. If you do not set this argument, ensure that you set `"document_ids"`.
  997. - `"document_ids"`: (*Body parameter*), `list[string]`
  998. The IDs of the documents to search. Ensure that all selected documents use the same embedding model. Otherwise, an error will occur. If you do not set this argument, ensure that you set `"dataset_ids"`.
  999. - `"page"`: (*Body parameter*), `integer`
  1000. Specifies the page on which the chunks will be displayed. Defaults to `1`.
  1001. - `"page_size"`: (*Body parameter*)
  1002. The maximum number of chunks on each page. Defaults to `30`.
  1003. - `"similarity_threshold"`: (*Body parameter*)
  1004. The minimum similarity score. Defaults to `0.2`.
  1005. - `"vector_similarity_weight"`: (*Body parameter*), `float`
  1006. The weight of vector cosine similarity. Defaults to `0.3`. If x represents the weight of vector cosine similarity, then (1 - x) is the term similarity weight.
  1007. - `"top_k"`: (*Body parameter*), `integer`
  1008. The number of chunks engaged in vector cosine computaton. Defaults to `1024`.
  1009. - `"rerank_id"`: (*Body parameter*), `integer`
  1010. The ID of the rerank model.
  1011. - `"keyword"`: (*Body parameter*), `boolean`
  1012. Indicates whether to enable keyword-based matching:
  1013. - `true`: Enable keyword-based matching.
  1014. - `false`: Disable keyword-based matching (default).
  1015. - `"highlight"`: (*Body parameter*), `boolean`
  1016. Specifies whether to enable highlighting of matched terms in the results:
  1017. - `true`: Enable highlighting of matched terms.
  1018. - `false`: Disable highlighting of matched terms (default).
  1019. ### Response
  1020. Success:
  1021. ```json
  1022. {
  1023. "code": 0,
  1024. "data": {
  1025. "chunks": [
  1026. {
  1027. "content": "ragflow content",
  1028. "content_ltks": "ragflow content",
  1029. "document_id": "5c5999ec7be811ef9cab0242ac120005",
  1030. "document_keyword": "1.txt",
  1031. "highlight": "<em>ragflow</em> content",
  1032. "id": "d78435d142bd5cf6704da62c778795c5",
  1033. "image_id": "",
  1034. "important_keywords": [
  1035. ""
  1036. ],
  1037. "kb_id": "c7ee74067a2c11efb21c0242ac120006",
  1038. "positions": [
  1039. ""
  1040. ],
  1041. "similarity": 0.9669436601210759,
  1042. "term_similarity": 1.0,
  1043. "vector_similarity": 0.8898122004035864
  1044. }
  1045. ],
  1046. "doc_aggs": [
  1047. {
  1048. "count": 1,
  1049. "doc_id": "5c5999ec7be811ef9cab0242ac120005",
  1050. "doc_name": "1.txt"
  1051. }
  1052. ],
  1053. "total": 1
  1054. }
  1055. }
  1056. ```
  1057. Failure:
  1058. ```json
  1059. {
  1060. "code": 102,
  1061. "message": "`datasets` is required."
  1062. }
  1063. ```
  1064. ---
  1065. :::tip API GROUPING
  1066. Chat Assistant Management
  1067. :::
  1068. ---
  1069. ## Create chat assistant
  1070. **POST** `/api/v1/chats`
  1071. Creates a chat assistant.
  1072. ### Request
  1073. - Method: POST
  1074. - URL: `/api/v1/chats`
  1075. - Headers:
  1076. - `'content-Type: application/json'`
  1077. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1078. - Body:
  1079. - `"name"`: `string`
  1080. - `"avatar"`: `string`
  1081. - `"dataset_ids"`: `list[string]`
  1082. - `"llm"`: `object`
  1083. - `"prompt"`: `object`
  1084. #### Request example
  1085. ```shell
  1086. curl --request POST \
  1087. --url http://{address}/api/v1/chats \
  1088. --header 'Content-Type: application/json' \
  1089. --header 'Authorization: Bearer <YOUR_API_KEY>'
  1090. --data '{
  1091. "dataset_ids": ["0b2cbc8c877f11ef89070242ac120005"],
  1092. "name":"new_chat_1"
  1093. }'
  1094. ```
  1095. #### Request parameters
  1096. - `"name"`: (*Body parameter*), `string`, *Required*
  1097. The name of the chat assistant.
  1098. - `"avatar"`: (*Body parameter*), `string`
  1099. Base64 encoding of the avatar.
  1100. - `"dataset_ids"`: (*Body parameter*), `list[string]`
  1101. The IDs of the associated datasets.
  1102. - `"llm"`: (*Body parameter*), `object`
  1103. The LLM settings for the chat assistant to create. If it is not explicitly set, a JSON object with the following values will be generated as the default. An `llm` JSON object contains the following attributes:
  1104. - `"model_name"`, `string`
  1105. The chat model name. If not set, the user's default chat model will be used.
  1106. - `"temperature"`: `float`
  1107. Controls the randomness of the model's predictions. A lower temperature increases the model's confidence in its responses; a higher temperature increases creativity and diversity. Defaults to `0.1`.
  1108. - `"top_p"`: `float`
  1109. Also known as “nucleus sampling”, this parameter sets a threshold to select a smaller set of words to sample from. It focuses on the most likely words, cutting off the less probable ones. Defaults to `0.3`
  1110. - `"presence_penalty"`: `float`
  1111. This discourages the model from repeating the same information by penalizing words that have already appeared in the conversation. Defaults to `0.2`.
  1112. - `"frequency penalty"`: `float`
  1113. Similar to the presence penalty, this reduces the model’s tendency to repeat the same words frequently. Defaults to `0.7`.
  1114. - `"max_token"`: `integer`
  1115. The maximum length of the model’s output, measured in the number of tokens (words or pieces of words). Defaults to `512`.
  1116. - `"prompt"`: (*Body parameter*), `object`
  1117. Instructions for the LLM to follow. If it is not explicitly set, a JSON object with the following values will be generated as the default. A `prompt` JSON object contains the following attributes:
  1118. - `"similarity_threshold"`: `float` RAGFlow uses a hybrid of weighted keyword similarity and vector cosine similarity during retrieval. This argument sets the threshold for similarities between the user query and chunks. If a similarity score falls below this threshold, the corresponding chunk will be excluded from the results. The default value is `0.2`.
  1119. - `"keywords_similarity_weight"`: `float` This argument sets the weight of keyword similarity in the hybrid similarity score with vector cosine similarity or reranking model similarity. By adjusting this weight, you can control the influence of keyword similarity in relation to other similarity measures. The default value is `0.7`.
  1120. - `"top_n"`: `int` This argument specifies the number of top chunks with similarity scores above the `similarity_threshold` that are fed to the LLM. The LLM will *only* access these 'top N' chunks. The default value is `8`.
  1121. - `"variables"`: `object[]` This argument lists the variables to use in the 'System' field of **Chat Configurations**. Note that:
  1122. - `"knowledge"` is a reserved variable, which represents the retrieved chunks.
  1123. - All the variables in 'System' should be curly bracketed.
  1124. - The default value is `[{"key": "knowledge", "optional": true}]`.
  1125. - `"rerank_model"`: `string` If it is not specified, vector cosine similarity will be used; otherwise, reranking score will be used.
  1126. - `"empty_response"`: `string` If nothing is retrieved in the dataset for the user's question, this will be used as the response. To allow the LLM to improvise when nothing is found, leave this blank.
  1127. - `"opener"`: `string` The opening greeting for the user. Defaults to `"Hi! I am your assistant, can I help you?"`.
  1128. - `"show_quote`: `boolean` Indicates whether the source of text should be displayed. Defaults to `true`.
  1129. - `"prompt"`: `string` The prompt content.
  1130. ### Response
  1131. Success:
  1132. ```json
  1133. {
  1134. "code": 0,
  1135. "data": {
  1136. "avatar": "",
  1137. "create_date": "Thu, 24 Oct 2024 11:18:29 GMT",
  1138. "create_time": 1729768709023,
  1139. "dataset_ids": [
  1140. "527fa74891e811ef9c650242ac120006"
  1141. ],
  1142. "description": "A helpful Assistant",
  1143. "do_refer": "1",
  1144. "id": "b1f2f15691f911ef81180242ac120003",
  1145. "language": "English",
  1146. "llm": {
  1147. "frequency_penalty": 0.7,
  1148. "max_tokens": 512,
  1149. "model_name": "qwen-plus@Tongyi-Qianwen",
  1150. "presence_penalty": 0.4,
  1151. "temperature": 0.1,
  1152. "top_p": 0.3
  1153. },
  1154. "name": "12234",
  1155. "prompt": {
  1156. "empty_response": "Sorry! No relevant content was found in the knowledge base!",
  1157. "keywords_similarity_weight": 0.3,
  1158. "opener": "Hi! I'm your assistant, what can I do for you?",
  1159. "prompt": "You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\" Answers need to consider chat history.\n ",
  1160. "rerank_model": "",
  1161. "similarity_threshold": 0.2,
  1162. "top_n": 6,
  1163. "variables": [
  1164. {
  1165. "key": "knowledge",
  1166. "optional": false
  1167. }
  1168. ]
  1169. },
  1170. "prompt_type": "simple",
  1171. "status": "1",
  1172. "tenant_id": "69736c5e723611efb51b0242ac120007",
  1173. "top_k": 1024,
  1174. "update_date": "Thu, 24 Oct 2024 11:18:29 GMT",
  1175. "update_time": 1729768709023
  1176. }
  1177. }
  1178. ```
  1179. Failure:
  1180. ```json
  1181. {
  1182. "code": 102,
  1183. "message": "Duplicated chat name in creating dataset."
  1184. }
  1185. ```
  1186. ---
  1187. ## Update chat assistant
  1188. **PUT** `/api/v1/chats/{chat_id}`
  1189. Updates configurations for a specified chat assistant.
  1190. ### Request
  1191. - Method: PUT
  1192. - URL: `/api/v1/chats/{chat_id}`
  1193. - Headers:
  1194. - `'content-Type: application/json'`
  1195. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1196. - Body:
  1197. - `"name"`: `string`
  1198. - `"avatar"`: `string`
  1199. - `"dataset_ids"`: `list[string]`
  1200. - `"llm"`: `object`
  1201. - `"prompt"`: `object`
  1202. #### Request example
  1203. ```bash
  1204. curl --request PUT \
  1205. --url http://{address}/api/v1/chats/{chat_id} \
  1206. --header 'Content-Type: application/json' \
  1207. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1208. --data '
  1209. {
  1210. "name":"Test"
  1211. }'
  1212. ```
  1213. #### Parameters
  1214. - `chat_id`: (*Path parameter*)
  1215. The ID of the chat assistant to update.
  1216. - `"name"`: (*Body parameter*), `string`, *Required*
  1217. The revised name of the chat assistant.
  1218. - `"avatar"`: (*Body parameter*), `string`
  1219. Base64 encoding of the avatar.
  1220. - `"dataset_ids"`: (*Body parameter*), `list[string]`
  1221. The IDs of the associated datasets.
  1222. - `"llm"`: (*Body parameter*), `object`
  1223. The LLM settings for the chat assistant to create. If it is not explicitly set, a dictionary with the following values will be generated as the default. An `llm` object contains the following attributes:
  1224. - `"model_name"`, `string`
  1225. The chat model name. If not set, the user's default chat model will be used.
  1226. - `"temperature"`: `float`
  1227. Controls the randomness of the model's predictions. A lower temperature increases the model's confidence in its responses; a higher temperature increases creativity and diversity. Defaults to `0.1`.
  1228. - `"top_p"`: `float`
  1229. Also known as “nucleus sampling”, this parameter sets a threshold to select a smaller set of words to sample from. It focuses on the most likely words, cutting off the less probable ones. Defaults to `0.3`
  1230. - `"presence_penalty"`: `float`
  1231. This discourages the model from repeating the same information by penalizing words that have already appeared in the conversation. Defaults to `0.2`.
  1232. - `"frequency penalty"`: `float`
  1233. Similar to the presence penalty, this reduces the model’s tendency to repeat the same words frequently. Defaults to `0.7`.
  1234. - `"max_token"`: `integer`
  1235. The maximum length of the model’s output, measured in the number of tokens (words or pieces of words). Defaults to `512`.
  1236. - `"prompt"`: (*Body parameter*), `object`
  1237. Instructions for the LLM to follow. A `prompt` object contains the following attributes:
  1238. - `"similarity_threshold"`: `float` RAGFlow uses a hybrid of weighted keyword similarity and vector cosine similarity during retrieval. This argument sets the threshold for similarities between the user query and chunks. If a similarity score falls below this threshold, the corresponding chunk will be excluded from the results. The default value is `0.2`.
  1239. - `"keywords_similarity_weight"`: `float` This argument sets the weight of keyword similarity in the hybrid similarity score with vector cosine similarity or reranking model similarity. By adjusting this weight, you can control the influence of keyword similarity in relation to other similarity measures. The default value is `0.7`.
  1240. - `"top_n"`: `int` This argument specifies the number of top chunks with similarity scores above the `similarity_threshold` that are fed to the LLM. The LLM will *only* access these 'top N' chunks. The default value is `8`.
  1241. - `"variables"`: `object[]` This argument lists the variables to use in the 'System' field of **Chat Configurations**. Note that:
  1242. - `"knowledge"` is a reserved variable, which represents the retrieved chunks.
  1243. - All the variables in 'System' should be curly bracketed.
  1244. - The default value is `[{"key": "knowledge", "optional": true}]`
  1245. - `"rerank_model"`: `string` If it is not specified, vector cosine similarity will be used; otherwise, reranking score will be used.
  1246. - `"empty_response"`: `string` If nothing is retrieved in the dataset for the user's question, this will be used as the response. To allow the LLM to improvise when nothing is found, leave this blank.
  1247. - `"opener"`: `string` The opening greeting for the user. Defaults to `"Hi! I am your assistant, can I help you?"`.
  1248. - `"show_quote`: `boolean` Indicates whether the source of text should be displayed. Defaults to `true`.
  1249. - `"prompt"`: `string` The prompt content.
  1250. ### Response
  1251. Success:
  1252. ```json
  1253. {
  1254. "code": 0
  1255. }
  1256. ```
  1257. Failure:
  1258. ```json
  1259. {
  1260. "code": 102,
  1261. "message": "Duplicated chat name in updating dataset."
  1262. }
  1263. ```
  1264. ---
  1265. ## Delete chat assistants
  1266. **DELETE** `/api/v1/chats`
  1267. Deletes chat assistants by ID.
  1268. ### Request
  1269. - Method: DELETE
  1270. - URL: `/api/v1/chats`
  1271. - Headers:
  1272. - `'content-Type: application/json'`
  1273. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1274. - Body:
  1275. - `"ids"`: `list[string]`
  1276. #### Request example
  1277. ```bash
  1278. curl --request DELETE \
  1279. --url http://{address}/api/v1/chats \
  1280. --header 'Content-Type: application/json' \
  1281. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1282. --data '
  1283. {
  1284. "ids": ["test_1", "test_2"]
  1285. }'
  1286. ```
  1287. #### Request parameters
  1288. - `"ids"`: (*Body parameter*), `list[string]`
  1289. The IDs of the chat assistants to delete. If it is not specified, all chat assistants in the system will be deleted.
  1290. ### Response
  1291. Success:
  1292. ```json
  1293. {
  1294. "code": 0
  1295. }
  1296. ```
  1297. Failure:
  1298. ```json
  1299. {
  1300. "code": 102,
  1301. "message": "ids are required"
  1302. }
  1303. ```
  1304. ---
  1305. ## List chat assistants
  1306. **GET** `/api/v1/chats?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={chat_name}&id={chat_id}`
  1307. Lists chat assistants.
  1308. ### Request
  1309. - Method: GET
  1310. - URL: `/api/v1/chats?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
  1311. - Headers:
  1312. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1313. #### Request example
  1314. ```bash
  1315. curl --request GET \
  1316. --url http://{address}/api/v1/chats?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id} \
  1317. --header 'Authorization: Bearer <YOUR_API_KEY>'
  1318. ```
  1319. #### Request parameters
  1320. - `page`: (*Filter parameter*), `integer`
  1321. Specifies the page on which the chat assistants will be displayed. Defaults to `1`.
  1322. - `page_size`: (*Filter parameter*), `integer`
  1323. The number of chat assistants on each page. Defaults to `30`.
  1324. - `orderby`: (*Filter parameter*), `string`
  1325. The attribute by which the results are sorted. Available options:
  1326. - `create_time` (default)
  1327. - `update_time`
  1328. - `desc`: (*Filter parameter*), `boolean`
  1329. Indicates whether the retrieved chat assistants should be sorted in descending order. Defaults to `true`.
  1330. - `id`: (*Filter parameter*), `string`
  1331. The ID of the chat assistant to retrieve.
  1332. - `name`: (*Filter parameter*), `string`
  1333. The name of the chat assistant to retrieve.
  1334. ### Response
  1335. Success:
  1336. ```json
  1337. {
  1338. "code": 0,
  1339. "data": [
  1340. {
  1341. "avatar": "",
  1342. "create_date": "Fri, 18 Oct 2024 06:20:06 GMT",
  1343. "create_time": 1729232406637,
  1344. "description": "A helpful Assistant",
  1345. "do_refer": "1",
  1346. "id": "04d0d8e28d1911efa3630242ac120006",
  1347. "dataset_ids": ["527fa74891e811ef9c650242ac120006"],
  1348. "language": "English",
  1349. "llm": {
  1350. "frequency_penalty": 0.7,
  1351. "max_tokens": 512,
  1352. "model_name": "qwen-plus@Tongyi-Qianwen",
  1353. "presence_penalty": 0.4,
  1354. "temperature": 0.1,
  1355. "top_p": 0.3
  1356. },
  1357. "name": "13243",
  1358. "prompt": {
  1359. "empty_response": "Sorry! No relevant content was found in the knowledge base!",
  1360. "keywords_similarity_weight": 0.3,
  1361. "opener": "Hi! I'm your assistant, what can I do for you?",
  1362. "prompt": "You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\" Answers need to consider chat history.\n",
  1363. "rerank_model": "",
  1364. "similarity_threshold": 0.2,
  1365. "top_n": 6,
  1366. "variables": [
  1367. {
  1368. "key": "knowledge",
  1369. "optional": false
  1370. }
  1371. ]
  1372. },
  1373. "prompt_type": "simple",
  1374. "status": "1",
  1375. "tenant_id": "69736c5e723611efb51b0242ac120007",
  1376. "top_k": 1024,
  1377. "update_date": "Fri, 18 Oct 2024 06:20:06 GMT",
  1378. "update_time": 1729232406638
  1379. }
  1380. ]
  1381. }
  1382. ```
  1383. Failure:
  1384. ```json
  1385. {
  1386. "code": 102,
  1387. "message": "The chat doesn't exist"
  1388. }
  1389. ```
  1390. ## Create session
  1391. **POST** `/api/v1/chats/{chat_id}/sessions`
  1392. Creates a chat session.
  1393. ### Request
  1394. - Method: POST
  1395. - URL: `/api/v1/chats/{chat_id}/sessions`
  1396. - Headers:
  1397. - `'content-Type: application/json'`
  1398. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1399. - Body:
  1400. - `"name"`: `string`
  1401. #### Request example
  1402. ```bash
  1403. curl --request POST \
  1404. --url http://{address}/api/v1/chats/{chat_id}/sessions \
  1405. --header 'Content-Type: application/json' \
  1406. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1407. --data '
  1408. {
  1409. "name": "new session"
  1410. }'
  1411. ```
  1412. #### Request parameters
  1413. - `chat_id`: (*Path parameter*)
  1414. The ID of the associated chat assistant.
  1415. - `"name"`: (*Body parameter*), `string`
  1416. The name of the chat session to create.
  1417. ### Response
  1418. Success:
  1419. ```json
  1420. {
  1421. "code": 0,
  1422. "data": {
  1423. "chat_id": "2ca4b22e878011ef88fe0242ac120005",
  1424. "create_date": "Fri, 11 Oct 2024 08:46:14 GMT",
  1425. "create_time": 1728636374571,
  1426. "id": "4606b4ec87ad11efbc4f0242ac120006",
  1427. "messages": [
  1428. {
  1429. "content": "Hi! I am your assistant,can I help you?",
  1430. "role": "assistant"
  1431. }
  1432. ],
  1433. "name": "new session",
  1434. "update_date": "Fri, 11 Oct 2024 08:46:14 GMT",
  1435. "update_time": 1728636374571
  1436. }
  1437. }
  1438. ```
  1439. Failure:
  1440. ```json
  1441. {
  1442. "code": 102,
  1443. "message": "Name can not be empty."
  1444. }
  1445. ```
  1446. ---
  1447. ## Update session
  1448. **PUT** `/api/v1/chats/{chat_id}/sessions/{session_id}`
  1449. Updates a chat session.
  1450. ### Request
  1451. - Method: PUT
  1452. - URL: `/api/v1/chats/{chat_id}/sessions/{session_id}`
  1453. - Headers:
  1454. - `'content-Type: application/json'`
  1455. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1456. - Body:
  1457. - `"name`: `string`
  1458. #### Request example
  1459. ```bash
  1460. curl --request PUT \
  1461. --url http://{address}/api/v1/chats/{chat_id}/sessions/{session_id} \
  1462. --header 'Content-Type: application/json' \
  1463. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1464. --data '
  1465. {
  1466. "name": "<REVISED_SESSION_NAME_HERE>"
  1467. }'
  1468. ```
  1469. #### Request Parameter
  1470. - `chat_id`: (*Path parameter*)
  1471. The ID of the associated chat assistant.
  1472. - `session_id`: (*Path parameter*)
  1473. The ID of the session to update.
  1474. - `"name"`: (*Body Parameter), `string`
  1475. The revised name of the session.
  1476. ### Response
  1477. Success:
  1478. ```json
  1479. {
  1480. "code": 0
  1481. }
  1482. ```
  1483. Failure:
  1484. ```json
  1485. {
  1486. "code": 102,
  1487. "message": "Name cannot be empty."
  1488. }
  1489. ```
  1490. ---
  1491. ## List sessions
  1492. **GET** `/api/v1/chats/{chat_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={session_name}&id={session_id}`
  1493. Lists sessions associated with a specified chat assistant.
  1494. ### Request
  1495. - Method: GET
  1496. - URL: `/api/v1/chats/{chat_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={session_name}&id={session_id}`
  1497. - Headers:
  1498. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1499. #### Request example
  1500. ```bash
  1501. curl --request GET \
  1502. --url http://{address}/api/v1/chats/{chat_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={session_name}&id={session_id} \
  1503. --header 'Authorization: Bearer <YOUR_API_KEY>'
  1504. ```
  1505. #### Request Parameters
  1506. - `chat_id`: (*Path parameter*)
  1507. The ID of the associated chat assistant.
  1508. - `page`: (*Filter parameter*), `integer`
  1509. Specifies the page on which the sessions will be displayed. Defaults to `1`.
  1510. - `page_size`: (*Filter parameter*), `integer`
  1511. The number of sessions on each page. Defaults to `30`.
  1512. - `orderby`: (*Filter parameter*), `string`
  1513. The field by which sessions should be sorted. Available options:
  1514. - `create_time` (default)
  1515. - `update_time`
  1516. - `desc`: (*Filter parameter*), `boolean`
  1517. Indicates whether the retrieved sessions should be sorted in descending order. Defaults to `true`.
  1518. - `name`: (*Filter parameter*) `string`
  1519. The name of the chat session to retrieve.
  1520. - `id`: (*Filter parameter*), `string`
  1521. The ID of the chat session to retrieve.
  1522. ### Response
  1523. Success:
  1524. ```json
  1525. {
  1526. "code": 0,
  1527. "data": [
  1528. {
  1529. "chat": "2ca4b22e878011ef88fe0242ac120005",
  1530. "create_date": "Fri, 11 Oct 2024 08:46:43 GMT",
  1531. "create_time": 1728636403974,
  1532. "id": "578d541e87ad11ef96b90242ac120006",
  1533. "messages": [
  1534. {
  1535. "content": "Hi! I am your assistant,can I help you?",
  1536. "role": "assistant"
  1537. }
  1538. ],
  1539. "name": "new session",
  1540. "update_date": "Fri, 11 Oct 2024 08:46:43 GMT",
  1541. "update_time": 1728636403974
  1542. }
  1543. ]
  1544. }
  1545. ```
  1546. Failure:
  1547. ```json
  1548. {
  1549. "code": 102,
  1550. "message": "The session doesn't exist"
  1551. }
  1552. ```
  1553. ---
  1554. ## Delete sessions
  1555. **DELETE** `/api/v1/chats/{chat_id}/sessions`
  1556. Deletes sessions by ID.
  1557. ### Request
  1558. - Method: DELETE
  1559. - URL: `/api/v1/chats/{chat_id}/sessions`
  1560. - Headers:
  1561. - `'content-Type: application/json'`
  1562. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1563. - Body:
  1564. - `"ids"`: `list[string]`
  1565. #### Request example
  1566. ```bash
  1567. # Either id or name must be provided, but not both.
  1568. curl --request DELETE \
  1569. --url http://{address}/api/v1/chats/{chat_id}/sessions \
  1570. --header 'Content-Type: application/json' \
  1571. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1572. --data '
  1573. {
  1574. "ids": ["test_1", "test_2"]
  1575. }'
  1576. ```
  1577. #### Request Parameters
  1578. - `chat_id`: (*Path parameter*)
  1579. The ID of the associated chat assistant.
  1580. - `"ids"`: (*Body Parameter*), `list[string]`
  1581. The IDs of the sessions to delete. If it is not specified, all sessions associated with the specified chat assistant will be deleted.
  1582. ### Response
  1583. Success:
  1584. ```json
  1585. {
  1586. "code": 0
  1587. }
  1588. ```
  1589. Failure:
  1590. ```json
  1591. {
  1592. "code": 102,
  1593. "message": "The chat doesn't own the session"
  1594. }
  1595. ```
  1596. ---
  1597. ## Converse
  1598. **POST** `/api/v1/chats/{chat_id}/completions`
  1599. Asks a question to start an AI-powered conversation.
  1600. ### Request
  1601. - Method: POST
  1602. - URL: `/api/v1/chats/{chat_id}/completions`
  1603. - Headers:
  1604. - `'content-Type: application/json'`
  1605. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1606. - Body:
  1607. - `"question"`: `string`
  1608. - `"stream"`: `boolean`
  1609. - `"session_id"`: `string`
  1610. #### Request example
  1611. ```bash
  1612. curl --request POST \
  1613. --url http://{address}/api/v1/chats/{chat_id}/completions \
  1614. --header 'Content-Type: application/json' \
  1615. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1616. --data-binary '
  1617. {
  1618. "question": "What is RAGFlow?",
  1619. "stream": true
  1620. }'
  1621. ```
  1622. #### Request Parameters
  1623. - `chat_id`: (*Path parameter*)
  1624. The ID of the associated chat assistant.
  1625. - `"question"`: (*Body Parameter*), `string` *Required*
  1626. The question to start an AI-powered conversation.
  1627. - `"stream"`: (*Body Parameter*), `boolean`
  1628. Indicates whether to output responses in a streaming way:
  1629. - `true`: Enable streaming.
  1630. - `false`: Disable streaming (default).
  1631. - `"session_id"`: (*Body Parameter*)
  1632. The ID of session. If it is not provided, a new session will be generated.
  1633. ### Response
  1634. Success:
  1635. ```text
  1636. data:{
  1637. "code": 0,
  1638. "data": {
  1639. "answer": "I am an intelligent assistant designed to help answer questions by summarizing content from a",
  1640. "reference": {},
  1641. "audio_binary": null,
  1642. "id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
  1643. "session_id": "82b0ab2a9c1911ef9d870242ac120006"
  1644. }
  1645. }
  1646. data:{
  1647. "code": 0,
  1648. "data": {
  1649. "answer": "I am an intelligent assistant designed to help answer questions by summarizing content from a knowledge base. My responses are based on the information available in the knowledge base and",
  1650. "reference": {},
  1651. "audio_binary": null,
  1652. "id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
  1653. "session_id": "82b0ab2a9c1911ef9d870242ac120006"
  1654. }
  1655. }
  1656. data:{
  1657. "code": 0,
  1658. "data": {
  1659. "answer": "I am an intelligent assistant designed to help answer questions by summarizing content from a knowledge base. My responses are based on the information available in the knowledge base and any relevant chat history.",
  1660. "reference": {},
  1661. "audio_binary": null,
  1662. "id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
  1663. "session_id": "82b0ab2a9c1911ef9d870242ac120006"
  1664. }
  1665. }
  1666. data:{
  1667. "code": 0,
  1668. "data": {
  1669. "answer": "I am an intelligent assistant designed to help answer questions by summarizing content from a knowledge base ##0$$. My responses are based on the information available in the knowledge base and any relevant chat history.",
  1670. "reference": {
  1671. "total": 1,
  1672. "chunks": [
  1673. {
  1674. "id": "faf26c791128f2d5e821f822671063bd",
  1675. "content": "xxxxxxxx",
  1676. "document_id": "dd58f58e888511ef89c90242ac120006",
  1677. "document_name": "1.txt",
  1678. "dataset_id": "8e83e57a884611ef9d760242ac120006",
  1679. "image_id": "",
  1680. "similarity": 0.7,
  1681. "vector_similarity": 0.0,
  1682. "term_similarity": 1.0,
  1683. "positions": [
  1684. ""
  1685. ]
  1686. }
  1687. ],
  1688. "doc_aggs": [
  1689. {
  1690. "doc_name": "1.txt",
  1691. "doc_id": "dd58f58e888511ef89c90242ac120006",
  1692. "count": 1
  1693. }
  1694. ]
  1695. },
  1696. "prompt": "xxxxxxxxxxx",
  1697. "id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
  1698. "session_id": "82b0ab2a9c1911ef9d870242ac120006"
  1699. }
  1700. }
  1701. data:{
  1702. "code": 0,
  1703. "data": true
  1704. }
  1705. ```
  1706. Failure:
  1707. ```json
  1708. {
  1709. "code": 102,
  1710. "message": "Please input your question."
  1711. }
  1712. ```
  1713. ## Create agent session
  1714. **POST** `/api/v1/agents/{agent_id}/sessions`
  1715. Creates an agent session.
  1716. ### Request
  1717. - Method: POST
  1718. - URL: `/api/v1/agents/{agent_id}/sessions`
  1719. - Headers:
  1720. - `'content-Type: application/json'`
  1721. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1722. - Body:
  1723. #### Request example
  1724. ```bash
  1725. curl --request POST \
  1726. --url http://{address}/api/v1/agents/{agent_id}/sessions \
  1727. --header 'Content-Type: application/json' \
  1728. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1729. --data '{
  1730. }'
  1731. ```
  1732. #### Request parameters
  1733. - `agent_id`: (*Path parameter*)
  1734. The ID of the associated agent assistant.
  1735. ### Response
  1736. Success:
  1737. ```json
  1738. {
  1739. "code": 0,
  1740. "data": {
  1741. "agent_id": "2e45b5209c1011efa3e90242ac120006",
  1742. "id": "7869e9e49c1711ef92840242ac120006",
  1743. "message": [
  1744. {
  1745. "content": "Hello! I am the HR responsible for recruitment at Infineon. I learned that you are an expert in this field, and I took the liberty of reaching out to you. There is an opportunity I would like to share with you. RAGFlow is currently looking for a senior engineer for your position. I was wondering if you might be interested?",
  1746. "role": "assistant"
  1747. }
  1748. ],
  1749. "source": "agent",
  1750. "user_id": ""
  1751. }
  1752. }
  1753. ```
  1754. Failure:
  1755. ```json
  1756. {
  1757. "code": 102,
  1758. "message": "Agent not found."
  1759. }
  1760. ```
  1761. ## Converse through agent
  1762. **POST** `/api/v1/agents/{agent_id}/completions`
  1763. #######
  1764. Asks a question to start an AI-powered conversation.
  1765. ### Request
  1766. - Method: POST
  1767. - URL: `/api/v1/agents/{agent_id}/completions`
  1768. - Headers:
  1769. - `'content-Type: application/json'`
  1770. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1771. - Body:
  1772. - `"question"`: `string`
  1773. - `"stream"`: `boolean`
  1774. - `"session_id"`: `string`
  1775. #### Request example
  1776. ```bash
  1777. curl --request POST \
  1778. --url http://{address}/api/v1/agents/{agent_id}/completions \
  1779. --header 'Content-Type: application/json' \
  1780. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1781. --data-binary '
  1782. {
  1783. "question": "What is RAGFlow?",
  1784. "stream": true
  1785. }'
  1786. ```
  1787. #### Request Parameters
  1788. - `agent_id`: (*Path parameter*)
  1789. The ID of the associated agent assistant.
  1790. - `"question"`: (*Body Parameter*), `string` *Required*
  1791. The question to start an AI-powered conversation.
  1792. - `"stream"`: (*Body Parameter*), `boolean`
  1793. Indicates whether to output responses in a streaming way:
  1794. - `true`: Enable streaming.
  1795. - `false`: Disable streaming (default).
  1796. - `"session_id"`: (*Body Parameter*)
  1797. The ID of session. If it is not provided, a new session will be generated.
  1798. ### Response
  1799. Success:
  1800. ```text
  1801. data:{
  1802. "code": 0,
  1803. "message": "",
  1804. "data": {
  1805. "answer": "",
  1806. "reference": [],
  1807. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1808. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1809. }
  1810. }
  1811. data:{
  1812. "code": 0,
  1813. "message": "",
  1814. "data": {
  1815. "answer": "Hello",
  1816. "reference": [],
  1817. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1818. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1819. }
  1820. }
  1821. data:{
  1822. "code": 0,
  1823. "message": "",
  1824. "data": {
  1825. "answer": "Hello!",
  1826. "reference": [],
  1827. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1828. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1829. }
  1830. }
  1831. data:{
  1832. "code": 0,
  1833. "message": "",
  1834. "data": {
  1835. "answer": "Hello! How",
  1836. "reference": [],
  1837. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1838. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1839. }
  1840. }
  1841. data:{
  1842. "code": 0,
  1843. "message": "",
  1844. "data": {
  1845. "answer": "Hello! How can",
  1846. "reference": [],
  1847. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1848. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1849. }
  1850. }
  1851. data:{
  1852. "code": 0,
  1853. "message": "",
  1854. "data": {
  1855. "answer": "Hello! How can I",
  1856. "reference": [],
  1857. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1858. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1859. }
  1860. }
  1861. data:{
  1862. "code": 0,
  1863. "message": "",
  1864. "data": {
  1865. "answer": "Hello! How can I assist",
  1866. "reference": [],
  1867. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1868. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1869. }
  1870. }
  1871. data:{
  1872. "code": 0,
  1873. "message": "",
  1874. "data": {
  1875. "answer": "Hello! How can I assist you",
  1876. "reference": [],
  1877. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1878. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1879. }
  1880. }
  1881. data:{
  1882. "code": 0,
  1883. "message": "",
  1884. "data": {
  1885. "answer": "Hello! How can I assist you today",
  1886. "reference": [],
  1887. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1888. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1889. }
  1890. }
  1891. data:{
  1892. "code": 0,
  1893. "message": "",
  1894. "data": {
  1895. "answer": "Hello! How can I assist you today?",
  1896. "reference": [],
  1897. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1898. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1899. }
  1900. }
  1901. data:{
  1902. "code": 0,
  1903. "message": "",
  1904. "data": {
  1905. "answer": "Hello! How can I assist you today?",
  1906. "reference": [],
  1907. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1908. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1909. }
  1910. }
  1911. data:{
  1912. "code": 0,
  1913. "message": "",
  1914. "data": true
  1915. }
  1916. ```
  1917. Failure:
  1918. ```json
  1919. {
  1920. "code": 102,
  1921. "message": "`question` is required."
  1922. }
  1923. ```