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

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