Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

http_api_reference.md 92KB

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