您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

http_api_reference.md 92KB

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