Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

http_api_reference.md 61KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110
  1. # DRAFT! HTTP API Reference
  2. **THE API REFERENCES BELOW ARE STILL UNDER DEVELOPMENT.**
  3. ---
  4. :::tip NOTE
  5. Dataset Management
  6. :::
  7. ---
  8. ## Create dataset
  9. **POST** `/api/v1/dataset`
  10. Creates a dataset.
  11. ### Request
  12. - Method: POST
  13. - URL: `/api/v1/dataset`
  14. - Headers:
  15. - `'content-Type: application/json'`
  16. - `'Authorization: Bearer {YOUR_API_KEY}'`
  17. - Body:
  18. - `"name"`: `string`
  19. - `"avatar"`: `string`
  20. - `"description"`: `string`
  21. - `"language"`: `string`
  22. - `"embedding_model"`: `string`
  23. - `"permission"`: `string`
  24. - `"parse_method"`: `string`
  25. - `"parser_config"`: `Dataset.ParserConfig`
  26. #### Request example
  27. ```bash
  28. # "name": name is required and can't be duplicated.
  29. # "embedding_model": embedding_model must not be provided.
  30. # "naive" means general.
  31. curl --request POST \
  32. --url http://{address}/api/v1/dataset \
  33. --header 'Content-Type: application/json' \
  34. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  35. --data '{
  36. "name": "test",
  37. "chunk_method": "naive"
  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. Defaults to `""`.
  52. - `"description"`: (*Body parameter*), `string`
  53. A brief description of the dataset to create. Defaults to `""`.
  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. - `"email"`: Email
  76. - `"parser_config"`: (*Body parameter*)
  77. The configuration settings for the dataset parser. A `ParserConfig` object contains the following attributes:
  78. - `"chunk_token_count"`: Defaults to `128`.
  79. - `"layout_recognize"`: Defaults to `True`.
  80. - `"delimiter"`: Defaults to `"\n!?。;!?"`.
  81. - `"task_page_size"`: Defaults to `12`.
  82. ### Response
  83. Success:
  84. ```json
  85. {
  86. "code": 0,
  87. "data": {
  88. "avatar": null,
  89. "chunk_count": 0,
  90. "create_date": "Thu, 10 Oct 2024 05:57:37 GMT",
  91. "create_time": 1728539857641,
  92. "created_by": "69736c5e723611efb51b0242ac120007",
  93. "description": null,
  94. "document_count": 0,
  95. "embedding_model": "BAAI/bge-large-zh-v1.5",
  96. "id": "8d73076886cc11ef8c270242ac120006",
  97. "language": "English",
  98. "name": "test_1",
  99. "parse_method": "naive",
  100. "parser_config": {
  101. "pages": [
  102. [
  103. 1,
  104. 1000000
  105. ]
  106. ]
  107. },
  108. "permission": "me",
  109. "similarity_threshold": 0.2,
  110. "status": "1",
  111. "tenant_id": "69736c5e723611efb51b0242ac120007",
  112. "token_num": 0,
  113. "update_date": "Thu, 10 Oct 2024 05:57:37 GMT",
  114. "update_time": 1728539857641,
  115. "vector_similarity_weight": 0.3
  116. }
  117. }
  118. ```
  119. Failure:
  120. ```json
  121. {
  122. "code": 102,
  123. "message": "Duplicated knowledgebase name in creating dataset."
  124. }
  125. ```
  126. ---
  127. ## Delete datasets
  128. **DELETE** `/api/v1/dataset`
  129. Deletes datasets by ID.
  130. ### Request
  131. - Method: DELETE
  132. - URL: `/api/v1/dataset`
  133. - Headers:
  134. - `'content-Type: application/json'`
  135. - `'Authorization: Bearer {YOUR_API_KEY}'`
  136. - Body:
  137. - `"ids"`: `list[string]`
  138. #### Request example
  139. ```bash
  140. # Either id or name must be provided, but not both.
  141. curl --request DELETE \
  142. --url http://{address}/api/v1/dataset \
  143. --header 'Content-Type: application/json' \
  144. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  145. --data '{
  146. "ids": ["test_1", "test_2"]
  147. }'
  148. ```
  149. #### Request parameters
  150. - `"ids"`: (*Body parameter*)
  151. The IDs of the datasets to delete. Defaults to `""`. If not specified, all datasets in the system will be deleted.
  152. ### Response
  153. Success:
  154. ```json
  155. {
  156. "code": 0
  157. }
  158. ```
  159. Failure:
  160. ```json
  161. {
  162. "code": 102,
  163. "message": "You don't own the dataset."
  164. }
  165. ```
  166. ---
  167. ## Update dataset
  168. **PUT** `/api/v1/dataset/{dataset_id}`
  169. Updates configurations for a specified dataset.
  170. ### Request
  171. - Method: PUT
  172. - URL: `/api/v1/dataset/{dataset_id}`
  173. - Headers:
  174. - `'content-Type: application/json'`
  175. - `'Authorization: Bearer {YOUR_API_KEY}'`
  176. - Body:
  177. - `"name"`: `string`
  178. - `"embedding_model"`: `string`
  179. - `"chunk_method"`: `enum<string>`
  180. #### Request example
  181. ```bash
  182. # "id": id is required.
  183. # "name": If you update name, it can't be duplicated.
  184. # "embedding_model": If you update embedding_model, it can't be changed.
  185. # "parse_method": If you update parse_method, chunk_count must be 0.
  186. # "naive" means general.
  187. curl --request PUT \
  188. --url http://{address}/api/v1/dataset/{dataset_id} \
  189. --header 'Content-Type: application/json' \
  190. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  191. --data '{
  192. "name": "test",
  193. "embedding_model": "BAAI/bge-zh-v1.5",
  194. "parse_method": "naive"
  195. }'
  196. ```
  197. #### Request parameters
  198. - `"name"`: `string` The name of the dataset to update.
  199. - `"embedding_model"`: `string` The embedding model name to update.
  200. - Ensure that `"chunk_count"` is `0` before updating `"embedding_model"`.
  201. - `"chunk_method"`: `enum<string>` The chunking method for the dataset. Available options:
  202. - `"naive"`: General
  203. - `"manual`: Manual
  204. - `"qa"`: Q&A
  205. - `"table"`: Table
  206. - `"paper"`: Paper
  207. - `"book"`: Book
  208. - `"laws"`: Laws
  209. - `"presentation"`: Presentation
  210. - `"picture"`: Picture
  211. - `"one"`:One
  212. - `"knowledge_graph"`: Knowledge Graph
  213. - `"email"`: Email
  214. ### Response
  215. Success:
  216. ```json
  217. {
  218. "code": 0
  219. }
  220. ```
  221. Failure:
  222. ```json
  223. {
  224. "code": 102,
  225. "message": "Can't change tenant_id."
  226. }
  227. ```
  228. ---
  229. ## List datasets
  230. **GET** `/api/v1/dataset?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
  231. Lists datasets.
  232. ### Request
  233. - Method: GET
  234. - URL: `/api/v1/dataset?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
  235. - Headers:
  236. - `'Authorization: Bearer {YOUR_API_KEY}'`
  237. #### Request example
  238. ```bash
  239. # If no page parameter is passed, the default is 1
  240. # If no page_size parameter is passed, the default is 1024
  241. # If no order_by parameter is passed, the default is "create_time"
  242. # If no desc parameter is passed, the default is True
  243. curl --request GET \
  244. --url http://{address}/api/v1/dataset?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id} \
  245. --header 'Authorization: Bearer {YOUR_API_KEY}'
  246. ```
  247. #### Request parameters
  248. - `"page"`: (*Path parameter*)
  249. Specifies the page on which the datasets will be displayed. Defaults to `1`.
  250. - `"page_size"`: (*Path parameter*)
  251. The number of datasets on each page. Defaults to `1024`.
  252. - `"orderby"`: (*Path parameter*)
  253. The field by which datasets should be sorted. Available options:
  254. - `"create_time"` (default)
  255. - `"update_time"`
  256. - `"desc"`: (*Path parameter*)
  257. Indicates whether the retrieved datasets should be sorted in descending order. Defaults to `True`.
  258. - `"id"`: (*Path parameter*)
  259. The ID of the dataset to retrieve.
  260. - `"name"`: (*Path parameter*)
  261. The name of the dataset to retrieve.
  262. ### Response
  263. Success:
  264. ```json
  265. {
  266. "code": 0,
  267. "data": [
  268. {
  269. "avatar": "",
  270. "chunk_count": 59,
  271. "create_date": "Sat, 14 Sep 2024 01:12:37 GMT",
  272. "create_time": 1726276357324,
  273. "created_by": "69736c5e723611efb51b0242ac120007",
  274. "description": null,
  275. "document_count": 1,
  276. "embedding_model": "BAAI/bge-large-zh-v1.5",
  277. "id": "6e211ee0723611efa10a0242ac120007",
  278. "language": "English",
  279. "name": "mysql",
  280. "parse_method": "knowledge_graph",
  281. "parser_config": {
  282. "chunk_token_num": 8192,
  283. "delimiter": "\\n!?;。;!?",
  284. "entity_types": [
  285. "organization",
  286. "person",
  287. "location",
  288. "event",
  289. "time"
  290. ]
  291. },
  292. "permission": "me",
  293. "similarity_threshold": 0.2,
  294. "status": "1",
  295. "tenant_id": "69736c5e723611efb51b0242ac120007",
  296. "token_num": 12744,
  297. "update_date": "Thu, 10 Oct 2024 04:07:23 GMT",
  298. "update_time": 1728533243536,
  299. "vector_similarity_weight": 0.3
  300. }
  301. ]
  302. }
  303. ```
  304. Failure:
  305. ```json
  306. {
  307. "code": 102,
  308. "message": "The dataset doesn't exist"
  309. }
  310. ```
  311. ---
  312. :::tip API GROUPING
  313. File Management within Dataset
  314. :::
  315. ---
  316. ## Upload documents
  317. **POST** `/api/v1/dataset/{dataset_id}/document`
  318. Uploads documents to a specified dataset.
  319. ### Request
  320. - Method: POST
  321. - URL: `/api/v1/dataset/{dataset_id}/document`
  322. - Headers:
  323. - `'Content-Type: multipart/form-data'`
  324. - `'Authorization: Bearer {YOUR_API_KEY}'`
  325. - Form:
  326. - `'file=@{FILE_PATH}'`
  327. #### Request example
  328. ```bash
  329. curl --request POST \
  330. --url http://{address}/api/v1/dataset/{dataset_id}/document \
  331. --header 'Content-Type: multipart/form-data' \
  332. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  333. --form 'file=@./test1.txt' \
  334. --form 'file=@./test2.pdf'
  335. ```
  336. #### Request parameters
  337. - `"dataset_id"`: (*Path parameter*)
  338. The ID of the dataset to which the documents will be uploaded.
  339. - `"file"`: (*Body parameter*)
  340. The document to upload.
  341. ### Response
  342. Success:
  343. ```json
  344. {
  345. "code": 0
  346. }
  347. ```
  348. Failure:
  349. ```json
  350. {
  351. "code": 101,
  352. "message": "No file part!"
  353. }
  354. ```
  355. ---
  356. ## Update document
  357. **PUT** `/api/v1/dataset/{dataset_id}/info/{document_id}`
  358. Updates configurations for a specified document.
  359. ### Request
  360. - Method: PUT
  361. - URL: `/api/v1/dataset/{dataset_id}/document/{document_id}`
  362. - Headers:
  363. - `'content-Type: application/json'`
  364. - `'Authorization: Bearer {YOUR_API_KEY}'`
  365. - Body:
  366. - `"name"`:`string`
  367. - `"chunk_method"`:`string`
  368. - `"parser_config"`:`object`
  369. #### Request example
  370. ```bash
  371. curl --request PUT \
  372. --url http://{address}/api/v1/dataset/{dataset_id}/info/{document_id} \
  373. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  374. --header 'Content-Type: application/json' \
  375. --data '{
  376. "name": "manual.txt",
  377. "chunk_method": "manual",
  378. "parser_config": {"chunk_token_count": 128}
  379. }'
  380. ```
  381. #### Request parameters
  382. - `"name"`: (*Body parameter*), `string`
  383. - `"chunk_method"`: (*Body parameter*), `string`
  384. The parsing method to apply to the document:
  385. - `"naive"`: General
  386. - `"manual`: Manual
  387. - `"qa"`: Q&A
  388. - `"table"`: Table
  389. - `"paper"`: Paper
  390. - `"book"`: Book
  391. - `"laws"`: Laws
  392. - `"presentation"`: Presentation
  393. - `"picture"`: Picture
  394. - `"one"`: One
  395. - `"knowledge_graph"`: Knowledge Graph
  396. - `"email"`: Email
  397. - `"parser_config"`: (*Body parameter*), `object`
  398. The parsing configuration for the document:
  399. - `"chunk_token_count"`: Defaults to `128`.
  400. - `"layout_recognize"`: Defaults to `True`.
  401. - `"delimiter"`: Defaults to `"\n!?。;!?"`.
  402. - `"task_page_size"`: Defaults to `12`.
  403. ### Response
  404. Success:
  405. ```json
  406. {
  407. "code": 0
  408. }
  409. ```
  410. Failure:
  411. ```json
  412. {
  413. "code": 102,
  414. "message": "The dataset does not have the document."
  415. }
  416. ```
  417. ---
  418. ## Download document
  419. **GET** `/api/v1/dataset/{dataset_id}/document/{document_id}`
  420. Downloads a document from a specified dataset.
  421. ### Request
  422. - Method: GET
  423. - URL: `/api/v1/dataset/{dataset_id}/document/{document_id}`
  424. - Headers:
  425. - `'Authorization: Bearer {YOUR_API_KEY}'`
  426. - Output:
  427. - `'{FILE_NAME}'`????????
  428. #### Request example
  429. ```bash
  430. curl --request GET \
  431. --url http://{address}/api/v1/dataset/{dataset_id}/document/{document_id} \
  432. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  433. --output ./ragflow.txt
  434. ```
  435. #### Request parameters
  436. - `"dataset_id"`: (*Path parameter*)
  437. The dataset ID.
  438. - `"documents_id"`: (*Path parameter*)
  439. The ID of the document to download.
  440. ### Response
  441. A successful response includes a text object like the following:
  442. ```text
  443. test_2.
  444. ```????????????????
  445. Failure:
  446. ```json
  447. {
  448. "code": 102,
  449. "message": "You do not own the dataset 7898da028a0511efbf750242ac1220005."
  450. }
  451. ```
  452. ---
  453. ## List documents
  454. **GET** `/api/v1/dataset/{dataset_id}/info?offset={offset}&limit={limit}&orderby={orderby}&desc={desc}&keywords={keywords}&id={document_id}`
  455. Lists documents in a specified dataset.
  456. ### Request
  457. - Method: GET
  458. - URL: `/api/v1/dataset/{dataset_id}/info?keywords={keyword}&page={page}&page_size={limit}&orderby={orderby}&desc={desc}&name={name`
  459. - Headers:
  460. - `'content-Type: application/json'`
  461. - `'Authorization: Bearer {YOUR_API_KEY}'`
  462. #### Request example
  463. ```bash
  464. curl --request GET \
  465. --url http://{address}/api/v1/dataset/{dataset_id}/info?offset={offset}&limit={limit}&orderby={orderby}&desc={desc}&keywords={keywords}&id={document_id} \
  466. --header 'Authorization: Bearer {YOUR_API_KEY}'
  467. ```
  468. #### Request parameters
  469. - `"dataset_id"`: (*Path parameter*)
  470. The dataset ID.
  471. - `"keywords"`: (*Filter parameter*), `string`
  472. The keywords used to match document titles.
  473. - `"offset"`: (*Filter parameter*), `integer`
  474. The starting index for the documents to retrieve. Typically used in conjunction with `limit`. Defaults to `1`.
  475. - `"limit"`: (*Filter parameter*), `integer`
  476. The maximum number of documents to retrieve. Defaults to `1024`.
  477. - `"orderby"`: (*Filter parameter*), `string`
  478. The field by which documents should be sorted. Available options:
  479. - `"create_time"` (default)
  480. - `"update_time"`
  481. - `"desc"`: (*Filter parameter*), `boolean`
  482. Indicates whether the retrieved documents should be sorted in descending order. Defaults to `True`.
  483. - `"document_id"`: (*Filter parameter*)
  484. The ID of the document to retrieve.
  485. ### Response
  486. Success:
  487. ```json
  488. {
  489. "code": 0,
  490. "data": {
  491. "docs": [
  492. {
  493. "chunk_count": 0,
  494. "create_date": "Mon, 14 Oct 2024 09:11:01 GMT",
  495. "create_time": 1728897061948,
  496. "created_by": "69736c5e723611efb51b0242ac120007",
  497. "id": "3bcfbf8a8a0c11ef8aba0242ac120006",
  498. "knowledgebase_id": "7898da028a0511efbf750242ac120005",
  499. "location": "Test_2.txt",
  500. "name": "Test_2.txt",
  501. "parser_config": {
  502. "chunk_token_count": 128,
  503. "delimiter": "\n!?。;!?",
  504. "layout_recognize": true,
  505. "task_page_size": 12
  506. },
  507. "parser_method": "naive",
  508. "process_begin_at": null,
  509. "process_duation": 0.0,
  510. "progress": 0.0,
  511. "progress_msg": "",
  512. "run": "0",
  513. "size": 7,
  514. "source_type": "local",
  515. "status": "1",
  516. "thumbnail": null,
  517. "token_count": 0,
  518. "type": "doc",
  519. "update_date": "Mon, 14 Oct 2024 09:11:01 GMT",
  520. "update_time": 1728897061948
  521. }
  522. ],
  523. "total": 1
  524. }
  525. }
  526. ```
  527. Failure:
  528. ```json
  529. {
  530. "code": 102,
  531. "message": "You don't own the dataset 7898da028a0511efbf750242ac1220005. "
  532. }
  533. ```
  534. ---
  535. ## Delete documents
  536. **DELETE** `/api/v1/dataset/{dataset_id}/document`
  537. Deletes documents by ID.
  538. ### Request
  539. - Method: DELETE
  540. - URL: `/api/v1/dataset/{dataset_id}/document`
  541. - Headers:
  542. - `'Content-Type: application/json'`
  543. - `'Authorization: Bearer {YOUR_API_KEY}'`
  544. - Body:
  545. - `"ids"`: `list[string]`
  546. #### Request example
  547. ```bash
  548. curl --request DELETE \
  549. --url http://{address}/api/v1/dataset/{dataset_id}/document \
  550. --header 'Content-Type: application/json' \
  551. --header 'Authorization: {YOUR_API_KEY}' \
  552. --data '{
  553. "ids": ["id_1","id_2"]
  554. }'
  555. ```
  556. #### Request parameters
  557. - `"ids"`: (*Body parameter*), `list[string]`
  558. The IDs of the documents to delete. If not specified, all documents in the dataset will be deleted.
  559. ### Response
  560. Success:
  561. ```json
  562. {
  563. "code": 0
  564. }.
  565. ```
  566. Failure:
  567. ```json
  568. {
  569. "code": 102,
  570. "message": "You do not own the dataset 7898da028a0511efbf750242ac1220005."
  571. }
  572. ```
  573. ---
  574. ## Parse documents
  575. **POST** `/api/v1/dataset/{dataset_id}/chunk`
  576. Parses documents in a specified dataset.
  577. ### Request
  578. - Method: POST
  579. - URL: `/api/v1/dataset/{dataset_id}/chunk`
  580. - Headers:
  581. - `'content-Type: application/json'`
  582. - 'Authorization: Bearer {YOUR_API_KEY}'
  583. - Body:
  584. - `"document_ids"`: `list[string]`
  585. #### Request example
  586. ```bash
  587. curl --request POST \
  588. --url http://{address}/api/v1/dataset/{dataset_id}/chunk \
  589. --header 'Content-Type: application/json' \
  590. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  591. --data '{"document_ids": ["97a5f1c2759811efaa500242ac120004","97ad64b6759811ef9fc30242ac120004"]}'
  592. ```
  593. #### Request parameters
  594. - `"dataset_id"`: (*Path parameter*)
  595. The dataset ID.
  596. - `"document_ids"`: (*Body parameter*), `list[string]`
  597. The IDs of the documents to parse.
  598. ### Response
  599. Success:
  600. ```json
  601. {
  602. "code": 0
  603. }
  604. ```
  605. Failure:
  606. ```json
  607. {
  608. "code": 102,
  609. "message": "`document_ids` is required"
  610. }
  611. ```
  612. ---
  613. ## Stop parsing documents
  614. **DELETE** `/api/v1/dataset/{dataset_id}/chunk`
  615. Stops parsing specified documents.
  616. ### Request
  617. - Method: DELETE
  618. - URL: `/api/v1/dataset/{dataset_id}/chunk`
  619. - Headers:
  620. - `'content-Type: application/json'`
  621. - `'Authorization: Bearer {YOUR_API_KEY}'`
  622. - Body:
  623. - `"document_ids"`: `list[string]`
  624. #### Request example
  625. ```bash
  626. curl --request DELETE \
  627. --url http://{address}/api/v1/dataset/{dataset_id}/chunk \
  628. --header 'Content-Type: application/json' \
  629. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  630. --data '{"document_ids": ["97a5f1c2759811efaa500242ac120004","97ad64b6759811ef9fc30242ac120004"]}'
  631. ```
  632. #### Request parameters
  633. - `"dataset_id"`: (*Path parameter*)
  634. The dataset ID
  635. - `"document_ids"`: (*Body parameter*)
  636. The IDs of the documents for which the parsing should be stopped.
  637. ### Response
  638. Success:
  639. ```json
  640. {
  641. "code": 0
  642. }
  643. ```
  644. Failure:
  645. ```json
  646. {
  647. "code": 102,
  648. "message": "`document_ids` is required"
  649. }
  650. ```
  651. ---
  652. ## Add chunks
  653. **POST** `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk`
  654. Adds a chunk to a specified document in a specified dataset.
  655. ### Request
  656. - Method: POST
  657. - URL: `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk`
  658. - Headers:
  659. - `'content-Type: application/json'`
  660. - `'Authorization: Bearer {YOUR_API_KEY}'`
  661. - Body:
  662. - `"content"`: `string`
  663. - `"important_keywords"`: `list[string]`
  664. #### Request example
  665. ```bash
  666. curl --request POST \
  667. --url http://{address}/api/v1/dataset/{dataset_id}/document/{document_id}/chunk \
  668. --header 'Content-Type: application/json' \
  669. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  670. --data '{
  671. "content": "<SOME_CHUNK_CONTENT_HERE>"
  672. }'
  673. ```
  674. #### Request parameters
  675. - `"content"`: (*Body parameter*), `string`, *Required*
  676. The text content of the chunk.
  677. - `"important_keywords`(*Body parameter*)
  678. The key terms or phrases to tag with the chunk.
  679. ### Response
  680. Success:
  681. ```json
  682. {
  683. "code": 0,
  684. "data": {
  685. "chunk": {
  686. "content": "ragflow content",
  687. "create_time": "2024-10-16 08:05:04",
  688. "create_timestamp": 1729065904.581025,
  689. "dataset_id": [
  690. "c7ee74067a2c11efb21c0242ac120006"
  691. ],
  692. "document_id": "5c5999ec7be811ef9cab0242ac120005",
  693. "id": "d78435d142bd5cf6704da62c778795c5",
  694. "important_keywords": []
  695. }
  696. }
  697. }
  698. ```
  699. Failure:
  700. ```json
  701. {
  702. "code": 102,
  703. "message": "`content` is required"
  704. }
  705. ```
  706. ---
  707. ## List chunks
  708. **GET** `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk?keywords={keywords}&offset={offset}&limit={limit}&id={id}`
  709. Lists chunks in a specified document.
  710. ### Request
  711. - Method: GET
  712. - URL: `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk?keywords={keywords}&offset={offset}&limit={limit}&id={id}`
  713. - Headers:
  714. - `'Authorization: Bearer {YOUR_API_KEY}'`
  715. #### Request example
  716. ```bash
  717. curl --request GET \
  718. --url http://{address}/api/v1/dataset/{dataset_id}/document/{document_id}/chunk?keywords={keywords}&offset={offset}&limit={limit}&id={id} \
  719. --header 'Authorization: Bearer {YOUR_API_KEY}'
  720. ```
  721. #### Request parameters
  722. - `"dataset_id"`: (*Path parameter*)
  723. The dataset ID.
  724. - `"document_id"`: (*Path parameter*)
  725. The document ID.
  726. - `"keywords"`(*Filter parameter*), `string`
  727. The keywords used to match chunk content. Defaults to `None`
  728. - `"offset"`(*Filter parameter*), `string`
  729. The starting index for the chunks to retrieve. Defaults to `1`.
  730. - `"limit"`(*Filter parameter*), `integer`
  731. The maximum number of chunks to retrieve. Default: `1024`
  732. - `"id"`(*Filter parameter*), `string`
  733. The ID of the chunk to retrieve. Default: `None`
  734. ### Response
  735. Success:
  736. ```json
  737. {
  738. "code": 0,
  739. "data": {
  740. "chunks": [],
  741. "doc": {
  742. "chunk_num": 0,
  743. "create_date": "Sun, 29 Sep 2024 03:47:29 GMT",
  744. "create_time": 1727581649216,
  745. "created_by": "69736c5e723611efb51b0242ac120007",
  746. "id": "8cb781ec7e1511ef98ac0242ac120006",
  747. "kb_id": "c7ee74067a2c11efb21c0242ac120006",
  748. "location": "sunny_tomorrow.txt",
  749. "name": "sunny_tomorrow.txt",
  750. "parser_config": {
  751. "pages": [
  752. [
  753. 1,
  754. 1000000
  755. ]
  756. ]
  757. },
  758. "parser_id": "naive",
  759. "process_begin_at": "Tue, 15 Oct 2024 10:23:51 GMT",
  760. "process_duation": 1435.37,
  761. "progress": 0.0370833,
  762. "progress_msg": "\nTask has been received.",
  763. "run": "1",
  764. "size": 24,
  765. "source_type": "local",
  766. "status": "1",
  767. "thumbnail": null,
  768. "token_num": 0,
  769. "type": "doc",
  770. "update_date": "Tue, 15 Oct 2024 10:47:46 GMT",
  771. "update_time": 1728989266371
  772. },
  773. "total": 0
  774. }
  775. }
  776. ```
  777. Failure:
  778. ```json
  779. {
  780. "code": 102,
  781. "message": "You don't own the document 5c5999ec7be811ef9cab0242ac12000e5."
  782. }
  783. ```
  784. ---
  785. ## Delete chunks
  786. **DELETE** `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk`
  787. Deletes chunks by ID.
  788. ### Request
  789. - Method: DELETE
  790. - URL: `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk`
  791. - Headers:
  792. - `'content-Type: application/json'`
  793. - `'Authorization: Bearer {YOUR_API_KEY}'`
  794. - Body:
  795. - `"chunk_ids"`: `list[string]`
  796. #### Request example
  797. ```bash
  798. curl --request DELETE \
  799. --url http://{address}/api/v1/dataset/{dataset_id}/document/{document_id}/chunk \
  800. --header 'Content-Type: application/json' \
  801. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  802. --data '{
  803. "chunk_ids": ["test_1", "test_2"]
  804. }'
  805. ```
  806. #### Request parameters
  807. - `"chunk_ids"`: (*Body parameter*)
  808. The IDs of the chunks to delete. If not specified, all chunks of the current document will be deleted.
  809. ### Response
  810. Success:
  811. ```json
  812. {
  813. "code": 0
  814. }
  815. ```
  816. Failure:
  817. ```json
  818. {
  819. "code": 102,
  820. "message": "`chunk_ids` is required"
  821. }
  822. ```
  823. ---
  824. ## Update chunk
  825. **PUT** `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk/{chunk_id}`
  826. Updates content or configurations for a specified chunk.
  827. ### Request
  828. - Method: PUT
  829. - URL: `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk/{chunk_id}`
  830. - Headers:
  831. - `'content-Type: application/json'`
  832. - `'Authorization: Bearer {YOUR_API_KEY}'`
  833. - Body:
  834. - `"content"`: `string`
  835. - `"important_keywords"`: `string`
  836. - `"available"`: `integer`
  837. #### Request example
  838. ```bash
  839. curl --request PUT \
  840. --url http://{address}/api/v1/dataset/{dataset_id}/document/{document_id}/chunk/{chunk_id} \
  841. --header 'Content-Type: application/json' \
  842. --header 'Authorization: {YOUR_API_KEY}' \
  843. --data '{
  844. "content": "ragflow123",
  845. "important_keywords": [],
  846. }'
  847. ```
  848. #### Request parameters
  849. - `"content"`: (*Body parameter*), `string`
  850. The text content of the chunk.
  851. - `"important_keywords"`: (*Body parameter*), `list[string]`
  852. A list of key terms or phrases to tag with the chunk.
  853. - `"available"`: (*Body parameter*) `boolean`
  854. The chunk's availability status in the dataset. Value options:
  855. - `False`: Unavailable
  856. - `True`: Available
  857. ### Response
  858. Success:
  859. ```json
  860. {
  861. "code": 0
  862. }
  863. ```
  864. Failure:
  865. ```json
  866. {
  867. "code": 102,
  868. "message": "Can't find this chunk 29a2d9987e16ba331fb4d7d30d99b71d2"
  869. }
  870. ```
  871. ---
  872. ## Retrieve chunks
  873. **GET** `/api/v1/retrieval`
  874. Retrieves chunks from specified datasets.
  875. ### Request
  876. - Method: POST
  877. - URL: `/api/v1/retrieval`
  878. - Headers:
  879. - `'content-Type: application/json'`
  880. - `'Authorization: Bearer {YOUR_API_KEY}'`
  881. - Body:
  882. - `"question"`: `string`
  883. - `"datasets"`: `list[string]`
  884. - `"documents"`: `list[string]`
  885. - `"offset"`: `integer`
  886. - `"limit"`: `integer`
  887. - `"similarity_threshold"`: `float`
  888. - `"vector_similarity_weight"`: `float`
  889. - `"top_k"`: `integer`
  890. - `"rerank_id"`: `string`
  891. - `"keyword"`: `boolean`
  892. - `"highlight"`: `boolean`
  893. #### Request example
  894. ```bash
  895. curl --request POST \
  896. --url http://{address}/api/v1/retrieval \
  897. --header 'Content-Type: application/json' \
  898. --header 'Authorization: {YOUR_API_KEY}' \
  899. --data '{
  900. "question": "What is advantage of ragflow?",
  901. "datasets": [
  902. "b2a62730759d11ef987d0242ac120004"
  903. ],
  904. "documents": [
  905. "77df9ef4759a11ef8bdd0242ac120004"
  906. ]
  907. }'
  908. ```
  909. #### Request parameter
  910. - `"question"`: (*Body parameter*), `string`, *Required*
  911. The user query or query keywords. Defaults to `""`.
  912. - `"datasets"`: (*Body parameter*) `list[string]`, *Required*
  913. The IDs of the datasets to search from.
  914. - `"documents"`: (*Body parameter*), `list[string]`
  915. The IDs of the documents to search from.
  916. - `"offset"`: (*Body parameter*), `integer`
  917. The starting index for the documents to retrieve. Defaults to `1`.
  918. - `"limit"`: (*Body parameter*)
  919. The maximum number of chunks to retrieve. Defaults to `1024`.
  920. - `"similarity_threshold"`: (*Body parameter*)
  921. The minimum similarity score. Defaults to `0.2`.
  922. - `"vector_similarity_weight"`: (*Body parameter*)
  923. The weight of vector cosine similarity. Defaults to `0.3`. If x represents the vector cosine similarity, then (1 - x) is the term similarity weight.
  924. - `"top_k"`: (*Body parameter*)
  925. The number of chunks engaged in vector cosine computaton. Defaults to `1024`.
  926. - `"rerank_id"`: (*Body parameter*)
  927. The ID of the rerank model.
  928. - `"keyword"`: (*Body parameter*), `boolean`
  929. Indicates whether to enable keyword-based matching:
  930. - `True`: Enable keyword-based matching.
  931. - `False`: Disable keyword-based matching (default).
  932. - `"highlight"`: (*Body parameter*), `boolean`
  933. Specifies whether to enable highlighting of matched terms in the results:
  934. - `True`: Enable highlighting of matched terms.
  935. - `False`: Disable highlighting of matched terms (default).
  936. ### Response
  937. Success:
  938. ```json
  939. {
  940. "code": 0,
  941. "data": {
  942. "chunks": [
  943. {
  944. "content": "ragflow content",
  945. "content_ltks": "ragflow content",
  946. "document_id": "5c5999ec7be811ef9cab0242ac120005",
  947. "document_keyword": "1.txt",
  948. "highlight": "<em>ragflow</em> content",
  949. "id": "d78435d142bd5cf6704da62c778795c5",
  950. "img_id": "",
  951. "important_keywords": [
  952. ""
  953. ],
  954. "kb_id": "c7ee74067a2c11efb21c0242ac120006",
  955. "positions": [
  956. ""
  957. ],
  958. "similarity": 0.9669436601210759,
  959. "term_similarity": 1.0,
  960. "vector_similarity": 0.8898122004035864
  961. }
  962. ],
  963. "doc_aggs": [
  964. {
  965. "count": 1,
  966. "doc_id": "5c5999ec7be811ef9cab0242ac120005",
  967. "doc_name": "1.txt"
  968. }
  969. ],
  970. "total": 1
  971. }
  972. }
  973. ```
  974. Failure:
  975. ```json
  976. {
  977. "code": 102,
  978. "message": "`datasets` is required."
  979. }
  980. ```
  981. ---
  982. :::tip API GROUPING
  983. Chat Assistant Management
  984. :::
  985. ---
  986. ## Create chat assistant
  987. **POST** `/api/v1/chat`
  988. Creates a chat assistant.
  989. ### Request
  990. - Method: POST
  991. - URL: `/api/v1/chat`
  992. - Headers:
  993. - `'content-Type: application/json'`
  994. - `'Authorization: Bearer {YOUR_API_KEY}'`
  995. - Body:
  996. - `"name"`: `string`
  997. - `"avatar"`: `string`
  998. - `"knowledgebases"`: `list[string]`
  999. - `"llm"`: `object`
  1000. - `"prompt"`: `object`
  1001. #### Request example
  1002. ```shell
  1003. curl --request POST \
  1004. --url http://{address}/api/v1/chat \
  1005. --header 'Content-Type: application/json' \
  1006. --header 'Authorization: Bearer {YOUR_API_KEY}'
  1007. --data-binary '{
  1008. "knowledgebases": [
  1009. {
  1010. "avatar": null,
  1011. "chunk_count": 0,
  1012. "description": null,
  1013. "document_count": 0,
  1014. "embedding_model": "",
  1015. "id": "0b2cbc8c877f11ef89070242ac120005",
  1016. "language": "English",
  1017. "name": "Test_assistant",
  1018. "parse_method": "naive",
  1019. "parser_config": {
  1020. "pages": [
  1021. [
  1022. 1,
  1023. 1000000
  1024. ]
  1025. ]
  1026. },
  1027. "permission": "me",
  1028. "tenant_id": "4fb0cd625f9311efba4a0242ac120006"
  1029. }
  1030. ],
  1031. "name":"new_chat_1"
  1032. }'
  1033. ```
  1034. #### Request parameters
  1035. - `"name"`: (*Body parameter*), `string`, *Required*
  1036. The name of the chat assistant.
  1037. - `"avatar"`: (*Body parameter*)
  1038. Base64 encoding of the avatar. Defaults to `""`.
  1039. - `"knowledgebases"`: (*Body parameter*)
  1040. The IDs of the associated datasets. Defaults to `[""]`.
  1041. - `"llm"`: (*Body parameter*), `object`
  1042. The LLM settings for the chat assistant to create. When the value is `None`, a dictionary with the following values will be generated as the default. An `llm` object contains the following attributes:
  1043. - `"model_name"`, `string`
  1044. The chat model name. If it is `None`, the user's default chat model will be returned.
  1045. - `"temperature"`: `float`
  1046. 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`.
  1047. - `"top_p"`: `float`
  1048. 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`
  1049. - `"presence_penalty"`: `float`
  1050. This discourages the model from repeating the same information by penalizing words that have already appeared in the conversation. Defaults to `0.2`.
  1051. - `"frequency penalty"`: `float`
  1052. Similar to the presence penalty, this reduces the model’s tendency to repeat the same words frequently. Defaults to `0.7`.
  1053. - `"max_token"`: `integer`
  1054. The maximum length of the model’s output, measured in the number of tokens (words or pieces of words). Defaults to `512`.
  1055. - `"prompt"`: (*Body parameter*), `object`
  1056. Instructions for the LLM to follow. A `prompt` object contains the following attributes:
  1057. - `"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`.
  1058. - `"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`.
  1059. - `"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`.
  1060. - `"variables"`: `object[]` This argument lists the variables to use in the 'System' field of **Chat Configurations**. Note that:
  1061. - `"knowledge"` is a reserved variable, which will be replaced with the retrieved chunks.
  1062. - All the variables in 'System' should be curly bracketed.
  1063. - The default value is `[{"key": "knowledge", "optional": True}]`
  1064. - `"rerank_model"`: `string` If it is not specified, vector cosine similarity will be used; otherwise, reranking score will be used. Defaults to `""`.
  1065. - `"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.
  1066. - `"opener"`: `string` The opening greeting for the user. Defaults to `"Hi! I am your assistant, can I help you?"`.
  1067. - `"show_quote`: `boolean` Indicates whether the source of text should be displayed. Defaults to `True`.
  1068. - `"prompt"`: `string` The prompt content. Defaults to `You are an intelligent assistant. Please summarize the content of the dataset 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.
  1069. Here is the knowledge base:
  1070. {knowledge}
  1071. The above is the knowledge base.`
  1072. ### Response
  1073. Success:
  1074. ```json
  1075. {
  1076. "code": 0,
  1077. "data": {
  1078. "avatar": "",
  1079. "create_date": "Fri, 11 Oct 2024 03:23:24 GMT",
  1080. "create_time": 1728617004635,
  1081. "description": "A helpful Assistant",
  1082. "do_refer": "1",
  1083. "id": "2ca4b22e878011ef88fe0242ac120005",
  1084. "knowledgebases": [
  1085. {
  1086. "avatar": null,
  1087. "chunk_count": 0,
  1088. "description": null,
  1089. "document_count": 0,
  1090. "embedding_model": "",
  1091. "id": "0b2cbc8c877f11ef89070242ac120005",
  1092. "language": "English",
  1093. "name": "Test_assistant",
  1094. "parse_method": "naive",
  1095. "parser_config": {
  1096. "pages": [
  1097. [
  1098. 1,
  1099. 1000000
  1100. ]
  1101. ]
  1102. },
  1103. "permission": "me",
  1104. "tenant_id": "4fb0cd625f9311efba4a0242ac120006"
  1105. }
  1106. ],
  1107. "language": "English",
  1108. "llm": {
  1109. "frequency_penalty": 0.7,
  1110. "max_tokens": 512,
  1111. "model_name": "deepseek-chat___OpenAI-API@OpenAI-API-Compatible",
  1112. "presence_penalty": 0.4,
  1113. "temperature": 0.1,
  1114. "top_p": 0.3
  1115. },
  1116. "name": "new_chat_1",
  1117. "prompt": {
  1118. "empty_response": "Sorry! 知识库中未找到相关内容!",
  1119. "keywords_similarity_weight": 0.3,
  1120. "opener": "您好,我是您的助手小樱,长得可爱又善良,can I help you?",
  1121. "prompt": "你是一个智能助手,请总结知识库的内容来回答问题,请列举知识库中的数据详细回答。当所有知识库内容都与问题无关时,你的回答必须包括“知识库中未找到您要的答案!”这句话。回答需要考虑聊天历史。\n 以下是知识库:\n {knowledge}\n 以上是知识库。",
  1122. "rerank_model": "",
  1123. "similarity_threshold": 0.2,
  1124. "top_n": 6,
  1125. "variables": [
  1126. {
  1127. "key": "knowledge",
  1128. "optional": false
  1129. }
  1130. ]
  1131. },
  1132. "prompt_type": "simple",
  1133. "status": "1",
  1134. "tenant_id": "69736c5e723611efb51b0242ac120007",
  1135. "top_k": 1024,
  1136. "update_date": "Fri, 11 Oct 2024 03:23:24 GMT",
  1137. "update_time": 1728617004635
  1138. }
  1139. }
  1140. ```
  1141. Failure:
  1142. ```json
  1143. {
  1144. "code": 102,
  1145. "message": "Duplicated chat name in creating dataset."
  1146. }
  1147. ```
  1148. ---
  1149. ## Update chat assistant
  1150. **PUT** `/api/v1/chat/{chat_id}`
  1151. Updates configurations for a specified chat assistant.
  1152. ### Request
  1153. - Method: PUT
  1154. - URL: `/api/v1/chat/{chat_id}`
  1155. - Headers:
  1156. - `'content-Type: application/json'`
  1157. - `'Authorization: Bearer {YOUR_API_KEY}'`
  1158. - Body:
  1159. - `"name"`: `string`
  1160. - `"avatar"`: `string`
  1161. - `"knowledgebases"`: `list[string]`
  1162. - `"llm"`: `object`
  1163. - `"prompt"`: `object`
  1164. #### Request example
  1165. ```bash
  1166. curl --request PUT \
  1167. --url http://{address}/api/v1/chat/{chat_id} \
  1168. --header 'Content-Type: application/json' \
  1169. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  1170. --data '{
  1171. "name":"Test"
  1172. }'
  1173. ```
  1174. #### Parameters
  1175. - `"name"`: (*Body parameter*), `string`, *Required*
  1176. The name of the chat assistant.
  1177. - `"avatar"`: (*Body parameter*)
  1178. Base64 encoding of the avatar. Defaults to `""`.
  1179. - `"knowledgebases"`: (*Body parameter*)
  1180. The IDs of the associated datasets. Defaults to `[""]`.
  1181. - `"llm"`: (*Body parameter*), `object`
  1182. The LLM settings for the chat assistant to create. When the value is `None`, a dictionary with the following values will be generated as the default. An `llm` object contains the following attributes:
  1183. - `"model_name"`, `string`
  1184. The chat model name. If it is `None`, the user's default chat model will be returned.
  1185. - `"temperature"`: `float`
  1186. 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`.
  1187. - `"top_p"`: `float`
  1188. 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`
  1189. - `"presence_penalty"`: `float`
  1190. This discourages the model from repeating the same information by penalizing words that have already appeared in the conversation. Defaults to `0.2`.
  1191. - `"frequency penalty"`: `float`
  1192. Similar to the presence penalty, this reduces the model’s tendency to repeat the same words frequently. Defaults to `0.7`.
  1193. - `"max_token"`: `integer`
  1194. The maximum length of the model’s output, measured in the number of tokens (words or pieces of words). Defaults to `512`.
  1195. - `"prompt"`: (*Body parameter*), `object`
  1196. Instructions for the LLM to follow. A `prompt` object contains the following attributes:
  1197. - `"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`.
  1198. - `"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`.
  1199. - `"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`.
  1200. - `"variables"`: `object[]` This argument lists the variables to use in the 'System' field of **Chat Configurations**. Note that:
  1201. - `"knowledge"` is a reserved variable, which will be replaced with the retrieved chunks.
  1202. - All the variables in 'System' should be curly bracketed.
  1203. - The default value is `[{"key": "knowledge", "optional": True}]`
  1204. - `"rerank_model"`: `string` If it is not specified, vector cosine similarity will be used; otherwise, reranking score will be used. Defaults to `""`.
  1205. - `"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.
  1206. - `"opener"`: `string` The opening greeting for the user. Defaults to `"Hi! I am your assistant, can I help you?"`.
  1207. - `"show_quote`: `boolean` Indicates whether the source of text should be displayed. Defaults to `True`.
  1208. - `"prompt"`: `string` The prompt content. Defaults to `You are an intelligent assistant. Please summarize the content of the dataset 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.
  1209. Here is the knowledge base:
  1210. {knowledge}
  1211. The above is the knowledge base.`
  1212. ### Response
  1213. Success:
  1214. ```json
  1215. {
  1216. "code": 0
  1217. }
  1218. ```
  1219. Failure:
  1220. ```json
  1221. {
  1222. "code": 102,
  1223. "message": "Duplicated chat name in updating dataset."
  1224. }
  1225. ```
  1226. ---
  1227. ## Delete chat assistants
  1228. **DELETE** `/api/v1/chat`
  1229. Deletes chat assistants by ID.
  1230. ### Request
  1231. - Method: DELETE
  1232. - URL: `/api/v1/chat`
  1233. - Headers:
  1234. - `'content-Type: application/json'`
  1235. - `'Authorization: Bearer {YOUR_API_KEY}'`
  1236. - Body:
  1237. - `"ids"`: `list[string]`
  1238. #### Request example
  1239. ```bash
  1240. # Either id or name must be provided, but not both.
  1241. curl --request DELETE \
  1242. --url http://{address}/api/v1/chat \
  1243. --header 'Content-Type: application/json' \
  1244. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  1245. --data '{
  1246. "ids": ["test_1", "test_2"]
  1247. }'
  1248. }'
  1249. ```
  1250. #### Request parameters
  1251. - `"ids"`: (*Body parameter*), `list[string]`
  1252. The IDs of the chat assistants to delete. If not specified, all chat assistants in the system will be deleted.
  1253. ### Response
  1254. Success:
  1255. ```json
  1256. {
  1257. "code": 0
  1258. }
  1259. ```
  1260. Failure:
  1261. ```json
  1262. {
  1263. "code": 102,
  1264. "message": "ids are required"
  1265. }
  1266. ```
  1267. ---
  1268. ## List chats
  1269. **GET** `/api/v1/chat?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={chat_name}&id={chat_id}`
  1270. Lists chat assistants.
  1271. ### Request
  1272. - Method: GET
  1273. - URL: `/api/v1/chat?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
  1274. - Headers:
  1275. - `'Authorization: Bearer {YOUR_API_KEY}'`
  1276. #### Request example
  1277. ```bash
  1278. curl --request GET \
  1279. --url http://{address}/api/v1/chat?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id} \
  1280. --header 'Authorization: Bearer {YOUR_API_KEY}'
  1281. ```
  1282. #### Request parameters
  1283. - `"page"`: (*Path parameter*), `integer`
  1284. Specifies the page on which the chat assistants will be displayed. Defaults to `1`.
  1285. - `"page_size"`: (*Path parameter*), `integer`
  1286. The number of chat assistants on each page. Defaults to `1024`.
  1287. - `"orderby"`: (*Path parameter*), `string`
  1288. The attribute by which the results are sorted. Available options:
  1289. - `"create_time"` (default)
  1290. - `"update_time"`
  1291. - `"desc"`: (*Path parameter*), `boolean`
  1292. Indicates whether the retrieved chat assistants should be sorted in descending order. Defaults to `True`.
  1293. - `"id"`: (*Path parameter*), `string`
  1294. The ID of the chat assistant to retrieve.
  1295. - `"name"`: (*Path parameter*), `string`
  1296. The name of the chat assistant to retrieve.
  1297. ### Response
  1298. Success:
  1299. ```json
  1300. {
  1301. "code": 0,
  1302. "data": [
  1303. {
  1304. "avatar": "",
  1305. "create_date": "Fri, 11 Oct 2024 03:23:24 GMT",
  1306. "create_time": 1728617004635,
  1307. "description": "A helpful Assistant",
  1308. "do_refer": "1",
  1309. "id": "2ca4b22e878011ef88fe0242ac120005",
  1310. "knowledgebases": [
  1311. {
  1312. "avatar": "",
  1313. "chunk_num": 0,
  1314. "create_date": "Fri, 11 Oct 2024 03:15:18 GMT",
  1315. "create_time": 1728616518986,
  1316. "created_by": "69736c5e723611efb51b0242ac120007",
  1317. "description": "",
  1318. "doc_num": 0,
  1319. "embd_id": "BAAI/bge-large-zh-v1.5",
  1320. "id": "0b2cbc8c877f11ef89070242ac120005",
  1321. "language": "English",
  1322. "name": "test_delete_chat",
  1323. "parser_config": {
  1324. "chunk_token_count": 128,
  1325. "delimiter": "\n!?。;!?",
  1326. "layout_recognize": true,
  1327. "task_page_size": 12
  1328. },
  1329. "parser_id": "naive",
  1330. "permission": "me",
  1331. "similarity_threshold": 0.2,
  1332. "status": "1",
  1333. "tenant_id": "69736c5e723611efb51b0242ac120007",
  1334. "token_num": 0,
  1335. "update_date": "Fri, 11 Oct 2024 04:01:31 GMT",
  1336. "update_time": 1728619291228,
  1337. "vector_similarity_weight": 0.3
  1338. }
  1339. ],
  1340. "language": "English",
  1341. "llm": {
  1342. "frequency_penalty": 0.7,
  1343. "max_tokens": 512,
  1344. "model_name": "deepseek-chat___OpenAI-API@OpenAI-API-Compatible",
  1345. "presence_penalty": 0.4,
  1346. "temperature": 0.1,
  1347. "top_p": 0.3
  1348. },
  1349. "name": "Test",
  1350. "prompt": {
  1351. "empty_response": "Sorry! 知识库中未找到相关内容!",
  1352. "keywords_similarity_weight": 0.3,
  1353. "opener": "您好,我是您的助手小樱,长得可爱又善良,can I help you?",
  1354. "prompt": "你是一个智能助手,请总结知识库的内容来回答问题,请列举知识库中的数据详细回答。当所有知识库内容都与问题无关时,你的回答必须包括“知识库中未找到您要的答案!”这句话。回答需要考虑聊天历史。\n 以下是知识库:\n {knowledge}\n 以上是知识库。",
  1355. "rerank_model": "",
  1356. "similarity_threshold": 0.2,
  1357. "top_n": 6,
  1358. "variables": [
  1359. {
  1360. "key": "knowledge",
  1361. "optional": false
  1362. }
  1363. ]
  1364. },
  1365. "prompt_type": "simple",
  1366. "status": "1",
  1367. "tenant_id": "69736c5e723611efb51b0242ac120007",
  1368. "top_k": 1024,
  1369. "update_date": "Fri, 11 Oct 2024 03:47:58 GMT",
  1370. "update_time": 1728618478392
  1371. }
  1372. ]
  1373. }
  1374. ```
  1375. Failure:
  1376. ```json
  1377. {
  1378. "code": 102,
  1379. "message": "The chat doesn't exist"
  1380. }
  1381. ```
  1382. ## Create session
  1383. **POST** `/api/v1/chat/{chat_id}/session`
  1384. Creates a chat session.
  1385. ### Request
  1386. - Method: POST
  1387. - URL: `/api/v1/chat/{chat_id}/session`
  1388. - Headers:
  1389. - `'content-Type: application/json'`
  1390. - `'Authorization: Bearer {YOUR_API_KEY}'`
  1391. - Body:
  1392. - `"name"`: `string`
  1393. #### Request example
  1394. ```bash
  1395. curl --request POST \
  1396. --url http://{address}/api/v1/chat/{chat_id}/session \
  1397. --header 'Content-Type: application/json' \
  1398. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  1399. --data '{
  1400. "name": "new session"
  1401. }'
  1402. ```
  1403. #### Request parameters
  1404. - `"name"`: (*Body parameter*), `string`
  1405. The name of the chat session to create.
  1406. ### Response
  1407. Success:
  1408. ```json
  1409. {
  1410. "code": 0,
  1411. "data": {
  1412. "chat_id": "2ca4b22e878011ef88fe0242ac120005",
  1413. "create_date": "Fri, 11 Oct 2024 08:46:14 GMT",
  1414. "create_time": 1728636374571,
  1415. "id": "4606b4ec87ad11efbc4f0242ac120006",
  1416. "messages": [
  1417. {
  1418. "content": "Hi! I am your assistant,can I help you?",
  1419. "role": "assistant"
  1420. }
  1421. ],
  1422. "name": "new session",
  1423. "update_date": "Fri, 11 Oct 2024 08:46:14 GMT",
  1424. "update_time": 1728636374571
  1425. }
  1426. }
  1427. ```
  1428. Failure:
  1429. ```json
  1430. {
  1431. "code": 102,
  1432. "message": "Name can not be empty."
  1433. }
  1434. ```
  1435. ---
  1436. ## Update session
  1437. **PUT** `/api/v1/chat/{chat_id}/session/{session_id}`
  1438. Update a chat session
  1439. ### Request
  1440. - Method: PUT
  1441. - URL: `/api/v1/chat/{chat_id}/session/{session_id}`
  1442. - Headers:
  1443. - `'content-Type: application/json'`
  1444. - `'Authorization: Bearer {YOUR_API_KEY}'`
  1445. - Body:
  1446. - `"name`: string
  1447. #### Request example
  1448. ```bash
  1449. curl --request PUT \
  1450. --url http://{address}/api/v1/chat/{chat_id}/session/{session_id} \
  1451. --header 'Content-Type: application/json' \
  1452. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  1453. --data '{
  1454. "name": "Updated session"
  1455. }'
  1456. ```
  1457. #### Request Parameter
  1458. - `"name`: (*Body Parameter), `string`
  1459. The name of the session to update.
  1460. ### Response
  1461. Success:
  1462. ```json
  1463. {
  1464. "code": 0
  1465. }
  1466. ```
  1467. Failure:
  1468. ```json
  1469. {
  1470. "code": 102,
  1471. "message": "Name can not be empty."
  1472. }
  1473. ```
  1474. ---
  1475. ## List sessions
  1476. **GET** `/api/v1/chat/{chat_id}/session?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={session_name}&id={session_id}`
  1477. Lists sessions associated with a specified chat assistant.
  1478. ### Request
  1479. - Method: GET
  1480. - URL: `/api/v1/chat/{chat_id}/session?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
  1481. - Headers:
  1482. - `'Authorization: Bearer {YOUR_API_KEY}'`
  1483. #### Request example
  1484. ```bash
  1485. curl --request GET \
  1486. --url http://{address}/api/v1/chat/{chat_id}/session?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id} \
  1487. --header 'Authorization: Bearer {YOUR_API_KEY}'
  1488. ```
  1489. #### Request Parameters
  1490. - `"page"`: (*Path parameter*), `integer`
  1491. Specifies the page on which the sessions will be displayed. Defaults to `1`.
  1492. - `"page_size"`: (*Path parameter*), `integer`
  1493. The number of sessions on each page. Defaults to `1024`.
  1494. - `"orderby"`: (*Path parameter*), `string`
  1495. The field by which sessions should be sorted. Available options:
  1496. - `"create_time"` (default)
  1497. - `"update_time"`
  1498. - `"desc"`: (*Path parameter*), `boolean`
  1499. Indicates whether the retrieved sessions should be sorted in descending order. Defaults to `True`.
  1500. - `"id"`: (*Path parameter*), `string`
  1501. The ID of the chat session to retrieve.
  1502. - `"name"`: (*Path parameter*) `string`
  1503. The name of the chat session to retrieve.
  1504. ### Response
  1505. Success:
  1506. ```json
  1507. {
  1508. "code": 0,
  1509. "data": [
  1510. {
  1511. "chat": "2ca4b22e878011ef88fe0242ac120005",
  1512. "create_date": "Fri, 11 Oct 2024 08:46:43 GMT",
  1513. "create_time": 1728636403974,
  1514. "id": "578d541e87ad11ef96b90242ac120006",
  1515. "messages": [
  1516. {
  1517. "content": "Hi! I am your assistant,can I help you?",
  1518. "role": "assistant"
  1519. }
  1520. ],
  1521. "name": "new session",
  1522. "update_date": "Fri, 11 Oct 2024 08:46:43 GMT",
  1523. "update_time": 1728636403974
  1524. }
  1525. ]
  1526. }
  1527. ```
  1528. Failure:
  1529. ```json
  1530. {
  1531. "code": 102,
  1532. "message": "The session doesn't exist"
  1533. }
  1534. ```
  1535. ---
  1536. ## Delete sessions
  1537. **DELETE** `/api/v1/chat/{chat_id}/session`
  1538. Deletes sessions by ID.
  1539. ### Request
  1540. - Method: DELETE
  1541. - URL: `/api/v1/chat/{chat_id}/session`
  1542. - Headers:
  1543. - `'content-Type: application/json'`
  1544. - `'Authorization: Bearer {YOUR_API_KEY}'`
  1545. - Body:
  1546. - `"ids"`: `list[string]`
  1547. #### Request example
  1548. ```bash
  1549. # Either id or name must be provided, but not both.
  1550. curl --request DELETE \
  1551. --url http://{address}/api/v1/chat/{chat_id}/session \
  1552. --header 'Content-Type: application/json' \
  1553. --header 'Authorization: Bear {YOUR_API_KEY}' \
  1554. --data '{
  1555. "ids": ["test_1", "test_2"]
  1556. }'
  1557. ```
  1558. #### Request Parameters
  1559. - `"ids"`: (*Body Parameter*), `list[string]`
  1560. The IDs of the sessions to delete. If not specified, all sessions associated with the current chat assistant will be deleted.
  1561. ### Response
  1562. Success:
  1563. ```json
  1564. {
  1565. "code": 0
  1566. }
  1567. ```
  1568. Failure:
  1569. ```json
  1570. {
  1571. "code": 102,
  1572. "message": "The chat doesn't own the session"
  1573. }
  1574. ```
  1575. ---
  1576. ## Chat
  1577. **POST** `/api/v1/chat/{chat_id}/completion`
  1578. Asks a question to start a conversation.
  1579. ### Request
  1580. - Method: POST
  1581. - URL: `/api/v1/chat/{chat_id}/completion`
  1582. - Headers:
  1583. - `'content-Type: application/json'`
  1584. - `'Authorization: Bearer {YOUR_API_KEY}'`
  1585. - Body:
  1586. - `"question"`: `string`
  1587. - `"stream"`: `boolean`
  1588. - `"session_id"`: `string`
  1589. #### Request example
  1590. ```bash
  1591. curl --request POST \
  1592. --url http://{address} /api/v1/chat/{chat_id}/completion \
  1593. --header 'Content-Type: application/json' \
  1594. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  1595. --data-binary '{
  1596. "question": "Hello!",
  1597. "stream": true
  1598. }'
  1599. ```
  1600. #### Request Parameters
  1601. - `"question"`: (*Body Parameter*), `string` *Required*
  1602. The question to start an AI chat.
  1603. - `"stream"`: (*Body Parameter*), `string`
  1604. Indicates whether to output responses in a streaming way:
  1605. - `True`: Enable streaming.
  1606. - `False`: (Default) Disable streaming.
  1607. - `"session_id"`: (*Body Parameter*)
  1608. The ID of session. If not provided, a new session will be generated.???????????????
  1609. ### Response
  1610. Success:
  1611. ```json
  1612. data: {
  1613. "code": 0,
  1614. "data": {
  1615. "answer": "您好!有什么具体的问题或者需要的帮助",
  1616. "reference": {},
  1617. "audio_binary": null,
  1618. "id": "31153052-7bac-4741-a513-ed07d853f29e"
  1619. }
  1620. }
  1621. data: {
  1622. "code": 0,
  1623. "data": {
  1624. "answer": "您好!有什么具体的问题或者需要的帮助可以告诉我吗?我在这里是为了帮助",
  1625. "reference": {},
  1626. "audio_binary": null,
  1627. "id": "31153052-7bac-4741-a513-ed07d853f29e"
  1628. }
  1629. }
  1630. data: {
  1631. "code": 0,
  1632. "data": {
  1633. "answer": "您好!有什么具体的问题或者需要的帮助可以告诉我吗?我在这里是为了帮助您的。如果您有任何疑问或是需要获取",
  1634. "reference": {},
  1635. "audio_binary": null,
  1636. "id": "31153052-7bac-4741-a513-ed07d853f29e"
  1637. }
  1638. }
  1639. data: {
  1640. "code": 0,
  1641. "data": {
  1642. "answer": "您好!有什么具体的问题或者需要的帮助可以告诉我吗?我在这里是为了帮助您的。如果您有任何疑问或是需要获取某些信息,请随时提出。",
  1643. "reference": {},
  1644. "audio_binary": null,
  1645. "id": "31153052-7bac-4741-a513-ed07d853f29e"
  1646. }
  1647. }
  1648. data: {
  1649. "code": 0,
  1650. "data": {
  1651. "answer": "您好!有什么具体的问题或者需要的帮助可以告诉我吗 ##0$$?我在这里是为了帮助您的。如果您有任何疑问或是需要获取某些信息,请随时提出。",
  1652. "reference": {
  1653. "total": 19,
  1654. "chunks": [
  1655. {
  1656. "chunk_id": "9d87f9d70a0d8a7565694a81fd4c5d5f",
  1657. "content_ltks": "当所有知识库内容都与问题无关时 ,你的回答必须包括“知识库中未找到您要的答案!”这句话。回答需要考虑聊天历史。\r\n以下是知识库:\r\n{knowledg}\r\n以上是知识库\r\n\"\"\"\r\n 1\r\n 2\r\n 3\r\n 4\r\n 5\r\n 6\r\n总结\r\n通过上面的介绍,可以对开源的 ragflow有了一个大致的了解,与前面的有道qanyth整体流程还是比较类似的。 ",
  1658. "content_with_weight": "当所有知识库内容都与问题无关时,你的回答必须包括“知识库中未找到您要的答案!”这句话。回答需要考虑聊天历史。\r\n 以下是知识库:\r\n {knowledge}\r\n 以上是知识库\r\n\"\"\"\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n总结\r\n通过上面的介绍,可以对开源的 RagFlow 有了一个大致的了解,与前面的 有道 QAnything 整体流程还是比较类似的。",
  1659. "doc_id": "5c5999ec7be811ef9cab0242ac120005",
  1660. "docnm_kwd": "1.txt",
  1661. "kb_id": "c7ee74067a2c11efb21c0242ac120006",
  1662. "important_kwd": [],
  1663. "img_id": "",
  1664. "similarity": 0.38337178633282265,
  1665. "vector_similarity": 0.3321336754679629,
  1666. "term_similarity": 0.4053309767034769,
  1667. "positions": [
  1668. ""
  1669. ]
  1670. },
  1671. {
  1672. "chunk_id": "895d34de762e674b43e8613c6fb54c6d",
  1673. "content_ltks": "\r\n\r\n实际内容可能会超过大模型的输入token数量,因此在调用大模型前会调用api/db/servic/dialog_service.py文件中 messag_fit_in ()根据大模型可用的 token数量进行过滤。这部分与有道的 qanyth的实现大同小异,就不额外展开了。\r\n\r\n将检索的内容,历史聊天记录以及问题构造为 prompt ,即可作为大模型的输入了 ,默认的英文prompt如下所示:\r\n\r\n\"\"\"\r\nyou are an intellig assistant. pleas summar the content of the knowledg base to answer the question. pleas list thedata in the knowledg base and answer in detail. when all knowledg base content is irrelev to the question , your answer must includ the sentenc\"the answer you are lookfor isnot found in the knowledg base!\" answer needto consid chat history.\r\n here is the knowledg base:\r\n{ knowledg}\r\nthe abov is the knowledg base.\r\n\"\"\"\r\n1\r\n 2\r\n 3\r\n 4\r\n 5\r\n 6\r\n对应的中文prompt如下所示:\r\n\r\n\"\"\"\r\n你是一个智能助手,请总结知识库的内容来回答问题,请列举知识库中的数据详细回答。 ",
  1674. "content_with_weight": "\r\n\r\n实际内容可能会超过大模型的输入 token 数量,因此在调用大模型前会调用 api/db/services/dialog_service.py 文件中 message_fit_in() 根据大模型可用的 token 数量进行过滤。这部分与有道的 QAnything 的实现大同小异,就不额外展开了。\r\n\r\n将检索的内容,历史聊天记录以及问题构造为 prompt,即可作为大模型的输入了,默认的英文 prompt 如下所示:\r\n\r\n\"\"\"\r\nYou 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.\r\n Here is the knowledge base:\r\n {knowledge}\r\n The above is the knowledge base.\r\n\"\"\"\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n对应的中文 prompt 如下所示:\r\n\r\n\"\"\"\r\n你是一个智能助手,请总结知识库的内容来回答问题,请列举知识库中的数据详细回答。",
  1675. "doc_id": "5c5999ec7be811ef9cab0242ac120005",
  1676. "docnm_kwd": "1.txt",
  1677. "kb_id": "c7ee74067a2c11efb21c0242ac120006",
  1678. "important_kwd": [],
  1679. "img_id": "",
  1680. "similarity": 0.2788204323926715,
  1681. "vector_similarity": 0.35489427679953667,
  1682. "term_similarity": 0.2462173562183008,
  1683. "positions": [
  1684. ""
  1685. ]
  1686. }
  1687. ],
  1688. "doc_aggs": [
  1689. {
  1690. "doc_name": "1.txt",
  1691. "doc_id": "5c5999ec7be811ef9cab0242ac120005",
  1692. "count": 2
  1693. }
  1694. ]
  1695. },
  1696. "prompt": "你是一个智能助手,请总结知识库的内容来回答问题,请列举知识库中的数据详细回答。当所有知识库内容都与问题无关时,你的回答必须包括“知识库中未找到您要的答案!”这句话。回答需要考虑聊天历史。\n 以下是知识库:\n 当所有知识库内容都与问题无关时,你的回答必须包括“知识库中未找到您要的答案!”这句话。回答需要考虑聊天历史。\r\n 以下是知识库:\r\n {knowledge}\r\n 以上是知识库\r\n\"\"\"\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n总结\r\n通过上面的介绍,可以对开源的 RagFlow 有了一个大致的了解,与前面的 有道 QAnything 整体流程还是比较类似的。\n\n------\n\n\r\n\r\n实际内容可能会超过大模型的输入 token 数量,因此在调用大模型前会调用 api/db/services/dialog_service.py 文件中 message_fit_in() 根据大模型可用的 token 数量进行过滤。这部分与有道的 QAnything 的实现大同小异,就不额外展开了。\r\n\r\n将检索的内容,历史聊天记录以及问题构造为 prompt,即可作为大模型的输入了,默认的英文 prompt 如下所示:\r\n\r\n\"\"\"\r\nYou 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.\r\n Here is the knowledge base:\r\n {knowledge}\r\n The above is the knowledge base.\r\n\"\"\"\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n对应的中文 prompt 如下所示:\r\n\r\n\"\"\"\r\n你是一个智能助手,请总结知识库的内容来回答问题,请列举知识库中的数据详细回答。\n 以上是知识库。\n\n### Query:\n你好,请问有什么问题需要我帮忙解答吗?\n\n### Elapsed\n - Retrieval: 9131.1 ms\n - LLM: 12802.6 ms",
  1697. "id": "31153052-7bac-4741-a513-ed07d853f29e"
  1698. }
  1699. }
  1700. data:{
  1701. "code": 0,
  1702. "data": true
  1703. }
  1704. ```
  1705. Failure:
  1706. ```json
  1707. {
  1708. "code": 102,
  1709. "message": "Please input your question."
  1710. }
  1711. ```