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

http_api_reference.md 59KB

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