選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

http_api_reference.md 101KB

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