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

http_api_reference.md 88KB

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