Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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