You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

http_api_reference.md 109KB

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