Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

http_api_reference.md 102KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736
  1. ---
  2. sidebar_position: 4
  3. slug: /http_api_reference
  4. ---
  5. # HTTP API
  6. A complete reference for RAGFlow's RESTful API. Before proceeding, please ensure you [have your RAGFlow API key ready for authentication](../guides/models/llm_api_key_setup.md).
  7. ---
  8. ## ERROR CODES
  9. ---
  10. | Code | Message | Description |
  11. | ---- | --------------------- | -------------------------- |
  12. | 400 | Bad Request | Invalid request parameters |
  13. | 401 | Unauthorized | Unauthorized access |
  14. | 403 | Forbidden | Access denied |
  15. | 404 | Not Found | Resource not found |
  16. | 500 | Internal Server Error | Server internal error |
  17. | 1001 | Invalid Chunk ID | Invalid Chunk ID |
  18. | 1002 | Chunk Update Failed | Chunk update failed |
  19. ---
  20. ## OpenAI-Compatible API
  21. ---
  22. ### Create chat completion
  23. **POST** `/api/v1/chats_openai/{chat_id}/chat/completions`
  24. Creates a model response for a given chat conversation.
  25. This API follows the same request and response format as OpenAI's API. It allows you to interact with the model in a manner similar to how you would with [OpenAI's API](https://platform.openai.com/docs/api-reference/chat/create).
  26. #### Request
  27. - Method: POST
  28. - URL: `/api/v1/chats_openai/{chat_id}/chat/completions`
  29. - Headers:
  30. - `'content-Type: application/json'`
  31. - `'Authorization: Bearer <YOUR_API_KEY>'`
  32. - Body:
  33. - `"model"`: `string`
  34. - `"messages"`: `object list`
  35. - `"stream"`: `boolean`
  36. ##### Request example
  37. ```bash
  38. curl --request POST \
  39. --url http://{address}/api/v1/chats_openai/{chat_id}/chat/completions \
  40. --header 'Content-Type: application/json' \
  41. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  42. --data '{
  43. "model": "model",
  44. "messages": [{"role": "user", "content": "Say this is a test!"}],
  45. "stream": true
  46. }'
  47. ```
  48. ##### Request Parameters
  49. - `model` (*Body parameter*) `string`, *Required*
  50. The model used to generate the response. The server will parse this automatically, so you can set it to any value for now.
  51. - `messages` (*Body parameter*) `list[object]`, *Required*
  52. A list of historical chat messages used to generate the response. This must contain at least one message with the `user` role.
  53. - `stream` (*Body parameter*) `boolean`
  54. Whether to receive the response as a stream. Set this to `false` explicitly if you prefer to receive the entire response in one go instead of as a stream.
  55. #### Response
  56. Stream:
  57. ```json
  58. {
  59. "id": "chatcmpl-3a9c3572f29311efa69751e139332ced",
  60. "choices": [
  61. {
  62. "delta": {
  63. "content": "This is a test. If you have any specific questions or need information, feel",
  64. "role": "assistant",
  65. "function_call": null,
  66. "tool_calls": null
  67. },
  68. "finish_reason": null,
  69. "index": 0,
  70. "logprobs": null
  71. }
  72. ],
  73. "created": 1740543996,
  74. "model": "model",
  75. "object": "chat.completion.chunk",
  76. "system_fingerprint": "",
  77. "usage": null
  78. }
  79. // omit duplicated information
  80. {"choices":[{"delta":{"content":" free to ask, and I will do my best to provide an answer based on","role":"assistant"}}]}
  81. {"choices":[{"delta":{"content":" the knowledge I have. If your question is unrelated to the provided knowledge base,","role":"assistant"}}]}
  82. {"choices":[{"delta":{"content":" I will let you know.","role":"assistant"}}]}
  83. // the last chunk
  84. {
  85. "id": "chatcmpl-3a9c3572f29311efa69751e139332ced",
  86. "choices": [
  87. {
  88. "delta": {
  89. "content": null,
  90. "role": "assistant",
  91. "function_call": null,
  92. "tool_calls": null
  93. },
  94. "finish_reason": "stop",
  95. "index": 0,
  96. "logprobs": null
  97. }
  98. ],
  99. "created": 1740543996,
  100. "model": "model",
  101. "object": "chat.completion.chunk",
  102. "system_fingerprint": "",
  103. "usage": {
  104. "prompt_tokens": 18,
  105. "completion_tokens": 225,
  106. "total_tokens": 243
  107. }
  108. }
  109. ```
  110. Non-stream:
  111. ```json
  112. {
  113. "choices":[
  114. {
  115. "finish_reason":"stop",
  116. "index":0,
  117. "logprobs":null,
  118. "message":{
  119. "content":"This is a test. If you have any specific questions or need information, feel free to ask, and I will do my best to provide an answer based on the knowledge I have. If your question is unrelated to the provided knowledge base, I will let you know.",
  120. "role":"assistant"
  121. }
  122. }
  123. ],
  124. "created":1740543499,
  125. "id":"chatcmpl-3a9c3572f29311efa69751e139332ced",
  126. "model":"model",
  127. "object":"chat.completion",
  128. "usage":{
  129. "completion_tokens":246,
  130. "completion_tokens_details":{
  131. "accepted_prediction_tokens":246,
  132. "reasoning_tokens":18,
  133. "rejected_prediction_tokens":0
  134. },
  135. "prompt_tokens":18,
  136. "total_tokens":264
  137. }
  138. }
  139. ```
  140. Failure:
  141. ```json
  142. {
  143. "code": 102,
  144. "message": "The last content of this conversation is not from user."
  145. }
  146. ```
  147. ---
  148. ### Create agent completion
  149. **POST** `/api/v1/agents_openai/{agent_id}/chat/completions`
  150. Creates a model response for a given chat conversation.
  151. This API follows the same request and response format as OpenAI's API. It allows you to interact with the model in a manner similar to how you would with [OpenAI's API](https://platform.openai.com/docs/api-reference/chat/create).
  152. #### Request
  153. - Method: POST
  154. - URL: `/api/v1/agents_openai/{agent_id}/chat/completions`
  155. - Headers:
  156. - `'content-Type: application/json'`
  157. - `'Authorization: Bearer <YOUR_API_KEY>'`
  158. - Body:
  159. - `"model"`: `string`
  160. - `"messages"`: `object list`
  161. - `"stream"`: `boolean`
  162. ##### Request example
  163. ```bash
  164. curl --request POST \
  165. --url http://{address}/api/v1/agents_openai/{agent_id}/chat/completions \
  166. --header 'Content-Type: application/json' \
  167. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  168. --data '{
  169. "model": "model",
  170. "messages": [{"role": "user", "content": "Say this is a test!"}],
  171. "stream": true
  172. }'
  173. ```
  174. ##### Request Parameters
  175. - `model` (*Body parameter*) `string`, *Required*
  176. The model used to generate the response. The server will parse this automatically, so you can set it to any value for now.
  177. - `messages` (*Body parameter*) `list[object]`, *Required*
  178. A list of historical chat messages used to generate the response. This must contain at least one message with the `user` role.
  179. - `stream` (*Body parameter*) `boolean`
  180. Whether to receive the response as a stream. Set this to `false` explicitly if you prefer to receive the entire response in one go instead of as a stream.
  181. #### Response
  182. Stream:
  183. ```json
  184. {
  185. "id": "chatcmpl-3a9c3572f29311efa69751e139332ced",
  186. "choices": [
  187. {
  188. "delta": {
  189. "content": "This is a test. If you have any specific questions or need information, feel",
  190. "role": "assistant",
  191. "function_call": null,
  192. "tool_calls": null
  193. },
  194. "finish_reason": null,
  195. "index": 0,
  196. "logprobs": null
  197. }
  198. ],
  199. "created": 1740543996,
  200. "model": "model",
  201. "object": "chat.completion.chunk",
  202. "system_fingerprint": "",
  203. "usage": null
  204. }
  205. // omit duplicated information
  206. {"choices":[{"delta":{"content":" free to ask, and I will do my best to provide an answer based on","role":"assistant"}}]}
  207. {"choices":[{"delta":{"content":" the knowledge I have. If your question is unrelated to the provided knowledge base,","role":"assistant"}}]}
  208. {"choices":[{"delta":{"content":" I will let you know.","role":"assistant"}}]}
  209. // the last chunk
  210. {
  211. "id": "chatcmpl-3a9c3572f29311efa69751e139332ced",
  212. "choices": [
  213. {
  214. "delta": {
  215. "content": null,
  216. "role": "assistant",
  217. "function_call": null,
  218. "tool_calls": null
  219. },
  220. "finish_reason": "stop",
  221. "index": 0,
  222. "logprobs": null
  223. }
  224. ],
  225. "created": 1740543996,
  226. "model": "model",
  227. "object": "chat.completion.chunk",
  228. "system_fingerprint": "",
  229. "usage": {
  230. "prompt_tokens": 18,
  231. "completion_tokens": 225,
  232. "total_tokens": 243
  233. }
  234. }
  235. ```
  236. Non-stream:
  237. ```json
  238. {
  239. "choices":[
  240. {
  241. "finish_reason":"stop",
  242. "index":0,
  243. "logprobs":null,
  244. "message":{
  245. "content":"This is a test. If you have any specific questions or need information, feel free to ask, and I will do my best to provide an answer based on the knowledge I have. If your question is unrelated to the provided knowledge base, I will let you know.",
  246. "role":"assistant"
  247. }
  248. }
  249. ],
  250. "created":1740543499,
  251. "id":"chatcmpl-3a9c3572f29311efa69751e139332ced",
  252. "model":"model",
  253. "object":"chat.completion",
  254. "usage":{
  255. "completion_tokens":246,
  256. "completion_tokens_details":{
  257. "accepted_prediction_tokens":246,
  258. "reasoning_tokens":18,
  259. "rejected_prediction_tokens":0
  260. },
  261. "prompt_tokens":18,
  262. "total_tokens":264
  263. }
  264. }
  265. ```
  266. Failure:
  267. ```json
  268. {
  269. "code": 102,
  270. "message": "The last content of this conversation is not from user."
  271. }
  272. ```
  273. ## DATASET MANAGEMENT
  274. ---
  275. ### Create dataset
  276. **POST** `/api/v1/datasets`
  277. Creates a dataset.
  278. #### Request
  279. - Method: POST
  280. - URL: `/api/v1/datasets`
  281. - Headers:
  282. - `'content-Type: application/json'`
  283. - `'Authorization: Bearer <YOUR_API_KEY>'`
  284. - Body:
  285. - `"name"`: `string`
  286. - `"avatar"`: `string`
  287. - `"description"`: `string`
  288. - `"embedding_model"`: `string`
  289. - `"permission"`: `string`
  290. - `"chunk_method"`: `string`
  291. - `"parser_config"`: `object`
  292. ##### Request example
  293. ```bash
  294. curl --request POST \
  295. --url http://{address}/api/v1/datasets \
  296. --header 'Content-Type: application/json' \
  297. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  298. --data '{
  299. "name": "test_1"
  300. }'
  301. ```
  302. ##### Request parameters
  303. - `"name"`: (*Body parameter*), `string`, *Required*
  304. The unique name of the dataset to create. It must adhere to the following requirements:
  305. - Basic Multilingual Plane (BMP) only
  306. - Maximum 128 characters
  307. - Case-insensitive
  308. - `"avatar"`: (*Body parameter*), `string`
  309. Base64 encoding of the avatar.
  310. - Maximum 65535 characters
  311. - `"description"`: (*Body parameter*), `string`
  312. A brief description of the dataset to create.
  313. - Maximum 65535 characters
  314. - `"embedding_model"`: (*Body parameter*), `string`
  315. The name of the embedding model to use. For example: `"BAAI/bge-large-zh-v1.5@BAAI"`
  316. - Maximum 255 characters
  317. - Must follow `model_name@model_factory` format
  318. - `"permission"`: (*Body parameter*), `string`
  319. Specifies who can access the dataset to create. Available options:
  320. - `"me"`: (Default) Only you can manage the dataset.
  321. - `"team"`: All team members can manage the dataset.
  322. - `"chunk_method"`: (*Body parameter*), `enum<string>`
  323. The chunking method of the dataset to create. Available options:
  324. - `"naive"`: General (default)
  325. - `"book"`: Book
  326. - `"email"`: Email
  327. - `"laws"`: Laws
  328. - `"manual"`: Manual
  329. - `"one"`: One
  330. - `"paper"`: Paper
  331. - `"picture"`: Picture
  332. - `"presentation"`: Presentation
  333. - `"qa"`: Q&A
  334. - `"table"`: Table
  335. - `"tag"`: Tag
  336. - `"parser_config"`: (*Body parameter*), `object`
  337. The configuration settings for the dataset parser. The attributes in this JSON object vary with the selected `"chunk_method"`:
  338. - If `"chunk_method"` is `"naive"`, the `"parser_config"` object contains the following attributes:
  339. - `"auto_keywords"`: `int`
  340. - Defaults to `0`
  341. - Minimum: `0`
  342. - Maximum: `32`
  343. - `"auto_questions"`: `int`
  344. - Defaults to `0`
  345. - Minimum: `0`
  346. - Maximum: `10`
  347. - `"chunk_token_num"`: `int`
  348. - Defaults to `512`
  349. - Minimum: `1`
  350. - Maximum: `2048`
  351. - `"delimiter"`: `string`
  352. - Defaults to `"\n"`.
  353. - `"html4excel"`: `bool` Indicates whether to convert Excel documents into HTML format.
  354. - Defaults to `false`
  355. - `"layout_recognize"`: `string`
  356. - Defaults to `DeepDOC`
  357. - `"tag_kb_ids"`: `array<string>` refer to [Use tag set](https://ragflow.io/docs/dev/use_tag_sets)
  358. - Must include a list of dataset IDs, where each dataset is parsed using the ​​Tag Chunk Method
  359. - `"task_page_size"`: `int` For PDF only.
  360. - Defaults to `12`
  361. - Minimum: `1`
  362. - `"raptor"`: `object` RAPTOR-specific settings.
  363. - Defaults to: `{"use_raptor": false}`
  364. - `"graphrag"`: `object` GRAPHRAG-specific settings.
  365. - Defaults to: `{"use_graphrag": false}`
  366. - If `"chunk_method"` is `"qa"`, `"manuel"`, `"paper"`, `"book"`, `"laws"`, or `"presentation"`, the `"parser_config"` object contains the following attribute:
  367. - `"raptor"`: `object` RAPTOR-specific settings.
  368. - Defaults to: `{"use_raptor": false}`.
  369. - If `"chunk_method"` is `"table"`, `"picture"`, `"one"`, or `"email"`, `"parser_config"` is an empty JSON object.
  370. #### Response
  371. Success:
  372. ```json
  373. {
  374. "code": 0,
  375. "data": {
  376. "avatar": null,
  377. "chunk_count": 0,
  378. "chunk_method": "naive",
  379. "create_date": "Mon, 28 Apr 2025 18:40:41 GMT",
  380. "create_time": 1745836841611,
  381. "created_by": "3af81804241d11f0a6a79f24fc270c7f",
  382. "description": null,
  383. "document_count": 0,
  384. "embedding_model": "BAAI/bge-large-zh-v1.5@BAAI",
  385. "id": "3b4de7d4241d11f0a6a79f24fc270c7f",
  386. "language": "English",
  387. "name": "RAGFlow example",
  388. "pagerank": 0,
  389. "parser_config": {
  390. "chunk_token_num": 128,
  391. "delimiter": "\\n!?;。;!?",
  392. "html4excel": false,
  393. "layout_recognize": "DeepDOC",
  394. "raptor": {
  395. "use_raptor": false
  396. }
  397. },
  398. "permission": "me",
  399. "similarity_threshold": 0.2,
  400. "status": "1",
  401. "tenant_id": "3af81804241d11f0a6a79f24fc270c7f",
  402. "token_num": 0,
  403. "update_date": "Mon, 28 Apr 2025 18:40:41 GMT",
  404. "update_time": 1745836841611,
  405. "vector_similarity_weight": 0.3,
  406. },
  407. }
  408. ```
  409. Failure:
  410. ```json
  411. {
  412. "code": 101,
  413. "message": "Dataset name 'RAGFlow example' already exists"
  414. }
  415. ```
  416. ---
  417. ### Delete datasets
  418. **DELETE** `/api/v1/datasets`
  419. Deletes datasets by ID.
  420. #### Request
  421. - Method: DELETE
  422. - URL: `/api/v1/datasets`
  423. - Headers:
  424. - `'content-Type: application/json'`
  425. - `'Authorization: Bearer <YOUR_API_KEY>'`
  426. - Body:
  427. - `"ids"`: `list[string]` or `null`
  428. ##### Request example
  429. ```bash
  430. curl --request DELETE \
  431. --url http://{address}/api/v1/datasets \
  432. --header 'Content-Type: application/json' \
  433. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  434. --data '{
  435. "ids": ["d94a8dc02c9711f0930f7fbc369eab6d", "e94a8dc02c9711f0930f7fbc369eab6e"]
  436. }'
  437. ```
  438. ##### Request parameters
  439. - `"ids"`: (*Body parameter*), `list[string]` or `null`, *Required*
  440. Specifies the datasets to delete:
  441. - If `null`, all datasets will be deleted.
  442. - If an array of IDs, only the specified datasets will be deleted.
  443. - If an empty array, no datasets will be deleted.
  444. #### Response
  445. Success:
  446. ```json
  447. {
  448. "code": 0
  449. }
  450. ```
  451. Failure:
  452. ```json
  453. {
  454. "code": 102,
  455. "message": "You don't own the dataset."
  456. }
  457. ```
  458. ---
  459. ### Update dataset
  460. **PUT** `/api/v1/datasets/{dataset_id}`
  461. Updates configurations for a specified dataset.
  462. #### Request
  463. - Method: PUT
  464. - URL: `/api/v1/datasets/{dataset_id}`
  465. - Headers:
  466. - `'content-Type: application/json'`
  467. - `'Authorization: Bearer <YOUR_API_KEY>'`
  468. - Body:
  469. - `"name"`: `string`
  470. - `"avatar"`: `string`
  471. - `"description"`: `string`
  472. - `"embedding_model"`: `string`
  473. - `"permission"`: `string`
  474. - `"chunk_method"`: `string`
  475. - `"pagerank"`: `int`
  476. - `"parser_config"`: `object`
  477. ##### Request example
  478. ```bash
  479. curl --request PUT \
  480. --url http://{address}/api/v1/datasets/{dataset_id} \
  481. --header 'Content-Type: application/json' \
  482. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  483. --data '
  484. {
  485. "name": "updated_dataset"
  486. }'
  487. ```
  488. ##### Request parameters
  489. - `dataset_id`: (*Path parameter*)
  490. The ID of the dataset to update.
  491. - `"name"`: (*Body parameter*), `string`
  492. The revised name of the dataset.
  493. - Basic Multilingual Plane (BMP) only
  494. - Maximum 128 characters
  495. - Case-insensitive
  496. - `"avatar"`: (*Body parameter*), `string`
  497. The updated base64 encoding of the avatar.
  498. - Maximum 65535 characters
  499. - `"embedding_model"`: (*Body parameter*), `string`
  500. The updated embedding model name.
  501. - Ensure that `"chunk_count"` is `0` before updating `"embedding_model"`.
  502. - Maximum 255 characters
  503. - Must follow `model_name@model_factory` format
  504. - `"permission"`: (*Body parameter*), `string`
  505. The updated dataset permission. Available options:
  506. - `"me"`: (Default) Only you can manage the dataset.
  507. - `"team"`: All team members can manage the dataset.
  508. - `"pagerank"`: (*Body parameter*), `int`
  509. refer to [Set page rank](https://ragflow.io/docs/dev/set_page_rank)
  510. - Default: `0`
  511. - Minimum: `0`
  512. - Maximum: `100`
  513. - `"chunk_method"`: (*Body parameter*), `enum<string>`
  514. The chunking method for the dataset. Available options:
  515. - `"naive"`: General (default)
  516. - `"book"`: Book
  517. - `"email"`: Email
  518. - `"laws"`: Laws
  519. - `"manual"`: Manual
  520. - `"one"`: One
  521. - `"paper"`: Paper
  522. - `"picture"`: Picture
  523. - `"presentation"`: Presentation
  524. - `"qa"`: Q&A
  525. - `"table"`: Table
  526. - `"tag"`: Tag
  527. - `"parser_config"`: (*Body parameter*), `object`
  528. The configuration settings for the dataset parser. The attributes in this JSON object vary with the selected `"chunk_method"`:
  529. - If `"chunk_method"` is `"naive"`, the `"parser_config"` object contains the following attributes:
  530. - `"auto_keywords"`: `int`
  531. - Defaults to `0`
  532. - Minimum: `0`
  533. - Maximum: `32`
  534. - `"auto_questions"`: `int`
  535. - Defaults to `0`
  536. - Minimum: `0`
  537. - Maximum: `10`
  538. - `"chunk_token_num"`: `int`
  539. - Defaults to `512`
  540. - Minimum: `1`
  541. - Maximum: `2048`
  542. - `"delimiter"`: `string`
  543. - Defaults to `"\n"`.
  544. - `"html4excel"`: `bool` Indicates whether to convert Excel documents into HTML format.
  545. - Defaults to `false`
  546. - `"layout_recognize"`: `string`
  547. - Defaults to `DeepDOC`
  548. - `"tag_kb_ids"`: `array<string>` refer to [Use tag set](https://ragflow.io/docs/dev/use_tag_sets)
  549. - Must include a list of dataset IDs, where each dataset is parsed using the ​​Tag Chunk Method
  550. - `"task_page_size"`: `int` For PDF only.
  551. - Defaults to `12`
  552. - Minimum: `1`
  553. - `"raptor"`: `object` RAPTOR-specific settings.
  554. - Defaults to: `{"use_raptor": false}`
  555. - `"graphrag"`: `object` GRAPHRAG-specific settings.
  556. - Defaults to: `{"use_graphrag": false}`
  557. - If `"chunk_method"` is `"qa"`, `"manuel"`, `"paper"`, `"book"`, `"laws"`, or `"presentation"`, the `"parser_config"` object contains the following attribute:
  558. - `"raptor"`: `object` RAPTOR-specific settings.
  559. - Defaults to: `{"use_raptor": false}`.
  560. - If `"chunk_method"` is `"table"`, `"picture"`, `"one"`, or `"email"`, `"parser_config"` is an empty JSON object.
  561. #### Response
  562. Success:
  563. ```json
  564. {
  565. "code": 0
  566. }
  567. ```
  568. Failure:
  569. ```json
  570. {
  571. "code": 102,
  572. "message": "Can't change tenant_id."
  573. }
  574. ```
  575. ---
  576. ### List datasets
  577. **GET** `/api/v1/datasets?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
  578. Lists datasets.
  579. #### Request
  580. - Method: GET
  581. - URL: `/api/v1/datasets?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
  582. - Headers:
  583. - `'Authorization: Bearer <YOUR_API_KEY>'`
  584. ##### Request example
  585. ```bash
  586. curl --request GET \
  587. --url http://{address}/api/v1/datasets?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id} \
  588. --header 'Authorization: Bearer <YOUR_API_KEY>'
  589. ```
  590. ##### Request parameters
  591. - `page`: (*Filter parameter*)
  592. Specifies the page on which the datasets will be displayed. Defaults to `1`.
  593. - `page_size`: (*Filter parameter*)
  594. The number of datasets on each page. Defaults to `30`.
  595. - `orderby`: (*Filter parameter*)
  596. The field by which datasets should be sorted. Available options:
  597. - `create_time` (default)
  598. - `update_time`
  599. - `desc`: (*Filter parameter*)
  600. Indicates whether the retrieved datasets should be sorted in descending order. Defaults to `true`.
  601. - `name`: (*Filter parameter*)
  602. The name of the dataset to retrieve.
  603. - `id`: (*Filter parameter*)
  604. The ID of the dataset to retrieve.
  605. #### Response
  606. Success:
  607. ```json
  608. {
  609. "code": 0,
  610. "data": [
  611. {
  612. "avatar": "",
  613. "chunk_count": 59,
  614. "create_date": "Sat, 14 Sep 2024 01:12:37 GMT",
  615. "create_time": 1726276357324,
  616. "created_by": "69736c5e723611efb51b0242ac120007",
  617. "description": null,
  618. "document_count": 1,
  619. "embedding_model": "BAAI/bge-large-zh-v1.5",
  620. "id": "6e211ee0723611efa10a0242ac120007",
  621. "language": "English",
  622. "name": "mysql",
  623. "chunk_method": "naive",
  624. "parser_config": {
  625. "chunk_token_num": 8192,
  626. "delimiter": "\\n",
  627. "entity_types": [
  628. "organization",
  629. "person",
  630. "location",
  631. "event",
  632. "time"
  633. ]
  634. },
  635. "permission": "me",
  636. "similarity_threshold": 0.2,
  637. "status": "1",
  638. "tenant_id": "69736c5e723611efb51b0242ac120007",
  639. "token_num": 12744,
  640. "update_date": "Thu, 10 Oct 2024 04:07:23 GMT",
  641. "update_time": 1728533243536,
  642. "vector_similarity_weight": 0.3
  643. }
  644. ]
  645. }
  646. ```
  647. Failure:
  648. ```json
  649. {
  650. "code": 102,
  651. "message": "The dataset doesn't exist"
  652. }
  653. ```
  654. ---
  655. ## Get dataset's knowledge graph
  656. **GET** `/api/v1/datasets/{dataset_id}/knowledge_graph`
  657. Retrieves the knowledge graph of a specified dataset.
  658. #### Request
  659. - Method: GET
  660. - URL: `/api/v1/datasets/{dataset_id}/knowledge_graph`
  661. - Headers:
  662. - `'Authorization: Bearer <YOUR_API_KEY>'`
  663. ##### Request example
  664. ```bash
  665. curl --request GET \
  666. --url http://{address}/api/v1/datasets/{dataset_id}/knowledge_graph \
  667. --header 'Authorization: Bearer <YOUR_API_KEY>'
  668. ```
  669. ##### Request parameters
  670. - `dataset_id`: (*Path parameter*)
  671. The ID of the target dataset.
  672. #### Response
  673. Success:
  674. ```json
  675. {
  676. "code": 0,
  677. "data": {
  678. "graph": {
  679. "directed": false,
  680. "edges": [
  681. {
  682. "description": "The notice is a document issued to convey risk warnings and operational alerts.<SEP>The notice is a specific instance of a notification document issued under the risk warning framework.",
  683. "keywords": ["9", "8"],
  684. "source": "notice",
  685. "source_id": ["8a46cdfe4b5c11f0a5281a58e595aa1c"],
  686. "src_id": "xxx",
  687. "target": "xxx",
  688. "tgt_id": "xxx",
  689. "weight": 17.0
  690. }
  691. ],
  692. "graph": {
  693. "source_id": ["8a46cdfe4b5c11f0a5281a58e595aa1c", "8a7eb6424b5c11f0a5281a58e595aa1c"]
  694. },
  695. "multigraph": false,
  696. "nodes": [
  697. {
  698. "description": "xxx",
  699. "entity_name": "xxx",
  700. "entity_type": "ORGANIZATION",
  701. "id": "xxx",
  702. "pagerank": 0.10804906590624092,
  703. "rank": 3,
  704. "source_id": ["8a7eb6424b5c11f0a5281a58e595aa1c"]
  705. }
  706. ]
  707. },
  708. "mind_map": {}
  709. }
  710. }
  711. ```
  712. Failure:
  713. ```json
  714. {
  715. "code": 102,
  716. "message": "The dataset doesn't exist"
  717. }
  718. ```
  719. ---
  720. ## Delete dataset's knowledge graph
  721. **DELETE** `/api/v1/datasets/{dataset_id}/knowledge_graph`
  722. Removes the knowledge graph of a specified dataset.
  723. #### Request
  724. - Method: DELETE
  725. - URL: `/api/v1/datasets/{dataset_id}/knowledge_graph`
  726. - Headers:
  727. - `'Authorization: Bearer <YOUR_API_KEY>'`
  728. ##### Request example
  729. ```bash
  730. curl --request DELETE \
  731. --url http://{address}/api/v1/datasets/{dataset_id}/knowledge_graph \
  732. --header 'Authorization: Bearer <YOUR_API_KEY>'
  733. ```
  734. ##### Request parameters
  735. - `dataset_id`: (*Path parameter*)
  736. The ID of the target dataset.
  737. #### Response
  738. Success:
  739. ```json
  740. {
  741. "code": 0,
  742. "data": true
  743. }
  744. ```
  745. Failure:
  746. ```json
  747. {
  748. "code": 102,
  749. "message": "The dataset doesn't exist"
  750. }
  751. ```
  752. ---
  753. ## FILE MANAGEMENT WITHIN DATASET
  754. ---
  755. ### Upload documents
  756. **POST** `/api/v1/datasets/{dataset_id}/documents`
  757. Uploads documents to a specified dataset.
  758. #### Request
  759. - Method: POST
  760. - URL: `/api/v1/datasets/{dataset_id}/documents`
  761. - Headers:
  762. - `'Content-Type: multipart/form-data'`
  763. - `'Authorization: Bearer <YOUR_API_KEY>'`
  764. - Form:
  765. - `'file=@{FILE_PATH}'`
  766. ##### Request example
  767. ```bash
  768. curl --request POST \
  769. --url http://{address}/api/v1/datasets/{dataset_id}/documents \
  770. --header 'Content-Type: multipart/form-data' \
  771. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  772. --form 'file=@./test1.txt' \
  773. --form 'file=@./test2.pdf'
  774. ```
  775. ##### Request parameters
  776. - `dataset_id`: (*Path parameter*)
  777. The ID of the dataset to which the documents will be uploaded.
  778. - `'file'`: (*Body parameter*)
  779. A document to upload.
  780. #### Response
  781. Success:
  782. ```json
  783. {
  784. "code": 0,
  785. "data": [
  786. {
  787. "chunk_method": "naive",
  788. "created_by": "69736c5e723611efb51b0242ac120007",
  789. "dataset_id": "527fa74891e811ef9c650242ac120006",
  790. "id": "b330ec2e91ec11efbc510242ac120004",
  791. "location": "1.txt",
  792. "name": "1.txt",
  793. "parser_config": {
  794. "chunk_token_num": 128,
  795. "delimiter": "\\n",
  796. "html4excel": false,
  797. "layout_recognize": true,
  798. "raptor": {
  799. "use_raptor": false
  800. }
  801. },
  802. "run": "UNSTART",
  803. "size": 17966,
  804. "thumbnail": "",
  805. "type": "doc"
  806. }
  807. ]
  808. }
  809. ```
  810. Failure:
  811. ```json
  812. {
  813. "code": 101,
  814. "message": "No file part!"
  815. }
  816. ```
  817. ---
  818. ### Update document
  819. **PUT** `/api/v1/datasets/{dataset_id}/documents/{document_id}`
  820. Updates configurations for a specified document.
  821. #### Request
  822. - Method: PUT
  823. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}`
  824. - Headers:
  825. - `'content-Type: application/json'`
  826. - `'Authorization: Bearer <YOUR_API_KEY>'`
  827. - Body:
  828. - `"name"`:`string`
  829. - `"meta_fields"`:`object`
  830. - `"chunk_method"`:`string`
  831. - `"parser_config"`:`object`
  832. ##### Request example
  833. ```bash
  834. curl --request PUT \
  835. --url http://{address}/api/v1/datasets/{dataset_id}/info/{document_id} \
  836. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  837. --header 'Content-Type: application/json' \
  838. --data '
  839. {
  840. "name": "manual.txt",
  841. "chunk_method": "manual",
  842. "parser_config": {"chunk_token_num": 128}
  843. }'
  844. ```
  845. ##### Request parameters
  846. - `dataset_id`: (*Path parameter*)
  847. The ID of the associated dataset.
  848. - `document_id`: (*Path parameter*)
  849. The ID of the document to update.
  850. - `"name"`: (*Body parameter*), `string`
  851. - `"meta_fields"`: (*Body parameter*), `dict[str, Any]` The meta fields of the document.
  852. - `"chunk_method"`: (*Body parameter*), `string`
  853. The parsing method to apply to the document:
  854. - `"naive"`: General
  855. - `"manual`: Manual
  856. - `"qa"`: Q&A
  857. - `"table"`: Table
  858. - `"paper"`: Paper
  859. - `"book"`: Book
  860. - `"laws"`: Laws
  861. - `"presentation"`: Presentation
  862. - `"picture"`: Picture
  863. - `"one"`: One
  864. - `"email"`: Email
  865. - `"parser_config"`: (*Body parameter*), `object`
  866. The configuration settings for the dataset parser. The attributes in this JSON object vary with the selected `"chunk_method"`:
  867. - If `"chunk_method"` is `"naive"`, the `"parser_config"` object contains the following attributes:
  868. - `"chunk_token_num"`: Defaults to `256`.
  869. - `"layout_recognize"`: Defaults to `true`.
  870. - `"html4excel"`: Indicates whether to convert Excel documents into HTML format. Defaults to `false`.
  871. - `"delimiter"`: Defaults to `"\n"`.
  872. - `"task_page_size"`: Defaults to `12`. For PDF only.
  873. - `"raptor"`: RAPTOR-specific settings. Defaults to: `{"use_raptor": false}`.
  874. - If `"chunk_method"` is `"qa"`, `"manuel"`, `"paper"`, `"book"`, `"laws"`, or `"presentation"`, the `"parser_config"` object contains the following attribute:
  875. - `"raptor"`: RAPTOR-specific settings. Defaults to: `{"use_raptor": false}`.
  876. - If `"chunk_method"` is `"table"`, `"picture"`, `"one"`, or `"email"`, `"parser_config"` is an empty JSON object.
  877. #### Response
  878. Success:
  879. ```json
  880. {
  881. "code": 0
  882. }
  883. ```
  884. Failure:
  885. ```json
  886. {
  887. "code": 102,
  888. "message": "The dataset does not have the document."
  889. }
  890. ```
  891. ---
  892. ### Download document
  893. **GET** `/api/v1/datasets/{dataset_id}/documents/{document_id}`
  894. Downloads a document from a specified dataset.
  895. #### Request
  896. - Method: GET
  897. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}`
  898. - Headers:
  899. - `'Authorization: Bearer <YOUR_API_KEY>'`
  900. - Output:
  901. - `'{PATH_TO_THE_FILE}'`
  902. ##### Request example
  903. ```bash
  904. curl --request GET \
  905. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id} \
  906. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  907. --output ./ragflow.txt
  908. ```
  909. ##### Request parameters
  910. - `dataset_id`: (*Path parameter*)
  911. The associated dataset ID.
  912. - `documents_id`: (*Path parameter*)
  913. The ID of the document to download.
  914. #### Response
  915. Success:
  916. ```json
  917. This is a test to verify the file download feature.
  918. ```
  919. Failure:
  920. ```json
  921. {
  922. "code": 102,
  923. "message": "You do not own the dataset 7898da028a0511efbf750242ac1220005."
  924. }
  925. ```
  926. ---
  927. ### List documents
  928. **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}&create_time_from={timestamp}&create_time_to={timestamp}`
  929. Lists documents in a specified dataset.
  930. #### Request
  931. - Method: GET
  932. - 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}&create_time_from={timestamp}&create_time_to={timestamp}`
  933. - Headers:
  934. - `'content-Type: application/json'`
  935. - `'Authorization: Bearer <YOUR_API_KEY>'`
  936. ##### Request example
  937. ```bash
  938. curl --request GET \
  939. --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}&create_time_from={timestamp}&create_time_to={timestamp} \
  940. --header 'Authorization: Bearer <YOUR_API_KEY>'
  941. ```
  942. ##### Request parameters
  943. - `dataset_id`: (*Path parameter*)
  944. The associated dataset ID.
  945. - `keywords`: (*Filter parameter*), `string`
  946. The keywords used to match document titles.
  947. - `page`: (*Filter parameter*), `integer`
  948. Specifies the page on which the documents will be displayed. Defaults to `1`.
  949. - `page_size`: (*Filter parameter*), `integer`
  950. The maximum number of documents on each page. Defaults to `30`.
  951. - `orderby`: (*Filter parameter*), `string`
  952. The field by which documents should be sorted. Available options:
  953. - `create_time` (default)
  954. - `update_time`
  955. - `desc`: (*Filter parameter*), `boolean`
  956. Indicates whether the retrieved documents should be sorted in descending order. Defaults to `true`.
  957. - `id`: (*Filter parameter*), `string`
  958. The ID of the document to retrieve.
  959. - `create_time_from`: (*Filter parameter*), `integer`
  960. Unix timestamp for filtering documents created after this time. 0 means no filter. Defaults to `0`.
  961. - `create_time_to`: (*Filter parameter*), `integer`
  962. Unix timestamp for filtering documents created before this time. 0 means no filter. Defaults to `0`.
  963. #### Response
  964. Success:
  965. ```json
  966. {
  967. "code": 0,
  968. "data": {
  969. "docs": [
  970. {
  971. "chunk_count": 0,
  972. "create_date": "Mon, 14 Oct 2024 09:11:01 GMT",
  973. "create_time": 1728897061948,
  974. "created_by": "69736c5e723611efb51b0242ac120007",
  975. "id": "3bcfbf8a8a0c11ef8aba0242ac120006",
  976. "knowledgebase_id": "7898da028a0511efbf750242ac120005",
  977. "location": "Test_2.txt",
  978. "name": "Test_2.txt",
  979. "parser_config": {
  980. "chunk_token_count": 128,
  981. "delimiter": "\n",
  982. "layout_recognize": true,
  983. "task_page_size": 12
  984. },
  985. "chunk_method": "naive",
  986. "process_begin_at": null,
  987. "process_duration": 0.0,
  988. "progress": 0.0,
  989. "progress_msg": "",
  990. "run": "0",
  991. "size": 7,
  992. "source_type": "local",
  993. "status": "1",
  994. "thumbnail": null,
  995. "token_count": 0,
  996. "type": "doc",
  997. "update_date": "Mon, 14 Oct 2024 09:11:01 GMT",
  998. "update_time": 1728897061948
  999. }
  1000. ],
  1001. "total": 1
  1002. }
  1003. }
  1004. ```
  1005. Failure:
  1006. ```json
  1007. {
  1008. "code": 102,
  1009. "message": "You don't own the dataset 7898da028a0511efbf750242ac1220005. "
  1010. }
  1011. ```
  1012. ---
  1013. ### Delete documents
  1014. **DELETE** `/api/v1/datasets/{dataset_id}/documents`
  1015. Deletes documents by ID.
  1016. #### Request
  1017. - Method: DELETE
  1018. - URL: `/api/v1/datasets/{dataset_id}/documents`
  1019. - Headers:
  1020. - `'Content-Type: application/json'`
  1021. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1022. - Body:
  1023. - `"ids"`: `list[string]`
  1024. ##### Request example
  1025. ```bash
  1026. curl --request DELETE \
  1027. --url http://{address}/api/v1/datasets/{dataset_id}/documents \
  1028. --header 'Content-Type: application/json' \
  1029. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1030. --data '
  1031. {
  1032. "ids": ["id_1","id_2"]
  1033. }'
  1034. ```
  1035. ##### Request parameters
  1036. - `dataset_id`: (*Path parameter*)
  1037. The associated dataset ID.
  1038. - `"ids"`: (*Body parameter*), `list[string]`
  1039. The IDs of the documents to delete. If it is not specified, all documents in the specified dataset will be deleted.
  1040. #### Response
  1041. Success:
  1042. ```json
  1043. {
  1044. "code": 0
  1045. }.
  1046. ```
  1047. Failure:
  1048. ```json
  1049. {
  1050. "code": 102,
  1051. "message": "You do not own the dataset 7898da028a0511efbf750242ac1220005."
  1052. }
  1053. ```
  1054. ---
  1055. ### Parse documents
  1056. **POST** `/api/v1/datasets/{dataset_id}/chunks`
  1057. Parses documents in a specified dataset.
  1058. #### Request
  1059. - Method: POST
  1060. - URL: `/api/v1/datasets/{dataset_id}/chunks`
  1061. - Headers:
  1062. - `'content-Type: application/json'`
  1063. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1064. - Body:
  1065. - `"document_ids"`: `list[string]`
  1066. ##### Request example
  1067. ```bash
  1068. curl --request POST \
  1069. --url http://{address}/api/v1/datasets/{dataset_id}/chunks \
  1070. --header 'Content-Type: application/json' \
  1071. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1072. --data '
  1073. {
  1074. "document_ids": ["97a5f1c2759811efaa500242ac120004","97ad64b6759811ef9fc30242ac120004"]
  1075. }'
  1076. ```
  1077. ##### Request parameters
  1078. - `dataset_id`: (*Path parameter*)
  1079. The dataset ID.
  1080. - `"document_ids"`: (*Body parameter*), `list[string]`, *Required*
  1081. The IDs of the documents to parse.
  1082. #### Response
  1083. Success:
  1084. ```json
  1085. {
  1086. "code": 0
  1087. }
  1088. ```
  1089. Failure:
  1090. ```json
  1091. {
  1092. "code": 102,
  1093. "message": "`document_ids` is required"
  1094. }
  1095. ```
  1096. ---
  1097. ### Stop parsing documents
  1098. **DELETE** `/api/v1/datasets/{dataset_id}/chunks`
  1099. Stops parsing specified documents.
  1100. #### Request
  1101. - Method: DELETE
  1102. - URL: `/api/v1/datasets/{dataset_id}/chunks`
  1103. - Headers:
  1104. - `'content-Type: application/json'`
  1105. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1106. - Body:
  1107. - `"document_ids"`: `list[string]`
  1108. ##### Request example
  1109. ```bash
  1110. curl --request DELETE \
  1111. --url http://{address}/api/v1/datasets/{dataset_id}/chunks \
  1112. --header 'Content-Type: application/json' \
  1113. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1114. --data '
  1115. {
  1116. "document_ids": ["97a5f1c2759811efaa500242ac120004","97ad64b6759811ef9fc30242ac120004"]
  1117. }'
  1118. ```
  1119. ##### Request parameters
  1120. - `dataset_id`: (*Path parameter*)
  1121. The associated dataset ID.
  1122. - `"document_ids"`: (*Body parameter*), `list[string]`, *Required*
  1123. The IDs of the documents for which the parsing should be stopped.
  1124. #### Response
  1125. Success:
  1126. ```json
  1127. {
  1128. "code": 0
  1129. }
  1130. ```
  1131. Failure:
  1132. ```json
  1133. {
  1134. "code": 102,
  1135. "message": "`document_ids` is required"
  1136. }
  1137. ```
  1138. ---
  1139. ## CHUNK MANAGEMENT WITHIN DATASET
  1140. ---
  1141. ### Add chunk
  1142. **POST** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
  1143. Adds a chunk to a specified document in a specified dataset.
  1144. #### Request
  1145. - Method: POST
  1146. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
  1147. - Headers:
  1148. - `'content-Type: application/json'`
  1149. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1150. - Body:
  1151. - `"content"`: `string`
  1152. - `"important_keywords"`: `list[string]`
  1153. ##### Request example
  1154. ```bash
  1155. curl --request POST \
  1156. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks \
  1157. --header 'Content-Type: application/json' \
  1158. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1159. --data '
  1160. {
  1161. "content": "<CHUNK_CONTENT_HERE>"
  1162. }'
  1163. ```
  1164. ##### Request parameters
  1165. - `dataset_id`: (*Path parameter*)
  1166. The associated dataset ID.
  1167. - `document_ids`: (*Path parameter*)
  1168. The associated document ID.
  1169. - `"content"`: (*Body parameter*), `string`, *Required*
  1170. The text content of the chunk.
  1171. - `"important_keywords`(*Body parameter*), `list[string]`
  1172. The key terms or phrases to tag with the chunk.
  1173. - `"questions"`(*Body parameter*), `list[string]`
  1174. If there is a given question, the embedded chunks will be based on them
  1175. #### Response
  1176. Success:
  1177. ```json
  1178. {
  1179. "code": 0,
  1180. "data": {
  1181. "chunk": {
  1182. "content": "who are you",
  1183. "create_time": "2024-12-30 16:59:55",
  1184. "create_timestamp": 1735549195.969164,
  1185. "dataset_id": "72f36e1ebdf411efb7250242ac120006",
  1186. "document_id": "61d68474be0111ef98dd0242ac120006",
  1187. "id": "12ccdc56e59837e5",
  1188. "important_keywords": [],
  1189. "questions": []
  1190. }
  1191. }
  1192. }
  1193. ```
  1194. Failure:
  1195. ```json
  1196. {
  1197. "code": 102,
  1198. "message": "`content` is required"
  1199. }
  1200. ```
  1201. ---
  1202. ### List chunks
  1203. **GET** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks?keywords={keywords}&page={page}&page_size={page_size}&id={id}`
  1204. Lists chunks in a specified document.
  1205. #### Request
  1206. - Method: GET
  1207. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks?keywords={keywords}&page={page}&page_size={page_size}&id={chunk_id}`
  1208. - Headers:
  1209. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1210. ##### Request example
  1211. ```bash
  1212. curl --request GET \
  1213. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks?keywords={keywords}&page={page}&page_size={page_size}&id={chunk_id} \
  1214. --header 'Authorization: Bearer <YOUR_API_KEY>'
  1215. ```
  1216. ##### Request parameters
  1217. - `dataset_id`: (*Path parameter*)
  1218. The associated dataset ID.
  1219. - `document_id`: (*Path parameter*)
  1220. The associated document ID.
  1221. - `keywords`(*Filter parameter*), `string`
  1222. The keywords used to match chunk content.
  1223. - `page`(*Filter parameter*), `integer`
  1224. Specifies the page on which the chunks will be displayed. Defaults to `1`.
  1225. - `page_size`(*Filter parameter*), `integer`
  1226. The maximum number of chunks on each page. Defaults to `1024`.
  1227. - `id`(*Filter parameter*), `string`
  1228. The ID of the chunk to retrieve.
  1229. #### Response
  1230. Success:
  1231. ```json
  1232. {
  1233. "code": 0,
  1234. "data": {
  1235. "chunks": [
  1236. {
  1237. "available": true,
  1238. "content": "This is a test content.",
  1239. "docnm_kwd": "1.txt",
  1240. "document_id": "b330ec2e91ec11efbc510242ac120004",
  1241. "id": "b48c170e90f70af998485c1065490726",
  1242. "image_id": "",
  1243. "important_keywords": "",
  1244. "positions": [
  1245. ""
  1246. ]
  1247. }
  1248. ],
  1249. "doc": {
  1250. "chunk_count": 1,
  1251. "chunk_method": "naive",
  1252. "create_date": "Thu, 24 Oct 2024 09:45:27 GMT",
  1253. "create_time": 1729763127646,
  1254. "created_by": "69736c5e723611efb51b0242ac120007",
  1255. "dataset_id": "527fa74891e811ef9c650242ac120006",
  1256. "id": "b330ec2e91ec11efbc510242ac120004",
  1257. "location": "1.txt",
  1258. "name": "1.txt",
  1259. "parser_config": {
  1260. "chunk_token_num": 128,
  1261. "delimiter": "\\n",
  1262. "html4excel": false,
  1263. "layout_recognize": true,
  1264. "raptor": {
  1265. "use_raptor": false
  1266. }
  1267. },
  1268. "process_begin_at": "Thu, 24 Oct 2024 09:56:44 GMT",
  1269. "process_duration": 0.54213,
  1270. "progress": 0.0,
  1271. "progress_msg": "Task dispatched...",
  1272. "run": "2",
  1273. "size": 17966,
  1274. "source_type": "local",
  1275. "status": "1",
  1276. "thumbnail": "",
  1277. "token_count": 8,
  1278. "type": "doc",
  1279. "update_date": "Thu, 24 Oct 2024 11:03:15 GMT",
  1280. "update_time": 1729767795721
  1281. },
  1282. "total": 1
  1283. }
  1284. }
  1285. ```
  1286. Failure:
  1287. ```json
  1288. {
  1289. "code": 102,
  1290. "message": "You don't own the document 5c5999ec7be811ef9cab0242ac12000e5."
  1291. }
  1292. ```
  1293. ---
  1294. ### Delete chunks
  1295. **DELETE** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
  1296. Deletes chunks by ID.
  1297. #### Request
  1298. - Method: DELETE
  1299. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
  1300. - Headers:
  1301. - `'content-Type: application/json'`
  1302. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1303. - Body:
  1304. - `"chunk_ids"`: `list[string]`
  1305. ##### Request example
  1306. ```bash
  1307. curl --request DELETE \
  1308. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks \
  1309. --header 'Content-Type: application/json' \
  1310. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1311. --data '
  1312. {
  1313. "chunk_ids": ["test_1", "test_2"]
  1314. }'
  1315. ```
  1316. ##### Request parameters
  1317. - `dataset_id`: (*Path parameter*)
  1318. The associated dataset ID.
  1319. - `document_ids`: (*Path parameter*)
  1320. The associated document ID.
  1321. - `"chunk_ids"`: (*Body parameter*), `list[string]`
  1322. The IDs of the chunks to delete. If it is not specified, all chunks of the specified document will be deleted.
  1323. #### Response
  1324. Success:
  1325. ```json
  1326. {
  1327. "code": 0
  1328. }
  1329. ```
  1330. Failure:
  1331. ```json
  1332. {
  1333. "code": 102,
  1334. "message": "`chunk_ids` is required"
  1335. }
  1336. ```
  1337. ---
  1338. ### Update chunk
  1339. **PUT** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks/{chunk_id}`
  1340. Updates content or configurations for a specified chunk.
  1341. #### Request
  1342. - Method: PUT
  1343. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks/{chunk_id}`
  1344. - Headers:
  1345. - `'content-Type: application/json'`
  1346. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1347. - Body:
  1348. - `"content"`: `string`
  1349. - `"important_keywords"`: `list[string]`
  1350. - `"available"`: `boolean`
  1351. ##### Request example
  1352. ```bash
  1353. curl --request PUT \
  1354. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks/{chunk_id} \
  1355. --header 'Content-Type: application/json' \
  1356. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1357. --data '
  1358. {
  1359. "content": "ragflow123",
  1360. "important_keywords": []
  1361. }'
  1362. ```
  1363. ##### Request parameters
  1364. - `dataset_id`: (*Path parameter*)
  1365. The associated dataset ID.
  1366. - `document_ids`: (*Path parameter*)
  1367. The associated document ID.
  1368. - `chunk_id`: (*Path parameter*)
  1369. The ID of the chunk to update.
  1370. - `"content"`: (*Body parameter*), `string`
  1371. The text content of the chunk.
  1372. - `"important_keywords"`: (*Body parameter*), `list[string]`
  1373. A list of key terms or phrases to tag with the chunk.
  1374. - `"available"`: (*Body parameter*) `boolean`
  1375. The chunk's availability status in the dataset. Value options:
  1376. - `true`: Available (default)
  1377. - `false`: Unavailable
  1378. #### Response
  1379. Success:
  1380. ```json
  1381. {
  1382. "code": 0
  1383. }
  1384. ```
  1385. Failure:
  1386. ```json
  1387. {
  1388. "code": 102,
  1389. "message": "Can't find this chunk 29a2d9987e16ba331fb4d7d30d99b71d2"
  1390. }
  1391. ```
  1392. ---
  1393. ### Retrieve chunks
  1394. **POST** `/api/v1/retrieval`
  1395. Retrieves chunks from specified datasets.
  1396. #### Request
  1397. - Method: POST
  1398. - URL: `/api/v1/retrieval`
  1399. - Headers:
  1400. - `'content-Type: application/json'`
  1401. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1402. - Body:
  1403. - `"question"`: `string`
  1404. - `"dataset_ids"`: `list[string]`
  1405. - `"document_ids"`: `list[string]`
  1406. - `"page"`: `integer`
  1407. - `"page_size"`: `integer`
  1408. - `"similarity_threshold"`: `float`
  1409. - `"vector_similarity_weight"`: `float`
  1410. - `"top_k"`: `integer`
  1411. - `"rerank_id"`: `string`
  1412. - `"keyword"`: `boolean`
  1413. - `"highlight"`: `boolean`
  1414. - `"cross_languages"`: `list[string]`
  1415. ##### Request example
  1416. ```bash
  1417. curl --request POST \
  1418. --url http://{address}/api/v1/retrieval \
  1419. --header 'Content-Type: application/json' \
  1420. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1421. --data '
  1422. {
  1423. "question": "What is advantage of ragflow?",
  1424. "dataset_ids": ["b2a62730759d11ef987d0242ac120004"],
  1425. "document_ids": ["77df9ef4759a11ef8bdd0242ac120004"]
  1426. }'
  1427. ```
  1428. ##### Request parameter
  1429. - `"question"`: (*Body parameter*), `string`, *Required*
  1430. The user query or query keywords.
  1431. - `"dataset_ids"`: (*Body parameter*) `list[string]`
  1432. The IDs of the datasets to search. If you do not set this argument, ensure that you set `"document_ids"`.
  1433. - `"document_ids"`: (*Body parameter*), `list[string]`
  1434. 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"`.
  1435. - `"page"`: (*Body parameter*), `integer`
  1436. Specifies the page on which the chunks will be displayed. Defaults to `1`.
  1437. - `"page_size"`: (*Body parameter*)
  1438. The maximum number of chunks on each page. Defaults to `30`.
  1439. - `"similarity_threshold"`: (*Body parameter*)
  1440. The minimum similarity score. Defaults to `0.2`.
  1441. - `"vector_similarity_weight"`: (*Body parameter*), `float`
  1442. 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.
  1443. - `"top_k"`: (*Body parameter*), `integer`
  1444. The number of chunks engaged in vector cosine computation. Defaults to `1024`.
  1445. - `"rerank_id"`: (*Body parameter*), `integer`
  1446. The ID of the rerank model.
  1447. - `"keyword"`: (*Body parameter*), `boolean`
  1448. Indicates whether to enable keyword-based matching:
  1449. - `true`: Enable keyword-based matching.
  1450. - `false`: Disable keyword-based matching (default).
  1451. - `"highlight"`: (*Body parameter*), `boolean`
  1452. Specifies whether to enable highlighting of matched terms in the results:
  1453. - `true`: Enable highlighting of matched terms.
  1454. - `false`: Disable highlighting of matched terms (default).
  1455. - `"cross_languages"`: (*Body parameter*) `list[string]`
  1456. The languages that should be translated into, in order to achieve keywords retrievals in different languages.
  1457. #### Response
  1458. Success:
  1459. ```json
  1460. {
  1461. "code": 0,
  1462. "data": {
  1463. "chunks": [
  1464. {
  1465. "content": "ragflow content",
  1466. "content_ltks": "ragflow content",
  1467. "document_id": "5c5999ec7be811ef9cab0242ac120005",
  1468. "document_keyword": "1.txt",
  1469. "highlight": "<em>ragflow</em> content",
  1470. "id": "d78435d142bd5cf6704da62c778795c5",
  1471. "image_id": "",
  1472. "important_keywords": [
  1473. ""
  1474. ],
  1475. "kb_id": "c7ee74067a2c11efb21c0242ac120006",
  1476. "positions": [
  1477. ""
  1478. ],
  1479. "similarity": 0.9669436601210759,
  1480. "term_similarity": 1.0,
  1481. "vector_similarity": 0.8898122004035864
  1482. }
  1483. ],
  1484. "doc_aggs": [
  1485. {
  1486. "count": 1,
  1487. "doc_id": "5c5999ec7be811ef9cab0242ac120005",
  1488. "doc_name": "1.txt"
  1489. }
  1490. ],
  1491. "total": 1
  1492. }
  1493. }
  1494. ```
  1495. Failure:
  1496. ```json
  1497. {
  1498. "code": 102,
  1499. "message": "`datasets` is required."
  1500. }
  1501. ```
  1502. ---
  1503. ## CHAT ASSISTANT MANAGEMENT
  1504. ---
  1505. ### Create chat assistant
  1506. **POST** `/api/v1/chats`
  1507. Creates a chat assistant.
  1508. #### Request
  1509. - Method: POST
  1510. - URL: `/api/v1/chats`
  1511. - Headers:
  1512. - `'content-Type: application/json'`
  1513. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1514. - Body:
  1515. - `"name"`: `string`
  1516. - `"avatar"`: `string`
  1517. - `"dataset_ids"`: `list[string]`
  1518. - `"llm"`: `object`
  1519. - `"prompt"`: `object`
  1520. ##### Request example
  1521. ```shell
  1522. curl --request POST \
  1523. --url http://{address}/api/v1/chats \
  1524. --header 'Content-Type: application/json' \
  1525. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1526. --data '{
  1527. "dataset_ids": ["0b2cbc8c877f11ef89070242ac120005"],
  1528. "name":"new_chat_1"
  1529. }'
  1530. ```
  1531. ##### Request parameters
  1532. - `"name"`: (*Body parameter*), `string`, *Required*
  1533. The name of the chat assistant.
  1534. - `"avatar"`: (*Body parameter*), `string`
  1535. Base64 encoding of the avatar.
  1536. - `"dataset_ids"`: (*Body parameter*), `list[string]`
  1537. The IDs of the associated datasets.
  1538. - `"llm"`: (*Body parameter*), `object`
  1539. 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:
  1540. - `"model_name"`, `string`
  1541. The chat model name. If not set, the user's default chat model will be used.
  1542. - `"temperature"`: `float`
  1543. Controls the randomness of the model's predictions. A lower temperature results in more conservative responses, while a higher temperature yields more creative and diverse responses. Defaults to `0.1`.
  1544. - `"top_p"`: `float`
  1545. 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`
  1546. - `"presence_penalty"`: `float`
  1547. This discourages the model from repeating the same information by penalizing words that have already appeared in the conversation. Defaults to `0.4`.
  1548. - `"frequency penalty"`: `float`
  1549. Similar to the presence penalty, this reduces the model’s tendency to repeat the same words frequently. Defaults to `0.7`.
  1550. - `"prompt"`: (*Body parameter*), `object`
  1551. 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:
  1552. - `"similarity_threshold"`: `float` RAGFlow employs either a combination of weighted keyword similarity and weighted vector cosine similarity, or a combination of weighted keyword similarity and weighted reranking score 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`.
  1553. - `"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`.
  1554. - `"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 `6`.
  1555. - `"variables"`: `object[]` This argument lists the variables to use in the 'System' field of **Chat Configurations**. Note that:
  1556. - `"knowledge"` is a reserved variable, which represents the retrieved chunks.
  1557. - All the variables in 'System' should be curly bracketed.
  1558. - The default value is `[{"key": "knowledge", "optional": true}]`.
  1559. - `"rerank_model"`: `string` If it is not specified, vector cosine similarity will be used; otherwise, reranking score will be used.
  1560. - `top_k`: `int` Refers to the process of reordering or selecting the top-k items from a list or set based on a specific ranking criterion. Default to 1024.
  1561. - `"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.
  1562. - `"opener"`: `string` The opening greeting for the user. Defaults to `"Hi! I am your assistant, can I help you?"`.
  1563. - `"show_quote`: `boolean` Indicates whether the source of text should be displayed. Defaults to `true`.
  1564. - `"prompt"`: `string` The prompt content.
  1565. #### Response
  1566. Success:
  1567. ```json
  1568. {
  1569. "code": 0,
  1570. "data": {
  1571. "avatar": "",
  1572. "create_date": "Thu, 24 Oct 2024 11:18:29 GMT",
  1573. "create_time": 1729768709023,
  1574. "dataset_ids": [
  1575. "527fa74891e811ef9c650242ac120006"
  1576. ],
  1577. "description": "A helpful Assistant",
  1578. "do_refer": "1",
  1579. "id": "b1f2f15691f911ef81180242ac120003",
  1580. "language": "English",
  1581. "llm": {
  1582. "frequency_penalty": 0.7,
  1583. "model_name": "qwen-plus@Tongyi-Qianwen",
  1584. "presence_penalty": 0.4,
  1585. "temperature": 0.1,
  1586. "top_p": 0.3
  1587. },
  1588. "name": "12234",
  1589. "prompt": {
  1590. "empty_response": "Sorry! No relevant content was found in the knowledge base!",
  1591. "keywords_similarity_weight": 0.3,
  1592. "opener": "Hi! I'm your assistant, what can I do for you?",
  1593. "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 ",
  1594. "rerank_model": "",
  1595. "similarity_threshold": 0.2,
  1596. "top_n": 6,
  1597. "variables": [
  1598. {
  1599. "key": "knowledge",
  1600. "optional": false
  1601. }
  1602. ]
  1603. },
  1604. "prompt_type": "simple",
  1605. "status": "1",
  1606. "tenant_id": "69736c5e723611efb51b0242ac120007",
  1607. "top_k": 1024,
  1608. "update_date": "Thu, 24 Oct 2024 11:18:29 GMT",
  1609. "update_time": 1729768709023
  1610. }
  1611. }
  1612. ```
  1613. Failure:
  1614. ```json
  1615. {
  1616. "code": 102,
  1617. "message": "Duplicated chat name in creating dataset."
  1618. }
  1619. ```
  1620. ---
  1621. ### Update chat assistant
  1622. **PUT** `/api/v1/chats/{chat_id}`
  1623. Updates configurations for a specified chat assistant.
  1624. #### Request
  1625. - Method: PUT
  1626. - URL: `/api/v1/chats/{chat_id}`
  1627. - Headers:
  1628. - `'content-Type: application/json'`
  1629. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1630. - Body:
  1631. - `"name"`: `string`
  1632. - `"avatar"`: `string`
  1633. - `"dataset_ids"`: `list[string]`
  1634. - `"llm"`: `object`
  1635. - `"prompt"`: `object`
  1636. ##### Request example
  1637. ```bash
  1638. curl --request PUT \
  1639. --url http://{address}/api/v1/chats/{chat_id} \
  1640. --header 'Content-Type: application/json' \
  1641. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1642. --data '
  1643. {
  1644. "name":"Test"
  1645. }'
  1646. ```
  1647. #### Parameters
  1648. - `chat_id`: (*Path parameter*)
  1649. The ID of the chat assistant to update.
  1650. - `"name"`: (*Body parameter*), `string`, *Required*
  1651. The revised name of the chat assistant.
  1652. - `"avatar"`: (*Body parameter*), `string`
  1653. Base64 encoding of the avatar.
  1654. - `"dataset_ids"`: (*Body parameter*), `list[string]`
  1655. The IDs of the associated datasets.
  1656. - `"llm"`: (*Body parameter*), `object`
  1657. 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:
  1658. - `"model_name"`, `string`
  1659. The chat model name. If not set, the user's default chat model will be used.
  1660. - `"temperature"`: `float`
  1661. Controls the randomness of the model's predictions. A lower temperature results in more conservative responses, while a higher temperature yields more creative and diverse responses. Defaults to `0.1`.
  1662. - `"top_p"`: `float`
  1663. 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`
  1664. - `"presence_penalty"`: `float`
  1665. This discourages the model from repeating the same information by penalizing words that have already appeared in the conversation. Defaults to `0.2`.
  1666. - `"frequency penalty"`: `float`
  1667. Similar to the presence penalty, this reduces the model’s tendency to repeat the same words frequently. Defaults to `0.7`.
  1668. - `"prompt"`: (*Body parameter*), `object`
  1669. Instructions for the LLM to follow. A `prompt` object contains the following attributes:
  1670. - `"similarity_threshold"`: `float` RAGFlow employs either a combination of weighted keyword similarity and weighted vector cosine similarity, or a combination of weighted keyword similarity and weighted rerank score 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`.
  1671. - `"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`.
  1672. - `"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`.
  1673. - `"variables"`: `object[]` This argument lists the variables to use in the 'System' field of **Chat Configurations**. Note that:
  1674. - `"knowledge"` is a reserved variable, which represents the retrieved chunks.
  1675. - All the variables in 'System' should be curly bracketed.
  1676. - The default value is `[{"key": "knowledge", "optional": true}]`
  1677. - `"rerank_model"`: `string` If it is not specified, vector cosine similarity will be used; otherwise, reranking score will be used.
  1678. - `"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.
  1679. - `"opener"`: `string` The opening greeting for the user. Defaults to `"Hi! I am your assistant, can I help you?"`.
  1680. - `"show_quote`: `boolean` Indicates whether the source of text should be displayed. Defaults to `true`.
  1681. - `"prompt"`: `string` The prompt content.
  1682. #### Response
  1683. Success:
  1684. ```json
  1685. {
  1686. "code": 0
  1687. }
  1688. ```
  1689. Failure:
  1690. ```json
  1691. {
  1692. "code": 102,
  1693. "message": "Duplicated chat name in updating dataset."
  1694. }
  1695. ```
  1696. ---
  1697. ### Delete chat assistants
  1698. **DELETE** `/api/v1/chats`
  1699. Deletes chat assistants by ID.
  1700. #### Request
  1701. - Method: DELETE
  1702. - URL: `/api/v1/chats`
  1703. - Headers:
  1704. - `'content-Type: application/json'`
  1705. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1706. - Body:
  1707. - `"ids"`: `list[string]`
  1708. ##### Request example
  1709. ```bash
  1710. curl --request DELETE \
  1711. --url http://{address}/api/v1/chats \
  1712. --header 'Content-Type: application/json' \
  1713. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1714. --data '
  1715. {
  1716. "ids": ["test_1", "test_2"]
  1717. }'
  1718. ```
  1719. ##### Request parameters
  1720. - `"ids"`: (*Body parameter*), `list[string]`
  1721. The IDs of the chat assistants to delete. If it is not specified, all chat assistants in the system will be deleted.
  1722. #### Response
  1723. Success:
  1724. ```json
  1725. {
  1726. "code": 0
  1727. }
  1728. ```
  1729. Failure:
  1730. ```json
  1731. {
  1732. "code": 102,
  1733. "message": "ids are required"
  1734. }
  1735. ```
  1736. ---
  1737. ### List chat assistants
  1738. **GET** `/api/v1/chats?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={chat_name}&id={chat_id}`
  1739. Lists chat assistants.
  1740. #### Request
  1741. - Method: GET
  1742. - URL: `/api/v1/chats?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={chat_name}&id={chat_id}`
  1743. - Headers:
  1744. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1745. ##### Request example
  1746. ```bash
  1747. curl --request GET \
  1748. --url http://{address}/api/v1/chats?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={chat_name}&id={chat_id} \
  1749. --header 'Authorization: Bearer <YOUR_API_KEY>'
  1750. ```
  1751. ##### Request parameters
  1752. - `page`: (*Filter parameter*), `integer`
  1753. Specifies the page on which the chat assistants will be displayed. Defaults to `1`.
  1754. - `page_size`: (*Filter parameter*), `integer`
  1755. The number of chat assistants on each page. Defaults to `30`.
  1756. - `orderby`: (*Filter parameter*), `string`
  1757. The attribute by which the results are sorted. Available options:
  1758. - `create_time` (default)
  1759. - `update_time`
  1760. - `desc`: (*Filter parameter*), `boolean`
  1761. Indicates whether the retrieved chat assistants should be sorted in descending order. Defaults to `true`.
  1762. - `id`: (*Filter parameter*), `string`
  1763. The ID of the chat assistant to retrieve.
  1764. - `name`: (*Filter parameter*), `string`
  1765. The name of the chat assistant to retrieve.
  1766. #### Response
  1767. Success:
  1768. ```json
  1769. {
  1770. "code": 0,
  1771. "data": [
  1772. {
  1773. "avatar": "",
  1774. "create_date": "Fri, 18 Oct 2024 06:20:06 GMT",
  1775. "create_time": 1729232406637,
  1776. "description": "A helpful Assistant",
  1777. "do_refer": "1",
  1778. "id": "04d0d8e28d1911efa3630242ac120006",
  1779. "dataset_ids": ["527fa74891e811ef9c650242ac120006"],
  1780. "language": "English",
  1781. "llm": {
  1782. "frequency_penalty": 0.7,
  1783. "model_name": "qwen-plus@Tongyi-Qianwen",
  1784. "presence_penalty": 0.4,
  1785. "temperature": 0.1,
  1786. "top_p": 0.3
  1787. },
  1788. "name": "13243",
  1789. "prompt": {
  1790. "empty_response": "Sorry! No relevant content was found in the knowledge base!",
  1791. "keywords_similarity_weight": 0.3,
  1792. "opener": "Hi! I'm your assistant, what can I do for you?",
  1793. "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",
  1794. "rerank_model": "",
  1795. "similarity_threshold": 0.2,
  1796. "top_n": 6,
  1797. "variables": [
  1798. {
  1799. "key": "knowledge",
  1800. "optional": false
  1801. }
  1802. ]
  1803. },
  1804. "prompt_type": "simple",
  1805. "status": "1",
  1806. "tenant_id": "69736c5e723611efb51b0242ac120007",
  1807. "top_k": 1024,
  1808. "update_date": "Fri, 18 Oct 2024 06:20:06 GMT",
  1809. "update_time": 1729232406638
  1810. }
  1811. ]
  1812. }
  1813. ```
  1814. Failure:
  1815. ```json
  1816. {
  1817. "code": 102,
  1818. "message": "The chat doesn't exist"
  1819. }
  1820. ```
  1821. ---
  1822. ## SESSION MANAGEMENT
  1823. ---
  1824. ### Create session with chat assistant
  1825. **POST** `/api/v1/chats/{chat_id}/sessions`
  1826. Creates a session with a chat assistant.
  1827. #### Request
  1828. - Method: POST
  1829. - URL: `/api/v1/chats/{chat_id}/sessions`
  1830. - Headers:
  1831. - `'content-Type: application/json'`
  1832. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1833. - Body:
  1834. - `"name"`: `string`
  1835. - `"user_id"`: `string` (optional)
  1836. ##### Request example
  1837. ```bash
  1838. curl --request POST \
  1839. --url http://{address}/api/v1/chats/{chat_id}/sessions \
  1840. --header 'Content-Type: application/json' \
  1841. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1842. --data '
  1843. {
  1844. "name": "new session"
  1845. }'
  1846. ```
  1847. ##### Request parameters
  1848. - `chat_id`: (*Path parameter*)
  1849. The ID of the associated chat assistant.
  1850. - `"name"`: (*Body parameter*), `string`
  1851. The name of the chat session to create.
  1852. - `"user_id"`: (*Body parameter*), `string`
  1853. Optional user-defined ID.
  1854. #### Response
  1855. Success:
  1856. ```json
  1857. {
  1858. "code": 0,
  1859. "data": {
  1860. "chat_id": "2ca4b22e878011ef88fe0242ac120005",
  1861. "create_date": "Fri, 11 Oct 2024 08:46:14 GMT",
  1862. "create_time": 1728636374571,
  1863. "id": "4606b4ec87ad11efbc4f0242ac120006",
  1864. "messages": [
  1865. {
  1866. "content": "Hi! I am your assistant, can I help you?",
  1867. "role": "assistant"
  1868. }
  1869. ],
  1870. "name": "new session",
  1871. "update_date": "Fri, 11 Oct 2024 08:46:14 GMT",
  1872. "update_time": 1728636374571
  1873. }
  1874. }
  1875. ```
  1876. Failure:
  1877. ```json
  1878. {
  1879. "code": 102,
  1880. "message": "Name cannot be empty."
  1881. }
  1882. ```
  1883. ---
  1884. ### Update chat assistant's session
  1885. **PUT** `/api/v1/chats/{chat_id}/sessions/{session_id}`
  1886. Updates a session of a specified chat assistant.
  1887. #### Request
  1888. - Method: PUT
  1889. - URL: `/api/v1/chats/{chat_id}/sessions/{session_id}`
  1890. - Headers:
  1891. - `'content-Type: application/json'`
  1892. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1893. - Body:
  1894. - `"name`: `string`
  1895. - `"user_id`: `string` (optional)
  1896. ##### Request example
  1897. ```bash
  1898. curl --request PUT \
  1899. --url http://{address}/api/v1/chats/{chat_id}/sessions/{session_id} \
  1900. --header 'Content-Type: application/json' \
  1901. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1902. --data '
  1903. {
  1904. "name": "<REVISED_SESSION_NAME_HERE>"
  1905. }'
  1906. ```
  1907. ##### Request Parameter
  1908. - `chat_id`: (*Path parameter*)
  1909. The ID of the associated chat assistant.
  1910. - `session_id`: (*Path parameter*)
  1911. The ID of the session to update.
  1912. - `"name"`: (*Body Parameter*), `string`
  1913. The revised name of the session.
  1914. - `"user_id"`: (*Body parameter*), `string`
  1915. Optional user-defined ID.
  1916. #### Response
  1917. Success:
  1918. ```json
  1919. {
  1920. "code": 0
  1921. }
  1922. ```
  1923. Failure:
  1924. ```json
  1925. {
  1926. "code": 102,
  1927. "message": "Name cannot be empty."
  1928. }
  1929. ```
  1930. ---
  1931. ### List chat assistant's sessions
  1932. **GET** `/api/v1/chats/{chat_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={session_name}&id={session_id}`
  1933. Lists sessions associated with a specified chat assistant.
  1934. #### Request
  1935. - Method: GET
  1936. - URL: `/api/v1/chats/{chat_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={session_name}&id={session_id}&user_id={user_id}`
  1937. - Headers:
  1938. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1939. ##### Request example
  1940. ```bash
  1941. curl --request GET \
  1942. --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} \
  1943. --header 'Authorization: Bearer <YOUR_API_KEY>'
  1944. ```
  1945. ##### Request Parameters
  1946. - `chat_id`: (*Path parameter*)
  1947. The ID of the associated chat assistant.
  1948. - `page`: (*Filter parameter*), `integer`
  1949. Specifies the page on which the sessions will be displayed. Defaults to `1`.
  1950. - `page_size`: (*Filter parameter*), `integer`
  1951. The number of sessions on each page. Defaults to `30`.
  1952. - `orderby`: (*Filter parameter*), `string`
  1953. The field by which sessions should be sorted. Available options:
  1954. - `create_time` (default)
  1955. - `update_time`
  1956. - `desc`: (*Filter parameter*), `boolean`
  1957. Indicates whether the retrieved sessions should be sorted in descending order. Defaults to `true`.
  1958. - `name`: (*Filter parameter*) `string`
  1959. The name of the chat session to retrieve.
  1960. - `id`: (*Filter parameter*), `string`
  1961. The ID of the chat session to retrieve.
  1962. - `user_id`: (*Filter parameter*), `string`
  1963. The optional user-defined ID passed in when creating session.
  1964. #### Response
  1965. Success:
  1966. ```json
  1967. {
  1968. "code": 0,
  1969. "data": [
  1970. {
  1971. "chat": "2ca4b22e878011ef88fe0242ac120005",
  1972. "create_date": "Fri, 11 Oct 2024 08:46:43 GMT",
  1973. "create_time": 1728636403974,
  1974. "id": "578d541e87ad11ef96b90242ac120006",
  1975. "messages": [
  1976. {
  1977. "content": "Hi! I am your assistant, can I help you?",
  1978. "role": "assistant"
  1979. }
  1980. ],
  1981. "name": "new session",
  1982. "update_date": "Fri, 11 Oct 2024 08:46:43 GMT",
  1983. "update_time": 1728636403974
  1984. }
  1985. ]
  1986. }
  1987. ```
  1988. Failure:
  1989. ```json
  1990. {
  1991. "code": 102,
  1992. "message": "The session doesn't exist"
  1993. }
  1994. ```
  1995. ---
  1996. ### Delete chat assistant's sessions
  1997. **DELETE** `/api/v1/chats/{chat_id}/sessions`
  1998. Deletes sessions of a chat assistant by ID.
  1999. #### Request
  2000. - Method: DELETE
  2001. - URL: `/api/v1/chats/{chat_id}/sessions`
  2002. - Headers:
  2003. - `'content-Type: application/json'`
  2004. - `'Authorization: Bearer <YOUR_API_KEY>'`
  2005. - Body:
  2006. - `"ids"`: `list[string]`
  2007. ##### Request example
  2008. ```bash
  2009. curl --request DELETE \
  2010. --url http://{address}/api/v1/chats/{chat_id}/sessions \
  2011. --header 'Content-Type: application/json' \
  2012. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  2013. --data '
  2014. {
  2015. "ids": ["test_1", "test_2"]
  2016. }'
  2017. ```
  2018. ##### Request Parameters
  2019. - `chat_id`: (*Path parameter*)
  2020. The ID of the associated chat assistant.
  2021. - `"ids"`: (*Body Parameter*), `list[string]`
  2022. The IDs of the sessions to delete. If it is not specified, all sessions associated with the specified chat assistant will be deleted.
  2023. #### Response
  2024. Success:
  2025. ```json
  2026. {
  2027. "code": 0
  2028. }
  2029. ```
  2030. Failure:
  2031. ```json
  2032. {
  2033. "code": 102,
  2034. "message": "The chat doesn't own the session"
  2035. }
  2036. ```
  2037. ---
  2038. ### Converse with chat assistant
  2039. **POST** `/api/v1/chats/{chat_id}/completions`
  2040. Asks a specified chat assistant a question to start an AI-powered conversation.
  2041. :::tip NOTE
  2042. - In streaming mode, not all responses include a reference, as this depends on the system's judgement.
  2043. - In streaming mode, the last message is an empty message:
  2044. ```json
  2045. data:
  2046. {
  2047. "code": 0,
  2048. "data": true
  2049. }
  2050. ```
  2051. :::
  2052. #### Request
  2053. - Method: POST
  2054. - URL: `/api/v1/chats/{chat_id}/completions`
  2055. - Headers:
  2056. - `'content-Type: application/json'`
  2057. - `'Authorization: Bearer <YOUR_API_KEY>'`
  2058. - Body:
  2059. - `"question"`: `string`
  2060. - `"stream"`: `boolean`
  2061. - `"session_id"`: `string` (optional)
  2062. - `"user_id`: `string` (optional)
  2063. ##### Request example
  2064. ```bash
  2065. curl --request POST \
  2066. --url http://{address}/api/v1/chats/{chat_id}/completions \
  2067. --header 'Content-Type: application/json' \
  2068. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  2069. --data-binary '
  2070. {
  2071. }'
  2072. ```
  2073. ```bash
  2074. curl --request POST \
  2075. --url http://{address}/api/v1/chats/{chat_id}/completions \
  2076. --header 'Content-Type: application/json' \
  2077. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  2078. --data-binary '
  2079. {
  2080. "question": "Who are you",
  2081. "stream": true,
  2082. "session_id":"9fa7691cb85c11ef9c5f0242ac120005"
  2083. }'
  2084. ```
  2085. ##### Request Parameters
  2086. - `chat_id`: (*Path parameter*)
  2087. The ID of the associated chat assistant.
  2088. - `"question"`: (*Body Parameter*), `string`, *Required*
  2089. The question to start an AI-powered conversation.
  2090. - `"stream"`: (*Body Parameter*), `boolean`
  2091. Indicates whether to output responses in a streaming way:
  2092. - `true`: Enable streaming (default).
  2093. - `false`: Disable streaming.
  2094. - `"session_id"`: (*Body Parameter*)
  2095. The ID of session. If it is not provided, a new session will be generated.
  2096. - `"user_id"`: (*Body parameter*), `string`
  2097. The optional user-defined ID. Valid *only* when no `session_id` is provided.
  2098. #### Response
  2099. Success without `session_id`:
  2100. ```json
  2101. data:{
  2102. "code": 0,
  2103. "message": "",
  2104. "data": {
  2105. "answer": "Hi! I'm your assistant, what can I do for you?",
  2106. "reference": {},
  2107. "audio_binary": null,
  2108. "id": null,
  2109. "session_id": "b01eed84b85611efa0e90242ac120005"
  2110. }
  2111. }
  2112. data:{
  2113. "code": 0,
  2114. "message": "",
  2115. "data": true
  2116. }
  2117. ```
  2118. Success with `session_id`:
  2119. ```json
  2120. data:{
  2121. "code": 0,
  2122. "data": {
  2123. "answer": "I am an intelligent assistant designed to help answer questions by summarizing content from a",
  2124. "reference": {},
  2125. "audio_binary": null,
  2126. "id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
  2127. "session_id": "82b0ab2a9c1911ef9d870242ac120006"
  2128. }
  2129. }
  2130. data:{
  2131. "code": 0,
  2132. "data": {
  2133. "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",
  2134. "reference": {},
  2135. "audio_binary": null,
  2136. "id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
  2137. "session_id": "82b0ab2a9c1911ef9d870242ac120006"
  2138. }
  2139. }
  2140. data:{
  2141. "code": 0,
  2142. "data": {
  2143. "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.",
  2144. "reference": {},
  2145. "audio_binary": null,
  2146. "id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
  2147. "session_id": "82b0ab2a9c1911ef9d870242ac120006"
  2148. }
  2149. }
  2150. data:{
  2151. "code": 0,
  2152. "data": {
  2153. "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.",
  2154. "reference": {
  2155. "total": 1,
  2156. "chunks": [
  2157. {
  2158. "id": "faf26c791128f2d5e821f822671063bd",
  2159. "content": "xxxxxxxx",
  2160. "document_id": "dd58f58e888511ef89c90242ac120006",
  2161. "document_name": "1.txt",
  2162. "dataset_id": "8e83e57a884611ef9d760242ac120006",
  2163. "image_id": "",
  2164. "similarity": 0.7,
  2165. "vector_similarity": 0.0,
  2166. "term_similarity": 1.0,
  2167. "positions": [
  2168. ""
  2169. ]
  2170. }
  2171. ],
  2172. "doc_aggs": [
  2173. {
  2174. "doc_name": "1.txt",
  2175. "doc_id": "dd58f58e888511ef89c90242ac120006",
  2176. "count": 1
  2177. }
  2178. ]
  2179. },
  2180. "prompt": "xxxxxxxxxxx",
  2181. "id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
  2182. "session_id": "82b0ab2a9c1911ef9d870242ac120006"
  2183. }
  2184. }
  2185. data:{
  2186. "code": 0,
  2187. "data": true
  2188. }
  2189. ```
  2190. Failure:
  2191. ```json
  2192. {
  2193. "code": 102,
  2194. "message": "Please input your question."
  2195. }
  2196. ```
  2197. ---
  2198. ### Create session with agent
  2199. **POST** `/api/v1/agents/{agent_id}/sessions`
  2200. Creates a session with an agent.
  2201. #### Request
  2202. - Method: POST
  2203. - URL: `/api/v1/agents/{agent_id}/sessions?user_id={user_id}`
  2204. - Headers:
  2205. - `'content-Type: application/json' or 'multipart/form-data'`
  2206. - `'Authorization: Bearer <YOUR_API_KEY>'`
  2207. - Body:
  2208. - the required parameters:`str`
  2209. - other parameters:
  2210. The parameters specified in the **Begin** component.
  2211. ##### Request example
  2212. If the **Begin** component in your agent does not take required parameters:
  2213. ```bash
  2214. curl --request POST \
  2215. --url http://{address}/api/v1/agents/{agent_id}/sessions \
  2216. --header 'Content-Type: application/json' \
  2217. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  2218. --data '{
  2219. }'
  2220. ```
  2221. If the **Begin** component in your agent takes required parameters:
  2222. ```bash
  2223. curl --request POST \
  2224. --url http://{address}/api/v1/agents/{agent_id}/sessions \
  2225. --header 'Content-Type: application/json' \
  2226. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  2227. --data '{
  2228. "lang":"Japanese",
  2229. "file":"Who are you"
  2230. }'
  2231. ```
  2232. If the **Begin** component in your agent takes required file parameters:
  2233. ```bash
  2234. curl --request POST \
  2235. --url http://{address}/api/v1/agents/{agent_id}/sessions?user_id={user_id} \
  2236. --header 'Content-Type: multipart/form-data' \
  2237. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  2238. --form '<FILE_KEY>=@./test1.png'
  2239. ```
  2240. ##### Request parameters
  2241. - `agent_id`: (*Path parameter*)
  2242. The ID of the associated agent.
  2243. - `user_id`: (*Filter parameter*)
  2244. The optional user-defined ID for parsing docs (especially images) when creating a session while uploading files.
  2245. #### Response
  2246. Success:
  2247. ```json
  2248. {
  2249. "code": 0,
  2250. "data": {
  2251. "agent_id": "b4a39922b76611efaa1a0242ac120006",
  2252. "dsl": {
  2253. "answer": [],
  2254. "components": {
  2255. "Answer:GreenReadersDrum": {
  2256. "downstream": [],
  2257. "obj": {
  2258. "component_name": "Answer",
  2259. "inputs": [],
  2260. "output": null,
  2261. "params": {}
  2262. },
  2263. "upstream": []
  2264. },
  2265. "begin": {
  2266. "downstream": [],
  2267. "obj": {
  2268. "component_name": "Begin",
  2269. "inputs": [],
  2270. "output": {},
  2271. "params": {}
  2272. },
  2273. "upstream": []
  2274. }
  2275. },
  2276. "embed_id": "",
  2277. "graph": {
  2278. "edges": [],
  2279. "nodes": [
  2280. {
  2281. "data": {
  2282. "label": "Begin",
  2283. "name": "begin"
  2284. },
  2285. "dragging": false,
  2286. "height": 44,
  2287. "id": "begin",
  2288. "position": {
  2289. "x": 53.25688640427177,
  2290. "y": 198.37155679786412
  2291. },
  2292. "positionAbsolute": {
  2293. "x": 53.25688640427177,
  2294. "y": 198.37155679786412
  2295. },
  2296. "selected": false,
  2297. "sourcePosition": "left",
  2298. "targetPosition": "right",
  2299. "type": "beginNode",
  2300. "width": 200
  2301. },
  2302. {
  2303. "data": {
  2304. "form": {},
  2305. "label": "Answer",
  2306. "name": "dialog_0"
  2307. },
  2308. "dragging": false,
  2309. "height": 44,
  2310. "id": "Answer:GreenReadersDrum",
  2311. "position": {
  2312. "x": 360.43473114516974,
  2313. "y": 207.29298425089348
  2314. },
  2315. "positionAbsolute": {
  2316. "x": 360.43473114516974,
  2317. "y": 207.29298425089348
  2318. },
  2319. "selected": false,
  2320. "sourcePosition": "right",
  2321. "targetPosition": "left",
  2322. "type": "logicNode",
  2323. "width": 200
  2324. }
  2325. ]
  2326. },
  2327. "history": [],
  2328. "messages": [],
  2329. "path": [
  2330. [
  2331. "begin"
  2332. ],
  2333. []
  2334. ],
  2335. "reference": []
  2336. },
  2337. "id": "2581031eb7a311efb5200242ac120005",
  2338. "message": [
  2339. {
  2340. "content": "Hi! I'm your smart assistant. What can I do for you?",
  2341. "role": "assistant"
  2342. }
  2343. ],
  2344. "source": "agent",
  2345. "user_id": "69736c5e723611efb51b0242ac120007"
  2346. }
  2347. }
  2348. ```
  2349. Failure:
  2350. ```json
  2351. {
  2352. "code": 102,
  2353. "message": "Agent not found."
  2354. }
  2355. ```
  2356. ---
  2357. ### Converse with agent
  2358. **POST** `/api/v1/agents/{agent_id}/completions`
  2359. Asks a specified agent a question to start an AI-powered conversation.
  2360. :::tip NOTE
  2361. - In streaming mode, not all responses include a reference, as this depends on the system's judgement.
  2362. - In streaming mode, the last message is an empty message:
  2363. ```json
  2364. data:
  2365. {
  2366. "code": 0,
  2367. "data": true
  2368. }
  2369. ```
  2370. :::
  2371. #### Request
  2372. - Method: POST
  2373. - URL: `/api/v1/agents/{agent_id}/completions`
  2374. - Headers:
  2375. - `'content-Type: application/json'`
  2376. - `'Authorization: Bearer <YOUR_API_KEY>'`
  2377. - Body:
  2378. - `"question"`: `string`
  2379. - `"stream"`: `boolean`
  2380. - `"session_id"`: `string`
  2381. - `"user_id"`: `string`(optional)
  2382. - `"sync_dsl"`: `boolean` (optional)
  2383. - other parameters: `string`
  2384. :::info IMPORTANT
  2385. You can include custom parameters in the request body, but first ensure they are defined in the [Begin](../guides/agent/agent_component_reference/begin.mdx) agent component.
  2386. :::
  2387. ##### Request example
  2388. - If the **Begin** component does not take parameters, the following code will create a session.
  2389. ```bash
  2390. curl --request POST \
  2391. --url http://{address}/api/v1/agents/{agent_id}/completions \
  2392. --header 'Content-Type: application/json' \
  2393. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  2394. --data-binary '
  2395. {
  2396. }'
  2397. ```
  2398. - If the **Begin** component takes parameters, the following code will create a session.
  2399. ```bash
  2400. curl --request POST \
  2401. --url http://{address}/api/v1/agents/{agent_id}/completions \
  2402. --header 'Content-Type: application/json' \
  2403. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  2404. --data-binary '
  2405. {
  2406. "lang":"English",
  2407. "file":"How is the weather tomorrow?"
  2408. }'
  2409. ```
  2410. The following code will execute the completion process
  2411. ```bash
  2412. curl --request POST \
  2413. --url http://{address}/api/v1/agents/{agent_id}/completions \
  2414. --header 'Content-Type: application/json' \
  2415. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  2416. --data-binary '
  2417. {
  2418. "question": "Hello",
  2419. "stream": true,
  2420. "session_id": "cb2f385cb86211efa36e0242ac120005"
  2421. }'
  2422. ```
  2423. ##### Request Parameters
  2424. - `agent_id`: (*Path parameter*), `string`
  2425. The ID of the associated agent.
  2426. - `"question"`: (*Body Parameter*), `string`, *Required*
  2427. The question to start an AI-powered conversation.
  2428. - `"stream"`: (*Body Parameter*), `boolean`
  2429. Indicates whether to output responses in a streaming way:
  2430. - `true`: Enable streaming (default).
  2431. - `false`: Disable streaming.
  2432. - `"session_id"`: (*Body Parameter*)
  2433. The ID of the session. If it is not provided, a new session will be generated.
  2434. - `"user_id"`: (*Body parameter*), `string`
  2435. The optional user-defined ID. Valid *only* when no `session_id` is provided.
  2436. - `"sync_dsl"`: (*Body parameter*), `boolean`
  2437. Whether to synchronize the changes to existing sessions when an agent is modified, defaults to `false`.
  2438. - Other parameters: (*Body Parameter*)
  2439. Parameters specified in the **Begin** component.
  2440. #### Response
  2441. success without `session_id` provided and with no parameters specified in the **Begin** component:
  2442. ```json
  2443. data:{
  2444. "code": 0,
  2445. "message": "",
  2446. "data": {
  2447. "answer": "Hi! I'm your smart assistant. What can I do for you?",
  2448. "reference": {},
  2449. "id": "31e6091d-88d4-441b-ac65-eae1c055be7b",
  2450. "session_id": "2987ad3eb85f11efb2a70242ac120005"
  2451. }
  2452. }
  2453. data:{
  2454. "code": 0,
  2455. "message": "",
  2456. "data": true
  2457. }
  2458. ```
  2459. Success without `session_id` provided and with parameters specified in the **Begin** component:
  2460. ```json
  2461. data:{
  2462. "code": 0,
  2463. "message": "",
  2464. "data": {
  2465. "session_id": "eacb36a0bdff11ef97120242ac120006",
  2466. "answer": "",
  2467. "reference": [],
  2468. "param": [
  2469. {
  2470. "key": "lang",
  2471. "name": "Target Language",
  2472. "optional": false,
  2473. "type": "line",
  2474. "value": "English"
  2475. },
  2476. {
  2477. "key": "file",
  2478. "name": "Files",
  2479. "optional": false,
  2480. "type": "file",
  2481. "value": "How is the weather tomorrow?"
  2482. },
  2483. {
  2484. "key": "hhyt",
  2485. "name": "hhty",
  2486. "optional": true,
  2487. "type": "line"
  2488. }
  2489. ]
  2490. }
  2491. }
  2492. data:
  2493. ```
  2494. Success with parameters specified in the **Begin** component:
  2495. ```json
  2496. data:{
  2497. "code": 0,
  2498. "message": "",
  2499. "data": {
  2500. "answer": "How",
  2501. "reference": {},
  2502. "id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
  2503. "session_id": "4399c7d0b86311efac5b0242ac120005"
  2504. }
  2505. }
  2506. data:{
  2507. "code": 0,
  2508. "message": "",
  2509. "data": {
  2510. "answer": "How is",
  2511. "reference": {},
  2512. "id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
  2513. "session_id": "4399c7d0b86311efac5b0242ac120005"
  2514. }
  2515. }
  2516. data:{
  2517. "code": 0,
  2518. "message": "",
  2519. "data": {
  2520. "answer": "How is the",
  2521. "reference": {},
  2522. "id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
  2523. "session_id": "4399c7d0b86311efac5b0242ac120005"
  2524. }
  2525. }
  2526. data:{
  2527. "code": 0,
  2528. "message": "",
  2529. "data": {
  2530. "answer": "How is the weather",
  2531. "reference": {},
  2532. "id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
  2533. "session_id": "4399c7d0b86311efac5b0242ac120005"
  2534. }
  2535. }
  2536. data:{
  2537. "code": 0,
  2538. "message": "",
  2539. "data": {
  2540. "answer": "How is the weather tomorrow",
  2541. "reference": {},
  2542. "id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
  2543. "session_id": "4399c7d0b86311efac5b0242ac120005"
  2544. }
  2545. }
  2546. data:{
  2547. "code": 0,
  2548. "message": "",
  2549. "data": {
  2550. "answer": "How is the weather tomorrow?",
  2551. "reference": {},
  2552. "id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
  2553. "session_id": "4399c7d0b86311efac5b0242ac120005"
  2554. }
  2555. }
  2556. data:{
  2557. "code": 0,
  2558. "message": "",
  2559. "data": {
  2560. "answer": "How is the weather tomorrow?",
  2561. "reference": {},
  2562. "id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
  2563. "session_id": "4399c7d0b86311efac5b0242ac120005"
  2564. }
  2565. }
  2566. data:{
  2567. "code": 0,
  2568. "message": "",
  2569. "data": true
  2570. }
  2571. ```
  2572. Failure:
  2573. ```json
  2574. {
  2575. "code": 102,
  2576. "message": "`question` is required."
  2577. }
  2578. ```
  2579. ---
  2580. ### List agent sessions
  2581. **GET** `/api/v1/agents/{agent_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&id={session_id}&user_id={user_id}&dsl={dsl}`
  2582. Lists sessions associated with a specified agent.
  2583. #### Request
  2584. - Method: GET
  2585. - URL: `/api/v1/agents/{agent_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&id={session_id}`
  2586. - Headers:
  2587. - `'Authorization: Bearer <YOUR_API_KEY>'`
  2588. ##### Request example
  2589. ```bash
  2590. curl --request GET \
  2591. --url http://{address}/api/v1/agents/{agent_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&id={session_id}&user_id={user_id} \
  2592. --header 'Authorization: Bearer <YOUR_API_KEY>'
  2593. ```
  2594. ##### Request Parameters
  2595. - `agent_id`: (*Path parameter*)
  2596. The ID of the associated agent.
  2597. - `page`: (*Filter parameter*), `integer`
  2598. Specifies the page on which the sessions will be displayed. Defaults to `1`.
  2599. - `page_size`: (*Filter parameter*), `integer`
  2600. The number of sessions on each page. Defaults to `30`.
  2601. - `orderby`: (*Filter parameter*), `string`
  2602. The field by which sessions should be sorted. Available options:
  2603. - `create_time` (default)
  2604. - `update_time`
  2605. - `desc`: (*Filter parameter*), `boolean`
  2606. Indicates whether the retrieved sessions should be sorted in descending order. Defaults to `true`.
  2607. - `id`: (*Filter parameter*), `string`
  2608. The ID of the agent session to retrieve.
  2609. - `user_id`: (*Filter parameter*), `string`
  2610. The optional user-defined ID passed in when creating session.
  2611. - `dsl`: (*Filter parameter*), `boolean`
  2612. Indicates whether to include the dsl field of the sessions in the response. Defaults to `true`.
  2613. #### Response
  2614. Success:
  2615. ```json
  2616. {
  2617. "code": 0,
  2618. "data": [{
  2619. "agent_id": "e9e2b9c2b2f911ef801d0242ac120006",
  2620. "dsl": {
  2621. "answer": [],
  2622. "components": {
  2623. "Answer:OrangeTermsBurn": {
  2624. "downstream": [],
  2625. "obj": {
  2626. "component_name": "Answer",
  2627. "params": {}
  2628. },
  2629. "upstream": []
  2630. },
  2631. "Generate:SocialYearsRemain": {
  2632. "downstream": [],
  2633. "obj": {
  2634. "component_name": "Generate",
  2635. "params": {
  2636. "cite": true,
  2637. "frequency_penalty": 0.7,
  2638. "llm_id": "gpt-4o___OpenAI-API@OpenAI-API-Compatible",
  2639. "message_history_window_size": 12,
  2640. "parameters": [],
  2641. "presence_penalty": 0.4,
  2642. "prompt": "Please summarize the following paragraph. Pay attention to the numbers and do not make things up. The paragraph is as follows:\n{input}\nThis is what you need to summarize.",
  2643. "temperature": 0.1,
  2644. "top_p": 0.3
  2645. }
  2646. },
  2647. "upstream": []
  2648. },
  2649. "begin": {
  2650. "downstream": [],
  2651. "obj": {
  2652. "component_name": "Begin",
  2653. "params": {}
  2654. },
  2655. "upstream": []
  2656. }
  2657. },
  2658. "graph": {
  2659. "edges": [],
  2660. "nodes": [
  2661. {
  2662. "data": {
  2663. "label": "Begin",
  2664. "name": "begin"
  2665. },
  2666. "height": 44,
  2667. "id": "begin",
  2668. "position": {
  2669. "x": 50,
  2670. "y": 200
  2671. },
  2672. "sourcePosition": "left",
  2673. "targetPosition": "right",
  2674. "type": "beginNode",
  2675. "width": 200
  2676. },
  2677. {
  2678. "data": {
  2679. "form": {
  2680. "cite": true,
  2681. "frequencyPenaltyEnabled": true,
  2682. "frequency_penalty": 0.7,
  2683. "llm_id": "gpt-4o___OpenAI-API@OpenAI-API-Compatible",
  2684. "maxTokensEnabled": true,
  2685. "message_history_window_size": 12,
  2686. "parameters": [],
  2687. "presencePenaltyEnabled": true,
  2688. "presence_penalty": 0.4,
  2689. "prompt": "Please summarize the following paragraph. Pay attention to the numbers and do not make things up. The paragraph is as follows:\n{input}\nThis is what you need to summarize.",
  2690. "temperature": 0.1,
  2691. "temperatureEnabled": true,
  2692. "topPEnabled": true,
  2693. "top_p": 0.3
  2694. },
  2695. "label": "Generate",
  2696. "name": "Generate Answer_0"
  2697. },
  2698. "dragging": false,
  2699. "height": 105,
  2700. "id": "Generate:SocialYearsRemain",
  2701. "position": {
  2702. "x": 561.3457829707513,
  2703. "y": 178.7211182312641
  2704. },
  2705. "positionAbsolute": {
  2706. "x": 561.3457829707513,
  2707. "y": 178.7211182312641
  2708. },
  2709. "selected": true,
  2710. "sourcePosition": "right",
  2711. "targetPosition": "left",
  2712. "type": "generateNode",
  2713. "width": 200
  2714. },
  2715. {
  2716. "data": {
  2717. "form": {},
  2718. "label": "Answer",
  2719. "name": "Dialogue_0"
  2720. },
  2721. "height": 44,
  2722. "id": "Answer:OrangeTermsBurn",
  2723. "position": {
  2724. "x": 317.2368194777658,
  2725. "y": 218.30635555445093
  2726. },
  2727. "sourcePosition": "right",
  2728. "targetPosition": "left",
  2729. "type": "logicNode",
  2730. "width": 200
  2731. }
  2732. ]
  2733. },
  2734. "history": [],
  2735. "messages": [],
  2736. "path": [],
  2737. "reference": []
  2738. },
  2739. "id": "792dde22b2fa11ef97550242ac120006",
  2740. "message": [
  2741. {
  2742. "content": "Hi! I'm your smart assistant. What can I do for you?",
  2743. "role": "assistant"
  2744. }
  2745. ],
  2746. "source": "agent",
  2747. "user_id": ""
  2748. }]
  2749. }
  2750. ```
  2751. Failure:
  2752. ```json
  2753. {
  2754. "code": 102,
  2755. "message": "You don't own the agent ccd2f856b12311ef94ca0242ac1200052."
  2756. }
  2757. ```
  2758. ---
  2759. ### Delete agent's sessions
  2760. **DELETE** `/api/v1/agents/{agent_id}/sessions`
  2761. Deletes sessions of a agent by ID.
  2762. #### Request
  2763. - Method: DELETE
  2764. - URL: `/api/v1/agents/{agent_id}/sessions`
  2765. - Headers:
  2766. - `'content-Type: application/json'`
  2767. - `'Authorization: Bearer <YOUR_API_KEY>'`
  2768. - Body:
  2769. - `"ids"`: `list[string]`
  2770. ##### Request example
  2771. ```bash
  2772. curl --request DELETE \
  2773. --url http://{address}/api/v1/agents/{agent_id}/sessions \
  2774. --header 'Content-Type: application/json' \
  2775. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  2776. --data '
  2777. {
  2778. "ids": ["test_1", "test_2"]
  2779. }'
  2780. ```
  2781. ##### Request Parameters
  2782. - `agent_id`: (*Path parameter*)
  2783. The ID of the associated agent.
  2784. - `"ids"`: (*Body Parameter*), `list[string]`
  2785. The IDs of the sessions to delete. If it is not specified, all sessions associated with the specified agent will be deleted.
  2786. #### Response
  2787. Success:
  2788. ```json
  2789. {
  2790. "code": 0
  2791. }
  2792. ```
  2793. Failure:
  2794. ```json
  2795. {
  2796. "code": 102,
  2797. "message": "The agent doesn't own the session cbd31e52f73911ef93b232903b842af6"
  2798. }
  2799. ```
  2800. ---
  2801. ### Generate related questions
  2802. **POST** `/v1/sessions/related_questions`
  2803. Generates five to ten alternative question strings from the user's original query to retrieve more relevant search results.
  2804. This operation requires a `Bearer Login Token`, which typically expires with in 24 hours. You can find the it in the Request Headers in your browser easily as shown below:
  2805. ![Image](https://raw.githubusercontent.com/infiniflow/ragflow-docs/main/images/login_token.jpg)
  2806. :::tip NOTE
  2807. The chat model autonomously determines the number of questions to generate based on the instruction, typically between five and ten.
  2808. :::
  2809. #### Request
  2810. - Method: POST
  2811. - URL: `/v1/sessions/related_questions`
  2812. - Headers:
  2813. - `'content-Type: application/json'`
  2814. - `'Authorization: Bearer <YOUR_LOGIN_TOKEN>'`
  2815. - Body:
  2816. - `"question"`: `string`
  2817. - `"industry"`: `string`
  2818. ##### Request example
  2819. ```bash
  2820. curl --request POST \
  2821. --url http://{address}/v1/sessions/related_questions \
  2822. --header 'Content-Type: application/json' \
  2823. --header 'Authorization: Bearer <YOUR_LOGIN_TOKEN>' \
  2824. --data '
  2825. {
  2826. "question": "What are the key advantages of Neovim over Vim?",
  2827. "industry": "software_development"
  2828. }'
  2829. ```
  2830. ##### Request Parameters
  2831. - `"question"`: (*Body Parameter*), `string`
  2832. The original user question.
  2833. - `"industry"`: (*Body Parameter*), `string`
  2834. Industry of the question.
  2835. #### Response
  2836. Success:
  2837. ```json
  2838. {
  2839. "code": 0,
  2840. "data": [
  2841. "What makes Neovim superior to Vim in terms of features?",
  2842. "How do the benefits of Neovim compare to those of Vim?",
  2843. "What advantages does Neovim offer that are not present in Vim?",
  2844. "In what ways does Neovim outperform Vim in functionality?",
  2845. "What are the most significant improvements in Neovim compared to Vim?",
  2846. "What unique advantages does Neovim bring to the table over Vim?",
  2847. "How does the user experience in Neovim differ from Vim in terms of benefits?",
  2848. "What are the top reasons to switch from Vim to Neovim?",
  2849. "What features of Neovim are considered more advanced than those in Vim?"
  2850. ],
  2851. "message": "success"
  2852. }
  2853. ```
  2854. Failure:
  2855. ```json
  2856. {
  2857. "code": 401,
  2858. "data": null,
  2859. "message": "<Unauthorized '401: Unauthorized'>"
  2860. }
  2861. ```
  2862. ---
  2863. ## AGENT MANAGEMENT
  2864. ---
  2865. ### List agents
  2866. **GET** `/api/v1/agents?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={agent_name}&id={agent_id}`
  2867. Lists agents.
  2868. #### Request
  2869. - Method: GET
  2870. - URL: `/api/v1/agents?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={agent_name}&id={agent_id}`
  2871. - Headers:
  2872. - `'Authorization: Bearer <YOUR_API_KEY>'`
  2873. ##### Request example
  2874. ```bash
  2875. curl --request GET \
  2876. --url http://{address}/api/v1/agents?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={agent_name}&id={agent_id} \
  2877. --header 'Authorization: Bearer <YOUR_API_KEY>'
  2878. ```
  2879. ##### Request parameters
  2880. - `page`: (*Filter parameter*), `integer`
  2881. Specifies the page on which the agents will be displayed. Defaults to `1`.
  2882. - `page_size`: (*Filter parameter*), `integer`
  2883. The number of agents on each page. Defaults to `30`.
  2884. - `orderby`: (*Filter parameter*), `string`
  2885. The attribute by which the results are sorted. Available options:
  2886. - `create_time` (default)
  2887. - `update_time`
  2888. - `desc`: (*Filter parameter*), `boolean`
  2889. Indicates whether the retrieved agents should be sorted in descending order. Defaults to `true`.
  2890. - `id`: (*Filter parameter*), `string`
  2891. The ID of the agent to retrieve.
  2892. - `name`: (*Filter parameter*), `string`
  2893. The name of the agent to retrieve.
  2894. #### Response
  2895. Success:
  2896. ```json
  2897. {
  2898. "code": 0,
  2899. "data": [
  2900. {
  2901. "avatar": null,
  2902. "canvas_type": null,
  2903. "create_date": "Thu, 05 Dec 2024 19:10:36 GMT",
  2904. "create_time": 1733397036424,
  2905. "description": null,
  2906. "dsl": {
  2907. "answer": [],
  2908. "components": {
  2909. "begin": {
  2910. "downstream": [],
  2911. "obj": {
  2912. "component_name": "Begin",
  2913. "params": {}
  2914. },
  2915. "upstream": []
  2916. }
  2917. },
  2918. "graph": {
  2919. "edges": [],
  2920. "nodes": [
  2921. {
  2922. "data": {
  2923. "label": "Begin",
  2924. "name": "begin"
  2925. },
  2926. "height": 44,
  2927. "id": "begin",
  2928. "position": {
  2929. "x": 50,
  2930. "y": 200
  2931. },
  2932. "sourcePosition": "left",
  2933. "targetPosition": "right",
  2934. "type": "beginNode",
  2935. "width": 200
  2936. }
  2937. ]
  2938. },
  2939. "history": [],
  2940. "messages": [],
  2941. "path": [],
  2942. "reference": []
  2943. },
  2944. "id": "8d9ca0e2b2f911ef9ca20242ac120006",
  2945. "title": "123465",
  2946. "update_date": "Thu, 05 Dec 2024 19:10:56 GMT",
  2947. "update_time": 1733397056801,
  2948. "user_id": "69736c5e723611efb51b0242ac120007"
  2949. }
  2950. ]
  2951. }
  2952. ```
  2953. Failure:
  2954. ```json
  2955. {
  2956. "code": 102,
  2957. "message": "The agent doesn't exist."
  2958. }
  2959. ```
  2960. ---
  2961. ### Create agent
  2962. **POST** `/api/v1/agents`
  2963. Create an agent.
  2964. #### Request
  2965. - Method: POST
  2966. - URL: `/api/v1/agents`
  2967. - Headers:
  2968. - `'Content-Type: application/json`
  2969. - `'Authorization: Bearer <YOUR_API_KEY>'`
  2970. - Body:
  2971. - `"title"`: `string`
  2972. - `"description"`: `string`
  2973. - `"dsl"`: `object`
  2974. ##### Request example
  2975. ```bash
  2976. curl --request POST \
  2977. --url http://{address}/api/v1/agents \
  2978. --header 'Content-Type: application/json' \
  2979. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  2980. --data '{
  2981. "title": "Test Agent",
  2982. "description": "A test agent",
  2983. "dsl": {
  2984. // ... Canvas DSL here ...
  2985. }
  2986. }'
  2987. ```
  2988. ##### Request parameters
  2989. - `title`: (*Body parameter*), `string`, *Required*
  2990. The title of the agent.
  2991. - `description`: (*Body parameter*), `string`
  2992. The description of the agent. Defaults to `None`.
  2993. - `dsl`: (*Body parameter*), `object`, *Required*
  2994. The canvas DSL object of the agent.
  2995. #### Response
  2996. Success:
  2997. ```json
  2998. {
  2999. "code": 0,
  3000. "data": true,
  3001. "message": "success"
  3002. }
  3003. ```
  3004. Failure:
  3005. ```json
  3006. {
  3007. "code": 102,
  3008. "message": "Agent with title test already exists."
  3009. }
  3010. ```
  3011. ---
  3012. ### Update agent
  3013. **PUT** `/api/v1/agents/{agent_id}`
  3014. Update an agent by id.
  3015. #### Request
  3016. - Method: PUT
  3017. - URL: `/api/v1/agents/{agent_id}`
  3018. - Headers:
  3019. - `'Content-Type: application/json`
  3020. - `'Authorization: Bearer <YOUR_API_KEY>'`
  3021. - Body:
  3022. - `"title"`: `string`
  3023. - `"description"`: `string`
  3024. - `"dsl"`: `object`
  3025. ##### Request example
  3026. ```bash
  3027. curl --request PUT \
  3028. --url http://{address}/api/v1/agents/58af890a2a8911f0a71a11b922ed82d6 \
  3029. --header 'Content-Type: application/json' \
  3030. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  3031. --data '{
  3032. "title": "Test Agent",
  3033. "description": "A test agent",
  3034. "dsl": {
  3035. // ... Canvas DSL here ...
  3036. }
  3037. }'
  3038. ```
  3039. ##### Request parameters
  3040. - `agent_id`: (*Path parameter*), `string`
  3041. The id of the agent to be updated.
  3042. - `title`: (*Body parameter*), `string`
  3043. The title of the agent.
  3044. - `description`: (*Body parameter*), `string`
  3045. The description of the agent.
  3046. - `dsl`: (*Body parameter*), `object`
  3047. The canvas DSL object of the agent.
  3048. Only specify the parameter you want to change in the request body. If a parameter does not exist or is `None`, it won't be updated.
  3049. #### Response
  3050. Success:
  3051. ```json
  3052. {
  3053. "code": 0,
  3054. "data": true,
  3055. "message": "success"
  3056. }
  3057. ```
  3058. Failure:
  3059. ```json
  3060. {
  3061. "code": 103,
  3062. "message": "Only owner of canvas authorized for this operation."
  3063. }
  3064. ```
  3065. ---
  3066. ### Delete agent
  3067. **DELETE** `/api/v1/agents/{agent_id}`
  3068. Delete an agent by id.
  3069. #### Request
  3070. - Method: DELETE
  3071. - URL: `/api/v1/agents/{agent_id}`
  3072. - Headers:
  3073. - `'Content-Type: application/json`
  3074. - `'Authorization: Bearer <YOUR_API_KEY>'`
  3075. ##### Request example
  3076. ```bash
  3077. curl --request DELETE \
  3078. --url http://{address}/api/v1/agents/58af890a2a8911f0a71a11b922ed82d6 \
  3079. --header 'Content-Type: application/json' \
  3080. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  3081. --data '{}'
  3082. ```
  3083. ##### Request parameters
  3084. - `agent_id`: (*Path parameter*), `string`
  3085. The id of the agent to be deleted.
  3086. #### Response
  3087. Success:
  3088. ```json
  3089. {
  3090. "code": 0,
  3091. "data": true,
  3092. "message": "success"
  3093. }
  3094. ```
  3095. Failure:
  3096. ```json
  3097. {
  3098. "code": 103,
  3099. "message": "Only owner of canvas authorized for this operation."
  3100. }
  3101. ```
  3102. ---