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

http_api_reference.md 92KB

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