Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

http_api_reference.md 63KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340
  1. ---
  2. sidebar_position: 1
  3. slug: /http_api_reference
  4. ---
  5. # HTTP API Reference
  6. A complete reference for RAGFlow's RESTful API. Before proceeding, please ensure you [have your RAGFlow API key ready for authentication](../guides/develop/acquire_ragflow_api_key.md).
  7. ---
  8. :::tip API GROUPING
  9. Dataset Management
  10. :::
  11. ---
  12. ## Create dataset
  13. **POST** `/api/v1/datasets`
  14. Creates a dataset.
  15. ### Request
  16. - Method: POST
  17. - URL: `/api/v1/datasets`
  18. - Headers:
  19. - `'content-Type: application/json'`
  20. - `'Authorization: Bearer <YOUR_API_KEY>'`
  21. - Body:
  22. - `"name"`: `string`
  23. - `"avatar"`: `string`
  24. - `"description"`: `string`
  25. - `"language"`: `string`
  26. - `"embedding_model"`: `string`
  27. - `"permission"`: `string`
  28. - `"chunk_method"`: `string`
  29. - `"parser_config"`: `object`
  30. #### Request example
  31. ```bash
  32. curl --request POST \
  33. --url http://{address}/api/v1/datasets \
  34. --header 'Content-Type: application/json' \
  35. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  36. --data '{
  37. "name": "test_1"
  38. }'
  39. ```
  40. #### Request parameters
  41. - `"name"`: (*Body parameter*), `string`, *Required*
  42. The unique name of the dataset to create. It must adhere to the following requirements:
  43. - Permitted characters include:
  44. - English letters (a-z, A-Z)
  45. - Digits (0-9)
  46. - "_" (underscore)
  47. - Must begin with an English letter or underscore.
  48. - Maximum 65,535 characters.
  49. - Case-insensitive.
  50. - `"avatar"`: (*Body parameter*), `string`
  51. Base64 encoding of the avatar.
  52. - `"description"`: (*Body parameter*), `string`
  53. A brief description of the dataset to create.
  54. - `"language"`: (*Body parameter*), `string`
  55. The language setting of the dataset to create. Available options:
  56. - `"English"` (default)
  57. - `"Chinese"`
  58. - `"embedding_model"`: (*Body parameter*), `string`
  59. The name of the embedding model to use. For example: `"BAAI/bge-zh-v1.5"`
  60. - `"permission"`: (*Body parameter*), `string`
  61. Specifies who can access the dataset to create. You can set it only to `"me"` for now.
  62. - `"chunk_method"`: (*Body parameter*), `enum<string>`
  63. The chunking method of the dataset to create. Available options:
  64. - `"naive"`: General (default)
  65. - `"manual"`: Manual
  66. - `"qa"`: Q&A
  67. - `"table"`: Table
  68. - `"paper"`: Paper
  69. - `"book"`: Book
  70. - `"laws"`: Laws
  71. - `"presentation"`: Presentation
  72. - `"picture"`: Picture
  73. - `"one"`: One
  74. - `"knowledge_graph"`: Knowledge Graph
  75. 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!
  76. - `"email"`: Email
  77. - `"parser_config"`: (*Body parameter*), `object`
  78. The configuration settings for the dataset parser. The attributes in this JSON object vary with the selected `"chunk_method"`:
  79. - If `"chunk_method"` is `"naive"`, the `"parser_config"` object contains the following attributes:
  80. - `"chunk_token_count"`: Defaults to `128`.
  81. - `"layout_recognize"`: Defaults to `true`.
  82. - `"html4excel"`: Indicates whether to convert Excel documents into HTML format. Defaults to `false`.
  83. - `"delimiter"`: Defaults to `"\n!?。;!?"`.
  84. - `"task_page_size"`: Defaults to `12`. For PDF only.
  85. - `"raptor"`: Raptor-specific settings. Defaults to: `{"use_raptor": false}`.
  86. - If `"chunk_method"` is `"qa"`, `"manuel"`, `"paper"`, `"book"`, `"laws"`, or `"presentation"`, the `"parser_config"` object contains the following attribute:
  87. - `"raptor"`: Raptor-specific settings. Defaults to: `{"use_raptor": false}`.
  88. - If `"chunk_method"` is `"table"`, `"picture"`, `"one"`, or `"email"`, `"parser_config"` is an empty JSON object.
  89. - If `"chunk_method"` is `"knowledge_graph"`, the `"parser_config"` object contains the following attributes:
  90. - `"chunk_token_count"`: Defaults to `128`.
  91. - `"delimiter"`: Defaults to `"\n!?。;!?"`.
  92. - `"entity_types"`: Defaults to `["organization","person","location","event","time"]`
  93. ### Response
  94. Success:
  95. ```json
  96. {
  97. "code": 0,
  98. "data": {
  99. "avatar": null,
  100. "chunk_count": 0,
  101. "chunk_method": "naive",
  102. "create_date": "Thu, 24 Oct 2024 09:14:07 GMT",
  103. "create_time": 1729761247434,
  104. "created_by": "69736c5e723611efb51b0242ac120007",
  105. "description": null,
  106. "document_count": 0,
  107. "embedding_model": "BAAI/bge-large-zh-v1.5",
  108. "id": "527fa74891e811ef9c650242ac120006",
  109. "language": "English",
  110. "name": "test_1",
  111. "parser_config": {
  112. "chunk_token_num": 128,
  113. "delimiter": "\\n!?;。;!?",
  114. "html4excel": false,
  115. "layout_recognize": true,
  116. "raptor": {
  117. "user_raptor": false
  118. }
  119. },
  120. "permission": "me",
  121. "similarity_threshold": 0.2,
  122. "status": "1",
  123. "tenant_id": "69736c5e723611efb51b0242ac120007",
  124. "token_num": 0,
  125. "update_date": "Thu, 24 Oct 2024 09:14:07 GMT",
  126. "update_time": 1729761247434,
  127. "vector_similarity_weight": 0.3
  128. }
  129. }
  130. ```
  131. Failure:
  132. ```json
  133. {
  134. "code": 102,
  135. "message": "Duplicated knowledgebase name in creating dataset."
  136. }
  137. ```
  138. ---
  139. ## Delete datasets
  140. **DELETE** `/api/v1/datasets`
  141. Deletes datasets by ID.
  142. ### Request
  143. - Method: DELETE
  144. - URL: `/api/v1/datasets`
  145. - Headers:
  146. - `'content-Type: application/json'`
  147. - `'Authorization: Bearer <YOUR_API_KEY>'`
  148. - Body:
  149. - `"ids"`: `list[string]`
  150. #### Request example
  151. ```bash
  152. curl --request DELETE \
  153. --url http://{address}/api/v1/datasets \
  154. --header 'Content-Type: application/json' \
  155. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  156. --data '{"ids": ["test_1", "test_2"]}'
  157. ```
  158. #### Request parameters
  159. - `"ids"`: (*Body parameter*), `list[string]`
  160. The IDs of the datasets to delete. If it is not specified, all datasets will be deleted.
  161. ### Response
  162. Success:
  163. ```json
  164. {
  165. "code": 0
  166. }
  167. ```
  168. Failure:
  169. ```json
  170. {
  171. "code": 102,
  172. "message": "You don't own the dataset."
  173. }
  174. ```
  175. ---
  176. ## Update dataset
  177. **PUT** `/api/v1/datasets/{dataset_id}`
  178. Updates configurations for a specified dataset.
  179. ### Request
  180. - Method: PUT
  181. - URL: `/api/v1/datasets/{dataset_id}`
  182. - Headers:
  183. - `'content-Type: application/json'`
  184. - `'Authorization: Bearer <YOUR_API_KEY>'`
  185. - Body:
  186. - `"name"`: `string`
  187. - `"embedding_model"`: `string`
  188. - `"chunk_method"`: `enum<string>`
  189. #### Request example
  190. ```bash
  191. curl --request PUT \
  192. --url http://{address}/api/v1/datasets/{dataset_id} \
  193. --header 'Content-Type: application/json' \
  194. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  195. --data '
  196. {
  197. "name": "updated_dataset",
  198. }'
  199. ```
  200. #### Request parameters
  201. - `dataset_id`: (*Path parameter*)
  202. The ID of the dataset to update.
  203. - `"name"`: (*Body parameter*), `string`
  204. The revised name of the dataset.
  205. - `"embedding_model"`: (*Body parameter*), `string`
  206. The updated embedding model name.
  207. - Ensure that `"chunk_count"` is `0` before updating `"embedding_model"`.
  208. - `"chunk_method"`: (*Body parameter*), `enum<string>`
  209. The chunking method for the dataset. Available options:
  210. - `"naive"`: General
  211. - `"manual`: Manual
  212. - `"qa"`: Q&A
  213. - `"table"`: Table
  214. - `"paper"`: Paper
  215. - `"book"`: Book
  216. - `"laws"`: Laws
  217. - `"presentation"`: Presentation
  218. - `"picture"`: Picture
  219. - `"one"`:One
  220. - `"email"`: Email
  221. - `"knowledge_graph"`: Knowledge Graph
  222. 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!
  223. ### Response
  224. Success:
  225. ```json
  226. {
  227. "code": 0
  228. }
  229. ```
  230. Failure:
  231. ```json
  232. {
  233. "code": 102,
  234. "message": "Can't change tenant_id."
  235. }
  236. ```
  237. ---
  238. ## List datasets
  239. **GET** `/api/v1/datasets?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
  240. Lists datasets.
  241. ### Request
  242. - Method: GET
  243. - URL: `/api/v1/datasets?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
  244. - Headers:
  245. - `'Authorization: Bearer <YOUR_API_KEY>'`
  246. #### Request example
  247. ```bash
  248. curl --request GET \
  249. --url http://{address}/api/v1/datasets?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id} \
  250. --header 'Authorization: Bearer <YOUR_API_KEY>'
  251. ```
  252. #### Request parameters
  253. - `page`: (*Filter parameter*)
  254. Specifies the page on which the datasets will be displayed. Defaults to `1`.
  255. - `page_size`: (*Filter parameter*)
  256. The number of datasets on each page. Defaults to `30`.
  257. - `orderby`: (*Filter parameter*)
  258. The field by which datasets should be sorted. Available options:
  259. - `create_time` (default)
  260. - `update_time`
  261. - `desc`: (*Filter parameter*)
  262. Indicates whether the retrieved datasets should be sorted in descending order. Defaults to `true`.
  263. - `name`: (*Filter parameter*)
  264. The name of the dataset to retrieve.
  265. - `id`: (*Filter parameter*)
  266. The ID of the dataset to retrieve.
  267. ### Response
  268. Success:
  269. ```json
  270. {
  271. "code": 0,
  272. "data": [
  273. {
  274. "avatar": "",
  275. "chunk_count": 59,
  276. "create_date": "Sat, 14 Sep 2024 01:12:37 GMT",
  277. "create_time": 1726276357324,
  278. "created_by": "69736c5e723611efb51b0242ac120007",
  279. "description": null,
  280. "document_count": 1,
  281. "embedding_model": "BAAI/bge-large-zh-v1.5",
  282. "id": "6e211ee0723611efa10a0242ac120007",
  283. "language": "English",
  284. "name": "mysql",
  285. "chunk_method": "knowledge_graph",
  286. "parser_config": {
  287. "chunk_token_num": 8192,
  288. "delimiter": "\\n!?;。;!?",
  289. "entity_types": [
  290. "organization",
  291. "person",
  292. "location",
  293. "event",
  294. "time"
  295. ]
  296. },
  297. "permission": "me",
  298. "similarity_threshold": 0.2,
  299. "status": "1",
  300. "tenant_id": "69736c5e723611efb51b0242ac120007",
  301. "token_num": 12744,
  302. "update_date": "Thu, 10 Oct 2024 04:07:23 GMT",
  303. "update_time": 1728533243536,
  304. "vector_similarity_weight": 0.3
  305. }
  306. ]
  307. }
  308. ```
  309. Failure:
  310. ```json
  311. {
  312. "code": 102,
  313. "message": "The dataset doesn't exist"
  314. }
  315. ```
  316. ---
  317. :::tip API GROUPING
  318. File Management within Dataset
  319. :::
  320. ---
  321. ## Upload documents
  322. **POST** `/api/v1/datasets/{dataset_id}/documents`
  323. Uploads documents to a specified dataset.
  324. ### Request
  325. - Method: POST
  326. - URL: `/api/v1/datasets/{dataset_id}/documents`
  327. - Headers:
  328. - `'Content-Type: multipart/form-data'`
  329. - `'Authorization: Bearer <YOUR_API_KEY>'`
  330. - Form:
  331. - `'file=@{FILE_PATH}'`
  332. #### Request example
  333. ```bash
  334. curl --request POST \
  335. --url http://{address}/api/v1/datasets/{dataset_id}/documents \
  336. --header 'Content-Type: multipart/form-data' \
  337. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  338. --form 'file=@./test1.txt' \
  339. --form 'file=@./test2.pdf'
  340. ```
  341. #### Request parameters
  342. - `dataset_id`: (*Path parameter*)
  343. The ID of the dataset to which the documents will be uploaded.
  344. - `'file'`: (*Body parameter*)
  345. A document to upload.
  346. ### Response
  347. Success:
  348. ```json
  349. {
  350. "code": 0,
  351. "data": [
  352. {
  353. "chunk_method": "naive",
  354. "created_by": "69736c5e723611efb51b0242ac120007",
  355. "dataset_id": "527fa74891e811ef9c650242ac120006",
  356. "id": "b330ec2e91ec11efbc510242ac120004",
  357. "location": "1.txt",
  358. "name": "1.txt",
  359. "parser_config": {
  360. "chunk_token_num": 128,
  361. "delimiter": "\\n!?;。;!?",
  362. "html4excel": false,
  363. "layout_recognize": true,
  364. "raptor": {
  365. "user_raptor": false
  366. }
  367. },
  368. "run": "UNSTART",
  369. "size": 17966,
  370. "thumbnail": "",
  371. "type": "doc"
  372. }
  373. ]
  374. }
  375. ```
  376. Failure:
  377. ```json
  378. {
  379. "code": 101,
  380. "message": "No file part!"
  381. }
  382. ```
  383. ---
  384. ## Update document
  385. **PUT** `/api/v1/datasets/{dataset_id}/documents/{document_id}`
  386. Updates configurations for a specified document.
  387. ### Request
  388. - Method: PUT
  389. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}`
  390. - Headers:
  391. - `'content-Type: application/json'`
  392. - `'Authorization: Bearer <YOUR_API_KEY>'`
  393. - Body:
  394. - `"name"`:`string`
  395. - `"chunk_method"`:`string`
  396. - `"parser_config"`:`object`
  397. #### Request example
  398. ```bash
  399. curl --request PUT \
  400. --url http://{address}/api/v1/datasets/{dataset_id}/info/{document_id} \
  401. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  402. --header 'Content-Type: application/json' \
  403. --data '
  404. {
  405. "name": "manual.txt",
  406. "chunk_method": "manual",
  407. "parser_config": {"chunk_token_count": 128}
  408. }'
  409. ```
  410. #### Request parameters
  411. - `dataset_id`: (*Path parameter*)
  412. The ID of the associated dataset.
  413. - `document_id`: (*Path parameter*)
  414. The ID of the document to update.
  415. - `"name"`: (*Body parameter*), `string`
  416. - `"chunk_method"`: (*Body parameter*), `string`
  417. The parsing method to apply to the document:
  418. - `"naive"`: General
  419. - `"manual`: Manual
  420. - `"qa"`: Q&A
  421. - `"table"`: Table
  422. - `"paper"`: Paper
  423. - `"book"`: Book
  424. - `"laws"`: Laws
  425. - `"presentation"`: Presentation
  426. - `"picture"`: Picture
  427. - `"one"`: One
  428. - `"knowledge_graph"`: Knowledge Graph
  429. 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!
  430. - `"email"`: Email
  431. - `"parser_config"`: (*Body parameter*), `object`
  432. The configuration settings for the dataset parser. The attributes in this JSON object vary with the selected `"chunk_method"`:
  433. - If `"chunk_method"` is `"naive"`, the `"parser_config"` object contains the following attributes:
  434. - `"chunk_token_count"`: Defaults to `128`.
  435. - `"layout_recognize"`: Defaults to `true`.
  436. - `"html4excel"`: Indicates whether to convert Excel documents into HTML format. Defaults to `false`.
  437. - `"delimiter"`: Defaults to `"\n!?。;!?"`.
  438. - `"task_page_size"`: Defaults to `12`. For PDF only.
  439. - `"raptor"`: Raptor-specific settings. Defaults to: `{"use_raptor": false}`.
  440. - If `"chunk_method"` is `"qa"`, `"manuel"`, `"paper"`, `"book"`, `"laws"`, or `"presentation"`, the `"parser_config"` object contains the following attribute:
  441. - `"raptor"`: Raptor-specific settings. Defaults to: `{"use_raptor": false}`.
  442. - If `"chunk_method"` is `"table"`, `"picture"`, `"one"`, or `"email"`, `"parser_config"` is an empty JSON object.
  443. - If `"chunk_method"` is `"knowledge_graph"`, the `"parser_config"` object contains the following attributes:
  444. - `"chunk_token_count"`: Defaults to `128`.
  445. - `"delimiter"`: Defaults to `"\n!?。;!?"`.
  446. - `"entity_types"`: Defaults to `["organization","person","location","event","time"]`
  447. ### Response
  448. Success:
  449. ```json
  450. {
  451. "code": 0
  452. }
  453. ```
  454. Failure:
  455. ```json
  456. {
  457. "code": 102,
  458. "message": "The dataset does not have the document."
  459. }
  460. ```
  461. ---
  462. ## Download document
  463. **GET** `/api/v1/datasets/{dataset_id}/documents/{document_id}`
  464. Downloads a document from a specified dataset.
  465. ### Request
  466. - Method: GET
  467. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}`
  468. - Headers:
  469. - `'Authorization: Bearer <YOUR_API_KEY>'`
  470. - Output:
  471. - `'{PATH_TO_THE_FILE}'`
  472. #### Request example
  473. ```bash
  474. curl --request GET \
  475. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id} \
  476. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  477. --output ./ragflow.txt
  478. ```
  479. #### Request parameters
  480. - `dataset_id`: (*Path parameter*)
  481. The associated dataset ID.
  482. - `documents_id`: (*Path parameter*)
  483. The ID of the document to download.
  484. ### Response
  485. Success:
  486. ```text
  487. This is a test to verify the file download feature.
  488. ```
  489. Failure:
  490. ```json
  491. {
  492. "code": 102,
  493. "message": "You do not own the dataset 7898da028a0511efbf750242ac1220005."
  494. }
  495. ```
  496. ---
  497. ## List documents
  498. **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}`
  499. Lists documents in a specified dataset.
  500. ### Request
  501. - Method: GET
  502. - 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}`
  503. - Headers:
  504. - `'content-Type: application/json'`
  505. - `'Authorization: Bearer <YOUR_API_KEY>'`
  506. #### Request example
  507. ```bash
  508. curl --request GET \
  509. --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} \
  510. --header 'Authorization: Bearer <YOUR_API_KEY>'
  511. ```
  512. #### Request parameters
  513. - `dataset_id`: (*Path parameter*)
  514. The associated dataset ID.
  515. - `keywords`: (*Filter parameter*), `string`
  516. The keywords used to match document titles.
  517. - `page`: (*Filter parameter*), `integer`
  518. Specifies the page on which the documents will be displayed. Defaults to `1`.
  519. - `page_size`: (*Filter parameter*), `integer`
  520. The maximum number of documents on each page. Defaults to `30`.
  521. - `orderby`: (*Filter parameter*), `string`
  522. The field by which documents should be sorted. Available options:
  523. - `create_time` (default)
  524. - `update_time`
  525. - `desc`: (*Filter parameter*), `boolean`
  526. Indicates whether the retrieved documents should be sorted in descending order. Defaults to `true`.
  527. - `id`: (*Filter parameter*), `string`
  528. The ID of the document to retrieve.
  529. ### Response
  530. Success:
  531. ```json
  532. {
  533. "code": 0,
  534. "data": {
  535. "docs": [
  536. {
  537. "chunk_count": 0,
  538. "create_date": "Mon, 14 Oct 2024 09:11:01 GMT",
  539. "create_time": 1728897061948,
  540. "created_by": "69736c5e723611efb51b0242ac120007",
  541. "id": "3bcfbf8a8a0c11ef8aba0242ac120006",
  542. "knowledgebase_id": "7898da028a0511efbf750242ac120005",
  543. "location": "Test_2.txt",
  544. "name": "Test_2.txt",
  545. "parser_config": {
  546. "chunk_token_count": 128,
  547. "delimiter": "\n!?。;!?",
  548. "layout_recognize": true,
  549. "task_page_size": 12
  550. },
  551. "chunk_method": "naive",
  552. "process_begin_at": null,
  553. "process_duation": 0.0,
  554. "progress": 0.0,
  555. "progress_msg": "",
  556. "run": "0",
  557. "size": 7,
  558. "source_type": "local",
  559. "status": "1",
  560. "thumbnail": null,
  561. "token_count": 0,
  562. "type": "doc",
  563. "update_date": "Mon, 14 Oct 2024 09:11:01 GMT",
  564. "update_time": 1728897061948
  565. }
  566. ],
  567. "total": 1
  568. }
  569. }
  570. ```
  571. Failure:
  572. ```json
  573. {
  574. "code": 102,
  575. "message": "You don't own the dataset 7898da028a0511efbf750242ac1220005. "
  576. }
  577. ```
  578. ---
  579. ## Delete documents
  580. **DELETE** `/api/v1/datasets/{dataset_id}/documents`
  581. Deletes documents by ID.
  582. ### Request
  583. - Method: DELETE
  584. - URL: `/api/v1/datasets/{dataset_id}/documents`
  585. - Headers:
  586. - `'Content-Type: application/json'`
  587. - `'Authorization: Bearer <YOUR_API_KEY>'`
  588. - Body:
  589. - `"ids"`: `list[string]`
  590. #### Request example
  591. ```bash
  592. curl --request DELETE \
  593. --url http://{address}/api/v1/datasets/{dataset_id}/documents \
  594. --header 'Content-Type: application/json' \
  595. --header 'Authorization: <YOUR_API_KEY>' \
  596. --data '
  597. {
  598. "ids": ["id_1","id_2"]
  599. }'
  600. ```
  601. #### Request parameters
  602. - `dataset_id`: (*Path parameter*)
  603. The associated dataset ID.
  604. - `"ids"`: (*Body parameter*), `list[string]`
  605. The IDs of the documents to delete. If it is not specified, all documents in the specified dataset will be deleted.
  606. ### Response
  607. Success:
  608. ```json
  609. {
  610. "code": 0
  611. }.
  612. ```
  613. Failure:
  614. ```json
  615. {
  616. "code": 102,
  617. "message": "You do not own the dataset 7898da028a0511efbf750242ac1220005."
  618. }
  619. ```
  620. ---
  621. ## Parse documents
  622. **POST** `/api/v1/datasets/{dataset_id}/chunks`
  623. Parses documents in a specified dataset.
  624. ### Request
  625. - Method: POST
  626. - URL: `/api/v1/datasets/{dataset_id}/chunks`
  627. - Headers:
  628. - `'content-Type: application/json'`
  629. - `'Authorization: Bearer <YOUR_API_KEY>'`
  630. - Body:
  631. - `"document_ids"`: `list[string]`
  632. #### Request example
  633. ```bash
  634. curl --request POST \
  635. --url http://{address}/api/v1/datasets/{dataset_id}/chunks \
  636. --header 'Content-Type: application/json' \
  637. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  638. --data '
  639. {
  640. "document_ids": ["97a5f1c2759811efaa500242ac120004","97ad64b6759811ef9fc30242ac120004"]
  641. }'
  642. ```
  643. #### Request parameters
  644. - `dataset_id`: (*Path parameter*)
  645. The dataset ID.
  646. - `"document_ids"`: (*Body parameter*), `list[string]`, *Required*
  647. The IDs of the documents to parse.
  648. ### Response
  649. Success:
  650. ```json
  651. {
  652. "code": 0
  653. }
  654. ```
  655. Failure:
  656. ```json
  657. {
  658. "code": 102,
  659. "message": "`document_ids` is required"
  660. }
  661. ```
  662. ---
  663. ## Stop parsing documents
  664. **DELETE** `/api/v1/datasets/{dataset_id}/chunks`
  665. Stops parsing specified documents.
  666. ### Request
  667. - Method: DELETE
  668. - URL: `/api/v1/datasets/{dataset_id}/chunks`
  669. - Headers:
  670. - `'content-Type: application/json'`
  671. - `'Authorization: Bearer <YOUR_API_KEY>'`
  672. - Body:
  673. - `"document_ids"`: `list[string]`
  674. #### Request example
  675. ```bash
  676. curl --request DELETE \
  677. --url http://{address}/api/v1/datasets/{dataset_id}/chunks \
  678. --header 'Content-Type: application/json' \
  679. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  680. --data '
  681. {
  682. "document_ids": ["97a5f1c2759811efaa500242ac120004","97ad64b6759811ef9fc30242ac120004"]
  683. }'
  684. ```
  685. #### Request parameters
  686. - `dataset_id`: (*Path parameter*)
  687. The associated dataset ID.
  688. - `"document_ids"`: (*Body parameter*), `list[string]`, *Required*
  689. The IDs of the documents for which the parsing should be stopped.
  690. ### Response
  691. Success:
  692. ```json
  693. {
  694. "code": 0
  695. }
  696. ```
  697. Failure:
  698. ```json
  699. {
  700. "code": 102,
  701. "message": "`document_ids` is required"
  702. }
  703. ```
  704. ---
  705. ## Add chunks
  706. **POST** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
  707. Adds a chunk to a specified document in a specified dataset.
  708. ### Request
  709. - Method: POST
  710. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
  711. - Headers:
  712. - `'content-Type: application/json'`
  713. - `'Authorization: Bearer <YOUR_API_KEY>'`
  714. - Body:
  715. - `"content"`: `string`
  716. - `"important_keywords"`: `list[string]`
  717. #### Request example
  718. ```bash
  719. curl --request POST \
  720. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks \
  721. --header 'Content-Type: application/json' \
  722. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  723. --data '
  724. {
  725. "content": "<SOME_CHUNK_CONTENT_HERE>"
  726. }'
  727. ```
  728. #### Request parameters
  729. - `dataset_id`: (*Path parameter*)
  730. The associated dataset ID.
  731. - `document_ids`: (*Path parameter*)
  732. The associated document ID.
  733. - `"content"`: (*Body parameter*), `string`, *Required*
  734. The text content of the chunk.
  735. - `"important_keywords`(*Body parameter*), `list[string]`
  736. The key terms or phrases to tag with the chunk.
  737. ### Response
  738. Success:
  739. ```json
  740. {
  741. "code": 0,
  742. "data": {
  743. "chunk": {
  744. "content": "ragflow content",
  745. "create_time": "2024-10-16 08:05:04",
  746. "create_timestamp": 1729065904.581025,
  747. "dataset_id": [
  748. "c7ee74067a2c11efb21c0242ac120006"
  749. ],
  750. "document_id": "5c5999ec7be811ef9cab0242ac120005",
  751. "id": "d78435d142bd5cf6704da62c778795c5",
  752. "important_keywords": []
  753. }
  754. }
  755. }
  756. ```
  757. Failure:
  758. ```json
  759. {
  760. "code": 102,
  761. "message": "`content` is required"
  762. }
  763. ```
  764. ---
  765. ## List chunks
  766. **GET** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks?keywords={keywords}&page={page}&page_size={page_size}&id={id}`
  767. Lists chunks in a specified document.
  768. ### Request
  769. - Method: GET
  770. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks?keywords={keywords}&page={page}&page_size={page_size}&id={chunk_id}`
  771. - Headers:
  772. - `'Authorization: Bearer <YOUR_API_KEY>'`
  773. #### Request example
  774. ```bash
  775. curl --request GET \
  776. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks?keywords={keywords}&page={page}&page_size={page_size}&id={chunk_id} \
  777. --header 'Authorization: Bearer <YOUR_API_KEY>'
  778. ```
  779. #### Request parameters
  780. - `dataset_id`: (*Path parameter*)
  781. The associated dataset ID.
  782. - `document_ids`: (*Path parameter*)
  783. The associated document ID.
  784. - `keywords`(*Filter parameter*), `string`
  785. The keywords used to match chunk content.
  786. - `page`(*Filter parameter*), `integer`
  787. Specifies the page on which the chunks will be displayed. Defaults to `1`.
  788. - `page_size`(*Filter parameter*), `integer`
  789. The maximum number of chunks on each page. Defaults to `1024`.
  790. - `id`(*Filter parameter*), `string`
  791. The ID of the chunk to retrieve.
  792. ### Response
  793. Success:
  794. ```json
  795. {
  796. "code": 0,
  797. "data": {
  798. "chunks": [
  799. {
  800. "available_int": 1,
  801. "content": "This is a test content.",
  802. "docnm_kwd": "1.txt",
  803. "document_id": "b330ec2e91ec11efbc510242ac120004",
  804. "id": "b48c170e90f70af998485c1065490726",
  805. "image_id": "",
  806. "important_keywords": "",
  807. "positions": [
  808. ""
  809. ]
  810. }
  811. ],
  812. "doc": {
  813. "chunk_count": 1,
  814. "chunk_method": "naive",
  815. "create_date": "Thu, 24 Oct 2024 09:45:27 GMT",
  816. "create_time": 1729763127646,
  817. "created_by": "69736c5e723611efb51b0242ac120007",
  818. "dataset_id": "527fa74891e811ef9c650242ac120006",
  819. "id": "b330ec2e91ec11efbc510242ac120004",
  820. "location": "1.txt",
  821. "name": "1.txt",
  822. "parser_config": {
  823. "chunk_token_num": 128,
  824. "delimiter": "\\n!?;。;!?",
  825. "html4excel": false,
  826. "layout_recognize": true,
  827. "raptor": {
  828. "user_raptor": false
  829. }
  830. },
  831. "process_begin_at": "Thu, 24 Oct 2024 09:56:44 GMT",
  832. "process_duation": 0.54213,
  833. "progress": 0.0,
  834. "progress_msg": "Task dispatched...",
  835. "run": "2",
  836. "size": 17966,
  837. "source_type": "local",
  838. "status": "1",
  839. "thumbnail": "",
  840. "token_count": 8,
  841. "type": "doc",
  842. "update_date": "Thu, 24 Oct 2024 11:03:15 GMT",
  843. "update_time": 1729767795721
  844. },
  845. "total": 1
  846. }
  847. }
  848. ```
  849. Failure:
  850. ```json
  851. {
  852. "code": 102,
  853. "message": "You don't own the document 5c5999ec7be811ef9cab0242ac12000e5."
  854. }
  855. ```
  856. ---
  857. ## Delete chunks
  858. **DELETE** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
  859. Deletes chunks by ID.
  860. ### Request
  861. - Method: DELETE
  862. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
  863. - Headers:
  864. - `'content-Type: application/json'`
  865. - `'Authorization: Bearer <YOUR_API_KEY>'`
  866. - Body:
  867. - `"chunk_ids"`: `list[string]`
  868. #### Request example
  869. ```bash
  870. curl --request DELETE \
  871. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks \
  872. --header 'Content-Type: application/json' \
  873. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  874. --data '
  875. {
  876. "chunk_ids": ["test_1", "test_2"]
  877. }'
  878. ```
  879. #### Request parameters
  880. - `dataset_id`: (*Path parameter*)
  881. The associated dataset ID.
  882. - `document_ids`: (*Path parameter*)
  883. The associated document ID.
  884. - `"chunk_ids"`: (*Body parameter*), `list[string]`
  885. The IDs of the chunks to delete. If it is not specified, all chunks of the specified document will be deleted.
  886. ### Response
  887. Success:
  888. ```json
  889. {
  890. "code": 0
  891. }
  892. ```
  893. Failure:
  894. ```json
  895. {
  896. "code": 102,
  897. "message": "`chunk_ids` is required"
  898. }
  899. ```
  900. ---
  901. ## Update chunk
  902. **PUT** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks/{chunk_id}`
  903. Updates content or configurations for a specified chunk.
  904. ### Request
  905. - Method: PUT
  906. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks/{chunk_id}`
  907. - Headers:
  908. - `'content-Type: application/json'`
  909. - `'Authorization: Bearer <YOUR_API_KEY>'`
  910. - Body:
  911. - `"content"`: `string`
  912. - `"important_keywords"`: `list[string]`
  913. - `"available"`: `boolean`
  914. #### Request example
  915. ```bash
  916. curl --request PUT \
  917. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks/{chunk_id} \
  918. --header 'Content-Type: application/json' \
  919. --header 'Authorization: <YOUR_API_KEY>' \
  920. --data '
  921. {
  922. "content": "ragflow123",
  923. "important_keywords": [],
  924. }'
  925. ```
  926. #### Request parameters
  927. - `dataset_id`: (*Path parameter*)
  928. The associated dataset ID.
  929. - `document_ids`: (*Path parameter*)
  930. The associated document ID.
  931. - `chunk_id`: (*Path parameter*)
  932. The ID of the chunk to update.
  933. - `"content"`: (*Body parameter*), `string`
  934. The text content of the chunk.
  935. - `"important_keywords"`: (*Body parameter*), `list[string]`
  936. A list of key terms or phrases to tag with the chunk.
  937. - `"available"`: (*Body parameter*) `boolean`
  938. The chunk's availability status in the dataset. Value options:
  939. - `true`: Available (default)
  940. - `false`: Unavailable
  941. ### Response
  942. Success:
  943. ```json
  944. {
  945. "code": 0
  946. }
  947. ```
  948. Failure:
  949. ```json
  950. {
  951. "code": 102,
  952. "message": "Can't find this chunk 29a2d9987e16ba331fb4d7d30d99b71d2"
  953. }
  954. ```
  955. ---
  956. ## Retrieve chunks
  957. **POST** `/api/v1/retrieval`
  958. Retrieves chunks from specified datasets.
  959. ### Request
  960. - Method: POST
  961. - URL: `/api/v1/retrieval`
  962. - Headers:
  963. - `'content-Type: application/json'`
  964. - `'Authorization: Bearer <YOUR_API_KEY>'`
  965. - Body:
  966. - `"question"`: `string`
  967. - `"dataset_ids"`: `list[string]`
  968. - `"document_ids"`: `list[string]`
  969. - `"page"`: `integer`
  970. - `"page_size"`: `integer`
  971. - `"similarity_threshold"`: `float`
  972. - `"vector_similarity_weight"`: `float`
  973. - `"top_k"`: `integer`
  974. - `"rerank_id"`: `string`
  975. - `"keyword"`: `boolean`
  976. - `"highlight"`: `boolean`
  977. #### Request example
  978. ```bash
  979. curl --request POST \
  980. --url http://{address}/api/v1/retrieval \
  981. --header 'Content-Type: application/json' \
  982. --header 'Authorization: <YOUR_API_KEY>' \
  983. --data '
  984. {
  985. "question": "What is advantage of ragflow?",
  986. "dataset_ids": ["b2a62730759d11ef987d0242ac120004"],
  987. "document_ids": ["77df9ef4759a11ef8bdd0242ac120004"]
  988. }'
  989. ```
  990. #### Request parameter
  991. - `"question"`: (*Body parameter*), `string`, *Required*
  992. The user query or query keywords.
  993. - `"dataset_ids"`: (*Body parameter*) `list[string]`
  994. The IDs of the datasets to search. If you do not set this argument, ensure that you set `"document_ids"`.
  995. - `"document_ids"`: (*Body parameter*), `list[string]`
  996. 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"`.
  997. - `"page"`: (*Body parameter*), `integer`
  998. Specifies the page on which the chunks will be displayed. Defaults to `1`.
  999. - `"page_size"`: (*Body parameter*)
  1000. The maximum number of chunks on each page. Defaults to `30`.
  1001. - `"similarity_threshold"`: (*Body parameter*)
  1002. The minimum similarity score. Defaults to `0.2`.
  1003. - `"vector_similarity_weight"`: (*Body parameter*), `float`
  1004. 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.
  1005. - `"top_k"`: (*Body parameter*), `integer`
  1006. The number of chunks engaged in vector cosine computaton. Defaults to `1024`.
  1007. - `"rerank_id"`: (*Body parameter*), `integer`
  1008. The ID of the rerank model.
  1009. - `"keyword"`: (*Body parameter*), `boolean`
  1010. Indicates whether to enable keyword-based matching:
  1011. - `true`: Enable keyword-based matching.
  1012. - `false`: Disable keyword-based matching (default).
  1013. - `"highlight"`: (*Body parameter*), `boolean`
  1014. Specifies whether to enable highlighting of matched terms in the results:
  1015. - `true`: Enable highlighting of matched terms.
  1016. - `false`: Disable highlighting of matched terms (default).
  1017. ### Response
  1018. Success:
  1019. ```json
  1020. {
  1021. "code": 0,
  1022. "data": {
  1023. "chunks": [
  1024. {
  1025. "content": "ragflow content",
  1026. "content_ltks": "ragflow content",
  1027. "document_id": "5c5999ec7be811ef9cab0242ac120005",
  1028. "document_keyword": "1.txt",
  1029. "highlight": "<em>ragflow</em> content",
  1030. "id": "d78435d142bd5cf6704da62c778795c5",
  1031. "img_id": "",
  1032. "important_keywords": [
  1033. ""
  1034. ],
  1035. "kb_id": "c7ee74067a2c11efb21c0242ac120006",
  1036. "positions": [
  1037. ""
  1038. ],
  1039. "similarity": 0.9669436601210759,
  1040. "term_similarity": 1.0,
  1041. "vector_similarity": 0.8898122004035864
  1042. }
  1043. ],
  1044. "doc_aggs": [
  1045. {
  1046. "count": 1,
  1047. "doc_id": "5c5999ec7be811ef9cab0242ac120005",
  1048. "doc_name": "1.txt"
  1049. }
  1050. ],
  1051. "total": 1
  1052. }
  1053. }
  1054. ```
  1055. Failure:
  1056. ```json
  1057. {
  1058. "code": 102,
  1059. "message": "`datasets` is required."
  1060. }
  1061. ```
  1062. ---
  1063. :::tip API GROUPING
  1064. Chat Assistant Management
  1065. :::
  1066. ---
  1067. ## Create chat assistant
  1068. **POST** `/api/v1/chats`
  1069. Creates a chat assistant.
  1070. ### Request
  1071. - Method: POST
  1072. - URL: `/api/v1/chats`
  1073. - Headers:
  1074. - `'content-Type: application/json'`
  1075. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1076. - Body:
  1077. - `"name"`: `string`
  1078. - `"avatar"`: `string`
  1079. - `"dataset_ids"`: `list[string]`
  1080. - `"llm"`: `object`
  1081. - `"prompt"`: `object`
  1082. #### Request example
  1083. ```shell
  1084. curl --request POST \
  1085. --url http://{address}/api/v1/chats \
  1086. --header 'Content-Type: application/json' \
  1087. --header 'Authorization: Bearer <YOUR_API_KEY>'
  1088. --data '{
  1089. "dataset_ids": ["0b2cbc8c877f11ef89070242ac120005"],
  1090. "name":"new_chat_1"
  1091. }'
  1092. ```
  1093. #### Request parameters
  1094. - `"name"`: (*Body parameter*), `string`, *Required*
  1095. The name of the chat assistant.
  1096. - `"avatar"`: (*Body parameter*), `string`
  1097. Base64 encoding of the avatar.
  1098. - `"dataset_ids"`: (*Body parameter*), `list[string]`
  1099. The IDs of the associated datasets.
  1100. - `"llm"`: (*Body parameter*), `object`
  1101. 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:
  1102. - `"model_name"`, `string`
  1103. The chat model name. If not set, the user's default chat model will be used.
  1104. - `"temperature"`: `float`
  1105. Controls the randomness of the model's predictions. A lower temperature increases the model's confidence in its responses; a higher temperature increases creativity and diversity. Defaults to `0.1`.
  1106. - `"top_p"`: `float`
  1107. 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`
  1108. - `"presence_penalty"`: `float`
  1109. This discourages the model from repeating the same information by penalizing words that have already appeared in the conversation. Defaults to `0.2`.
  1110. - `"frequency penalty"`: `float`
  1111. Similar to the presence penalty, this reduces the model’s tendency to repeat the same words frequently. Defaults to `0.7`.
  1112. - `"max_token"`: `integer`
  1113. The maximum length of the model’s output, measured in the number of tokens (words or pieces of words). Defaults to `512`.
  1114. - `"prompt"`: (*Body parameter*), `object`
  1115. 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:
  1116. - `"similarity_threshold"`: `float` RAGFlow uses a hybrid of weighted keyword similarity and vector cosine similarity 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`.
  1117. - `"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`.
  1118. - `"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`.
  1119. - `"variables"`: `object[]` This argument lists the variables to use in the 'System' field of **Chat Configurations**. Note that:
  1120. - `"knowledge"` is a reserved variable, which represents the retrieved chunks.
  1121. - All the variables in 'System' should be curly bracketed.
  1122. - The default value is `[{"key": "knowledge", "optional": true}]`.
  1123. - `"rerank_model"`: `string` If it is not specified, vector cosine similarity will be used; otherwise, reranking score will be used.
  1124. - `"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.
  1125. - `"opener"`: `string` The opening greeting for the user. Defaults to `"Hi! I am your assistant, can I help you?"`.
  1126. - `"show_quote`: `boolean` Indicates whether the source of text should be displayed. Defaults to `true`.
  1127. - `"prompt"`: `string` The prompt content.
  1128. ### Response
  1129. Success:
  1130. ```json
  1131. {
  1132. "code": 0,
  1133. "data": {
  1134. "avatar": "",
  1135. "create_date": "Thu, 24 Oct 2024 11:18:29 GMT",
  1136. "create_time": 1729768709023,
  1137. "dataset_ids": [
  1138. "527fa74891e811ef9c650242ac120006"
  1139. ],
  1140. "description": "A helpful Assistant",
  1141. "do_refer": "1",
  1142. "id": "b1f2f15691f911ef81180242ac120003",
  1143. "language": "English",
  1144. "llm": {
  1145. "frequency_penalty": 0.7,
  1146. "max_tokens": 512,
  1147. "model_name": "qwen-plus@Tongyi-Qianwen",
  1148. "presence_penalty": 0.4,
  1149. "temperature": 0.1,
  1150. "top_p": 0.3
  1151. },
  1152. "name": "12234",
  1153. "prompt": {
  1154. "empty_response": "Sorry! No relevant content was found in the knowledge base!",
  1155. "keywords_similarity_weight": 0.3,
  1156. "opener": "Hi! I'm your assistant, what can I do for you?",
  1157. "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 ",
  1158. "rerank_model": "",
  1159. "similarity_threshold": 0.2,
  1160. "top_n": 6,
  1161. "variables": [
  1162. {
  1163. "key": "knowledge",
  1164. "optional": false
  1165. }
  1166. ]
  1167. },
  1168. "prompt_type": "simple",
  1169. "status": "1",
  1170. "tenant_id": "69736c5e723611efb51b0242ac120007",
  1171. "top_k": 1024,
  1172. "update_date": "Thu, 24 Oct 2024 11:18:29 GMT",
  1173. "update_time": 1729768709023
  1174. }
  1175. }
  1176. ```
  1177. Failure:
  1178. ```json
  1179. {
  1180. "code": 102,
  1181. "message": "Duplicated chat name in creating dataset."
  1182. }
  1183. ```
  1184. ---
  1185. ## Update chat assistant
  1186. **PUT** `/api/v1/chats/{chat_id}`
  1187. Updates configurations for a specified chat assistant.
  1188. ### Request
  1189. - Method: PUT
  1190. - URL: `/api/v1/chats/{chat_id}`
  1191. - Headers:
  1192. - `'content-Type: application/json'`
  1193. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1194. - Body:
  1195. - `"name"`: `string`
  1196. - `"avatar"`: `string`
  1197. - `"dataset_ids"`: `list[string]`
  1198. - `"llm"`: `object`
  1199. - `"prompt"`: `object`
  1200. #### Request example
  1201. ```bash
  1202. curl --request PUT \
  1203. --url http://{address}/api/v1/chats/{chat_id} \
  1204. --header 'Content-Type: application/json' \
  1205. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1206. --data '
  1207. {
  1208. "name":"Test"
  1209. }'
  1210. ```
  1211. #### Parameters
  1212. - `chat_id`: (*Path parameter*)
  1213. The ID of the chat assistant to update.
  1214. - `"name"`: (*Body parameter*), `string`, *Required*
  1215. The revised name of the chat assistant.
  1216. - `"avatar"`: (*Body parameter*), `string`
  1217. Base64 encoding of the avatar.
  1218. - `"dataset_ids"`: (*Body parameter*), `list[string]`
  1219. The IDs of the associated datasets.
  1220. - `"llm"`: (*Body parameter*), `object`
  1221. 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:
  1222. - `"model_name"`, `string`
  1223. The chat model name. If not set, the user's default chat model will be used.
  1224. - `"temperature"`: `float`
  1225. Controls the randomness of the model's predictions. A lower temperature increases the model's confidence in its responses; a higher temperature increases creativity and diversity. Defaults to `0.1`.
  1226. - `"top_p"`: `float`
  1227. 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`
  1228. - `"presence_penalty"`: `float`
  1229. This discourages the model from repeating the same information by penalizing words that have already appeared in the conversation. Defaults to `0.2`.
  1230. - `"frequency penalty"`: `float`
  1231. Similar to the presence penalty, this reduces the model’s tendency to repeat the same words frequently. Defaults to `0.7`.
  1232. - `"max_token"`: `integer`
  1233. The maximum length of the model’s output, measured in the number of tokens (words or pieces of words). Defaults to `512`.
  1234. - `"prompt"`: (*Body parameter*), `object`
  1235. Instructions for the LLM to follow. A `prompt` object contains the following attributes:
  1236. - `"similarity_threshold"`: `float` RAGFlow uses a hybrid of weighted keyword similarity and vector cosine similarity 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`.
  1237. - `"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`.
  1238. - `"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`.
  1239. - `"variables"`: `object[]` This argument lists the variables to use in the 'System' field of **Chat Configurations**. Note that:
  1240. - `"knowledge"` is a reserved variable, which represents the retrieved chunks.
  1241. - All the variables in 'System' should be curly bracketed.
  1242. - The default value is `[{"key": "knowledge", "optional": true}]`
  1243. - `"rerank_model"`: `string` If it is not specified, vector cosine similarity will be used; otherwise, reranking score will be used.
  1244. - `"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.
  1245. - `"opener"`: `string` The opening greeting for the user. Defaults to `"Hi! I am your assistant, can I help you?"`.
  1246. - `"show_quote`: `boolean` Indicates whether the source of text should be displayed. Defaults to `true`.
  1247. - `"prompt"`: `string` The prompt content.
  1248. ### Response
  1249. Success:
  1250. ```json
  1251. {
  1252. "code": 0
  1253. }
  1254. ```
  1255. Failure:
  1256. ```json
  1257. {
  1258. "code": 102,
  1259. "message": "Duplicated chat name in updating dataset."
  1260. }
  1261. ```
  1262. ---
  1263. ## Delete chat assistants
  1264. **DELETE** `/api/v1/chats`
  1265. Deletes chat assistants by ID.
  1266. ### Request
  1267. - Method: DELETE
  1268. - URL: `/api/v1/chats`
  1269. - Headers:
  1270. - `'content-Type: application/json'`
  1271. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1272. - Body:
  1273. - `"ids"`: `list[string]`
  1274. #### Request example
  1275. ```bash
  1276. curl --request DELETE \
  1277. --url http://{address}/api/v1/chats \
  1278. --header 'Content-Type: application/json' \
  1279. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1280. --data '
  1281. {
  1282. "ids": ["test_1", "test_2"]
  1283. }'
  1284. ```
  1285. #### Request parameters
  1286. - `"ids"`: (*Body parameter*), `list[string]`
  1287. The IDs of the chat assistants to delete. If it is not specified, all chat assistants in the system will be deleted.
  1288. ### Response
  1289. Success:
  1290. ```json
  1291. {
  1292. "code": 0
  1293. }
  1294. ```
  1295. Failure:
  1296. ```json
  1297. {
  1298. "code": 102,
  1299. "message": "ids are required"
  1300. }
  1301. ```
  1302. ---
  1303. ## List chat assistants
  1304. **GET** `/api/v1/chats?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={chat_name}&id={chat_id}`
  1305. Lists chat assistants.
  1306. ### Request
  1307. - Method: GET
  1308. - URL: `/api/v1/chats?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
  1309. - Headers:
  1310. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1311. #### Request example
  1312. ```bash
  1313. curl --request GET \
  1314. --url http://{address}/api/v1/chats?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id} \
  1315. --header 'Authorization: Bearer <YOUR_API_KEY>'
  1316. ```
  1317. #### Request parameters
  1318. - `page`: (*Filter parameter*), `integer`
  1319. Specifies the page on which the chat assistants will be displayed. Defaults to `1`.
  1320. - `page_size`: (*Filter parameter*), `integer`
  1321. The number of chat assistants on each page. Defaults to `30`.
  1322. - `orderby`: (*Filter parameter*), `string`
  1323. The attribute by which the results are sorted. Available options:
  1324. - `create_time` (default)
  1325. - `update_time`
  1326. - `desc`: (*Filter parameter*), `boolean`
  1327. Indicates whether the retrieved chat assistants should be sorted in descending order. Defaults to `true`.
  1328. - `id`: (*Filter parameter*), `string`
  1329. The ID of the chat assistant to retrieve.
  1330. - `name`: (*Filter parameter*), `string`
  1331. The name of the chat assistant to retrieve.
  1332. ### Response
  1333. Success:
  1334. ```json
  1335. {
  1336. "code": 0,
  1337. "data": [
  1338. {
  1339. "avatar": "",
  1340. "create_date": "Fri, 18 Oct 2024 06:20:06 GMT",
  1341. "create_time": 1729232406637,
  1342. "description": "A helpful Assistant",
  1343. "do_refer": "1",
  1344. "id": "04d0d8e28d1911efa3630242ac120006",
  1345. "dataset_ids": ["527fa74891e811ef9c650242ac120006"],
  1346. "language": "English",
  1347. "llm": {
  1348. "frequency_penalty": 0.7,
  1349. "max_tokens": 512,
  1350. "model_name": "qwen-plus@Tongyi-Qianwen",
  1351. "presence_penalty": 0.4,
  1352. "temperature": 0.1,
  1353. "top_p": 0.3
  1354. },
  1355. "name": "13243",
  1356. "prompt": {
  1357. "empty_response": "Sorry! No relevant content was found in the knowledge base!",
  1358. "keywords_similarity_weight": 0.3,
  1359. "opener": "Hi! I'm your assistant, what can I do for you?",
  1360. "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",
  1361. "rerank_model": "",
  1362. "similarity_threshold": 0.2,
  1363. "top_n": 6,
  1364. "variables": [
  1365. {
  1366. "key": "knowledge",
  1367. "optional": false
  1368. }
  1369. ]
  1370. },
  1371. "prompt_type": "simple",
  1372. "status": "1",
  1373. "tenant_id": "69736c5e723611efb51b0242ac120007",
  1374. "top_k": 1024,
  1375. "update_date": "Fri, 18 Oct 2024 06:20:06 GMT",
  1376. "update_time": 1729232406638
  1377. }
  1378. ]
  1379. }
  1380. ```
  1381. Failure:
  1382. ```json
  1383. {
  1384. "code": 102,
  1385. "message": "The chat doesn't exist"
  1386. }
  1387. ```
  1388. ## Create session
  1389. **POST** `/api/v1/chats/{chat_id}/sessions`
  1390. Creates a chat session.
  1391. ### Request
  1392. - Method: POST
  1393. - URL: `/api/v1/chats/{chat_id}/sessions`
  1394. - Headers:
  1395. - `'content-Type: application/json'`
  1396. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1397. - Body:
  1398. - `"name"`: `string`
  1399. #### Request example
  1400. ```bash
  1401. curl --request POST \
  1402. --url http://{address}/api/v1/chats/{chat_id}/sessions \
  1403. --header 'Content-Type: application/json' \
  1404. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1405. --data '
  1406. {
  1407. "name": "new session"
  1408. }'
  1409. ```
  1410. #### Request parameters
  1411. - `chat_id`: (*Path parameter*)
  1412. The ID of the associated chat assistant.
  1413. - `"name"`: (*Body parameter*), `string`
  1414. The name of the chat session to create.
  1415. ### Response
  1416. Success:
  1417. ```json
  1418. {
  1419. "code": 0,
  1420. "data": {
  1421. "chat_id": "2ca4b22e878011ef88fe0242ac120005",
  1422. "create_date": "Fri, 11 Oct 2024 08:46:14 GMT",
  1423. "create_time": 1728636374571,
  1424. "id": "4606b4ec87ad11efbc4f0242ac120006",
  1425. "messages": [
  1426. {
  1427. "content": "Hi! I am your assistant,can I help you?",
  1428. "role": "assistant"
  1429. }
  1430. ],
  1431. "name": "new session",
  1432. "update_date": "Fri, 11 Oct 2024 08:46:14 GMT",
  1433. "update_time": 1728636374571
  1434. }
  1435. }
  1436. ```
  1437. Failure:
  1438. ```json
  1439. {
  1440. "code": 102,
  1441. "message": "Name can not be empty."
  1442. }
  1443. ```
  1444. ---
  1445. ## Update session
  1446. **PUT** `/api/v1/chats/{chat_id}/sessions/{session_id}`
  1447. Updates a chat session.
  1448. ### Request
  1449. - Method: PUT
  1450. - URL: `/api/v1/chats/{chat_id}/sessions/{session_id}`
  1451. - Headers:
  1452. - `'content-Type: application/json'`
  1453. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1454. - Body:
  1455. - `"name`: `string`
  1456. #### Request example
  1457. ```bash
  1458. curl --request PUT \
  1459. --url http://{address}/api/v1/chats/{chat_id}/sessions/{session_id} \
  1460. --header 'Content-Type: application/json' \
  1461. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1462. --data '
  1463. {
  1464. "name": "<REVISED_SESSION_NAME_HERE>"
  1465. }'
  1466. ```
  1467. #### Request Parameter
  1468. - `chat_id`: (*Path parameter*)
  1469. The ID of the associated chat assistant.
  1470. - `session_id`: (*Path parameter*)
  1471. The ID of the session to update.
  1472. - `"name"`: (*Body Parameter), `string`
  1473. The revised name of the session.
  1474. ### Response
  1475. Success:
  1476. ```json
  1477. {
  1478. "code": 0
  1479. }
  1480. ```
  1481. Failure:
  1482. ```json
  1483. {
  1484. "code": 102,
  1485. "message": "Name cannot be empty."
  1486. }
  1487. ```
  1488. ---
  1489. ## List sessions
  1490. **GET** `/api/v1/chats/{chat_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={session_name}&id={session_id}`
  1491. Lists sessions associated with a specified chat assistant.
  1492. ### Request
  1493. - Method: GET
  1494. - URL: `/api/v1/chats/{chat_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={session_name}&id={session_id}`
  1495. - Headers:
  1496. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1497. #### Request example
  1498. ```bash
  1499. curl --request GET \
  1500. --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} \
  1501. --header 'Authorization: Bearer <YOUR_API_KEY>'
  1502. ```
  1503. #### Request Parameters
  1504. - `chat_id`: (*Path parameter*)
  1505. The ID of the associated chat assistant.
  1506. - `page`: (*Filter parameter*), `integer`
  1507. Specifies the page on which the sessions will be displayed. Defaults to `1`.
  1508. - `page_size`: (*Filter parameter*), `integer`
  1509. The number of sessions on each page. Defaults to `30`.
  1510. - `orderby`: (*Filter parameter*), `string`
  1511. The field by which sessions should be sorted. Available options:
  1512. - `create_time` (default)
  1513. - `update_time`
  1514. - `desc`: (*Filter parameter*), `boolean`
  1515. Indicates whether the retrieved sessions should be sorted in descending order. Defaults to `true`.
  1516. - `name`: (*Filter parameter*) `string`
  1517. The name of the chat session to retrieve.
  1518. - `id`: (*Filter parameter*), `string`
  1519. The ID of the chat session to retrieve.
  1520. ### Response
  1521. Success:
  1522. ```json
  1523. {
  1524. "code": 0,
  1525. "data": [
  1526. {
  1527. "chat": "2ca4b22e878011ef88fe0242ac120005",
  1528. "create_date": "Fri, 11 Oct 2024 08:46:43 GMT",
  1529. "create_time": 1728636403974,
  1530. "id": "578d541e87ad11ef96b90242ac120006",
  1531. "messages": [
  1532. {
  1533. "content": "Hi! I am your assistant,can I help you?",
  1534. "role": "assistant"
  1535. }
  1536. ],
  1537. "name": "new session",
  1538. "update_date": "Fri, 11 Oct 2024 08:46:43 GMT",
  1539. "update_time": 1728636403974
  1540. }
  1541. ]
  1542. }
  1543. ```
  1544. Failure:
  1545. ```json
  1546. {
  1547. "code": 102,
  1548. "message": "The session doesn't exist"
  1549. }
  1550. ```
  1551. ---
  1552. ## Delete sessions
  1553. **DELETE** `/api/v1/chats/{chat_id}/sessions`
  1554. Deletes sessions by ID.
  1555. ### Request
  1556. - Method: DELETE
  1557. - URL: `/api/v1/chats/{chat_id}/sessions`
  1558. - Headers:
  1559. - `'content-Type: application/json'`
  1560. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1561. - Body:
  1562. - `"ids"`: `list[string]`
  1563. #### Request example
  1564. ```bash
  1565. # Either id or name must be provided, but not both.
  1566. curl --request DELETE \
  1567. --url http://{address}/api/v1/chats/{chat_id}/sessions \
  1568. --header 'Content-Type: application/json' \
  1569. --header 'Authorization: Bear <YOUR_API_KEY>' \
  1570. --data '
  1571. {
  1572. "ids": ["test_1", "test_2"]
  1573. }'
  1574. ```
  1575. #### Request Parameters
  1576. - `chat_id`: (*Path parameter*)
  1577. The ID of the associated chat assistant.
  1578. - `"ids"`: (*Body Parameter*), `list[string]`
  1579. The IDs of the sessions to delete. If it is not specified, all sessions associated with the specified chat assistant will be deleted.
  1580. ### Response
  1581. Success:
  1582. ```json
  1583. {
  1584. "code": 0
  1585. }
  1586. ```
  1587. Failure:
  1588. ```json
  1589. {
  1590. "code": 102,
  1591. "message": "The chat doesn't own the session"
  1592. }
  1593. ```
  1594. ---
  1595. ## Converse
  1596. **POST** `/api/v1/chats/{chat_id}/completions`
  1597. Asks a question to start an AI-powered conversation.
  1598. ### Request
  1599. - Method: POST
  1600. - URL: `/api/v1/chats/{chat_id}/completions`
  1601. - Headers:
  1602. - `'content-Type: application/json'`
  1603. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1604. - Body:
  1605. - `"question"`: `string`
  1606. - `"stream"`: `boolean`
  1607. - `"session_id"`: `string`
  1608. #### Request example
  1609. ```bash
  1610. curl --request POST \
  1611. --url http://{address}/api/v1/chats/{chat_id}/completions \
  1612. --header 'Content-Type: application/json' \
  1613. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1614. --data-binary '
  1615. {
  1616. "question": "What is RAGFlow?",
  1617. "stream": true
  1618. }'
  1619. ```
  1620. #### Request Parameters
  1621. - `chat_id`: (*Path parameter*)
  1622. The ID of the associated chat assistant.
  1623. - `"question"`: (*Body Parameter*), `string` *Required*
  1624. The question to start an AI-powered conversation.
  1625. - `"stream"`: (*Body Parameter*), `boolean`
  1626. Indicates whether to output responses in a streaming way:
  1627. - `true`: Enable streaming.
  1628. - `false`: Disable streaming (default).
  1629. - `"session_id"`: (*Body Parameter*)
  1630. The ID of session. If it is not provided, a new session will be generated.
  1631. ### Response
  1632. Success:
  1633. ```text
  1634. data:{
  1635. "code": 0,
  1636. "data": {
  1637. "answer": "I am an intelligent assistant designed to help answer questions by summarizing content from a",
  1638. "reference": {},
  1639. "audio_binary": null,
  1640. "id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
  1641. "session_id": "82b0ab2a9c1911ef9d870242ac120006"
  1642. }
  1643. }
  1644. data:{
  1645. "code": 0,
  1646. "data": {
  1647. "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",
  1648. "reference": {},
  1649. "audio_binary": null,
  1650. "id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
  1651. "session_id": "82b0ab2a9c1911ef9d870242ac120006"
  1652. }
  1653. }
  1654. data:{
  1655. "code": 0,
  1656. "data": {
  1657. "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.",
  1658. "reference": {},
  1659. "audio_binary": null,
  1660. "id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
  1661. "session_id": "82b0ab2a9c1911ef9d870242ac120006"
  1662. }
  1663. }
  1664. data:{
  1665. "code": 0,
  1666. "data": {
  1667. "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.",
  1668. "reference": {
  1669. "total": 1,
  1670. "chunks": [
  1671. {
  1672. "id": "faf26c791128f2d5e821f822671063bd",
  1673. "content": "xxxxxxxx",
  1674. "document_id": "dd58f58e888511ef89c90242ac120006",
  1675. "document_name": "1.txt",
  1676. "dataset_id": "8e83e57a884611ef9d760242ac120006",
  1677. "image_id": "",
  1678. "similarity": 0.7,
  1679. "vector_similarity": 0.0,
  1680. "term_similarity": 1.0,
  1681. "positions": [
  1682. ""
  1683. ]
  1684. }
  1685. ],
  1686. "doc_aggs": [
  1687. {
  1688. "doc_name": "1.txt",
  1689. "doc_id": "dd58f58e888511ef89c90242ac120006",
  1690. "count": 1
  1691. }
  1692. ]
  1693. },
  1694. "prompt": "xxxxxxxxxxx",
  1695. "id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
  1696. "session_id": "82b0ab2a9c1911ef9d870242ac120006"
  1697. }
  1698. }
  1699. data:{
  1700. "code": 0,
  1701. "data": true
  1702. }
  1703. ```
  1704. Failure:
  1705. ```json
  1706. {
  1707. "code": 102,
  1708. "message": "Please input your question."
  1709. }
  1710. ```
  1711. ## Create agent session
  1712. **POST** `/api/v1/agents/{agent_id}/sessions`
  1713. Creates an agent session.
  1714. ### Request
  1715. - Method: POST
  1716. - URL: `/api/v1/agents/{agent_id}/sessions`
  1717. - Headers:
  1718. - `'content-Type: application/json'`
  1719. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1720. - Body:
  1721. #### Request example
  1722. ```bash
  1723. curl --request POST \
  1724. --url http://{address}/api/v1/agents/{agent_id}/sessions \
  1725. --header 'Content-Type: application/json' \
  1726. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1727. --data '{
  1728. }'
  1729. ```
  1730. #### Request parameters
  1731. - `agent_id`: (*Path parameter*)
  1732. The ID of the associated agent assistant.
  1733. ### Response
  1734. Success:
  1735. ```json
  1736. {
  1737. "code": 0,
  1738. "data": {
  1739. "agent_id": "2e45b5209c1011efa3e90242ac120006",
  1740. "id": "7869e9e49c1711ef92840242ac120006",
  1741. "message": [
  1742. {
  1743. "content": "Hello! I am the HR responsible for recruitment at Infineon. I learned that you are an expert in this field, and I took the liberty of reaching out to you. There is an opportunity I would like to share with you. RAGFlow is currently looking for a senior engineer for your position. I was wondering if you might be interested?",
  1744. "role": "assistant"
  1745. }
  1746. ],
  1747. "source": "agent",
  1748. "user_id": ""
  1749. }
  1750. }
  1751. ```
  1752. Failure:
  1753. ```json
  1754. {
  1755. "code": 102,
  1756. "message": "Agent not found."
  1757. }
  1758. ```
  1759. ## Converse through agent
  1760. **POST** `/api/v1/agents/{agent_id}/completions`
  1761. #######
  1762. Asks a question to start an AI-powered conversation.
  1763. ### Request
  1764. - Method: POST
  1765. - URL: `/api/v1/agents/{agent_id}/completions`
  1766. - Headers:
  1767. - `'content-Type: application/json'`
  1768. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1769. - Body:
  1770. - `"question"`: `string`
  1771. - `"stream"`: `boolean`
  1772. - `"session_id"`: `string`
  1773. #### Request example
  1774. ```bash
  1775. curl --request POST \
  1776. --url http://{address}/api/v1/agents/{agent_id}/completions \
  1777. --header 'Content-Type: application/json' \
  1778. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1779. --data-binary '
  1780. {
  1781. "question": "What is RAGFlow?",
  1782. "stream": true
  1783. }'
  1784. ```
  1785. #### Request Parameters
  1786. - `agent_id`: (*Path parameter*)
  1787. The ID of the associated agent assistant.
  1788. - `"question"`: (*Body Parameter*), `string` *Required*
  1789. The question to start an AI-powered conversation.
  1790. - `"stream"`: (*Body Parameter*), `boolean`
  1791. Indicates whether to output responses in a streaming way:
  1792. - `true`: Enable streaming.
  1793. - `false`: Disable streaming (default).
  1794. - `"session_id"`: (*Body Parameter*)
  1795. The ID of session. If it is not provided, a new session will be generated.
  1796. ### Response
  1797. Success:
  1798. ```text
  1799. data:{
  1800. "code": 0,
  1801. "message": "",
  1802. "data": {
  1803. "answer": "",
  1804. "reference": [],
  1805. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1806. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1807. }
  1808. }
  1809. data:{
  1810. "code": 0,
  1811. "message": "",
  1812. "data": {
  1813. "answer": "Hello",
  1814. "reference": [],
  1815. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1816. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1817. }
  1818. }
  1819. data:{
  1820. "code": 0,
  1821. "message": "",
  1822. "data": {
  1823. "answer": "Hello!",
  1824. "reference": [],
  1825. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1826. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1827. }
  1828. }
  1829. data:{
  1830. "code": 0,
  1831. "message": "",
  1832. "data": {
  1833. "answer": "Hello! How",
  1834. "reference": [],
  1835. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1836. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1837. }
  1838. }
  1839. data:{
  1840. "code": 0,
  1841. "message": "",
  1842. "data": {
  1843. "answer": "Hello! How can",
  1844. "reference": [],
  1845. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1846. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1847. }
  1848. }
  1849. data:{
  1850. "code": 0,
  1851. "message": "",
  1852. "data": {
  1853. "answer": "Hello! How can I",
  1854. "reference": [],
  1855. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1856. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1857. }
  1858. }
  1859. data:{
  1860. "code": 0,
  1861. "message": "",
  1862. "data": {
  1863. "answer": "Hello! How can I assist",
  1864. "reference": [],
  1865. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1866. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1867. }
  1868. }
  1869. data:{
  1870. "code": 0,
  1871. "message": "",
  1872. "data": {
  1873. "answer": "Hello! How can I assist you",
  1874. "reference": [],
  1875. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1876. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1877. }
  1878. }
  1879. data:{
  1880. "code": 0,
  1881. "message": "",
  1882. "data": {
  1883. "answer": "Hello! How can I assist you today",
  1884. "reference": [],
  1885. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1886. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1887. }
  1888. }
  1889. data:{
  1890. "code": 0,
  1891. "message": "",
  1892. "data": {
  1893. "answer": "Hello! How can I assist you today?",
  1894. "reference": [],
  1895. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1896. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1897. }
  1898. }
  1899. data:{
  1900. "code": 0,
  1901. "message": "",
  1902. "data": {
  1903. "answer": "Hello! How can I assist you today?",
  1904. "reference": [],
  1905. "id": "7ed5c2e4-aa28-4397-bbed-59664a332aa0",
  1906. "session_id": "ce1b4fa89c1811ef85720242ac120006"
  1907. }
  1908. }
  1909. data:{
  1910. "code": 0,
  1911. "message": "",
  1912. "data": true
  1913. }
  1914. ```
  1915. Failure:
  1916. ```json
  1917. {
  1918. "code": 102,
  1919. "message": "`question` is required."
  1920. }
  1921. ```