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

http_api_reference.md 58KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183
  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=@./test.txt'
  336. ```
  337. #### Request parameters
  338. - `"dataset_id"`: (*Path parameter*)
  339. The ID of the dataset to which the documents will be uploaded.
  340. - `"file"`: (*Body parameter*)
  341. The document???? to upload.
  342. ### Response
  343. A successful response includes a JSON object like the following:
  344. ```json
  345. {
  346. "code": 0
  347. }
  348. ```
  349. An error response includes a JSON object like the following:
  350. ```json
  351. {
  352. "code": 101,
  353. "message": "No file part!"
  354. }
  355. ```
  356. ---
  357. ## Update document
  358. **PUT** `/api/v1/dataset/{dataset_id}/info/{document_id}`
  359. Updates configurations for a specified document.
  360. ### Request
  361. - Method: PUT
  362. - URL: `/api/v1/dataset/{dataset_id}/document/{document_id}`
  363. - Headers:
  364. - `'content-Type: application/json'`
  365. - `'Authorization: Bearer {YOUR_API_KEY}'`
  366. - Body:
  367. - `"name"`:`string`
  368. - `"chunk_method"`:`string`
  369. - `"parser_config"`:`dict`
  370. #### Request example
  371. ```bash
  372. curl --request PUT \
  373. --url http://{address}/api/v1/dataset/{dataset_id}/info/{document_id} \
  374. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  375. --header 'Content-Type: application/json' \
  376. --data '{
  377. "name": "manual.txt",
  378. "chunk_method": "manual",
  379. "parser_config": {"chunk_token_count": 128, "delimiter": "\n!?。;!?", "layout_recognize": true, "task_page_size": 12}
  380. }'
  381. ```
  382. #### Request parameters
  383. - `"name"`: (*Body parameter*), `string`
  384. - `"chunk_method"`: (*Body parameter*), `string`
  385. The parsing method to apply to the document.
  386. - `"naive"`: General
  387. - `"manual`: Manual
  388. - `"qa"`: Q&A
  389. - `"table"`: Table
  390. - `"paper"`: Paper
  391. - `"book"`: Book
  392. - `"laws"`: Laws
  393. - `"presentation"`: Presentation
  394. - `"picture"`: Picture
  395. - `"one"`: One
  396. - `"knowledge_graph"`: Knowledge Graph
  397. - `"email"`: Email
  398. -
  399. ### Returns
  400. - `"parser_config"`: (*Body parameter*)
  401. Configuration object for the parser.
  402. - If the value is `None`, a dictionary with default values will be generated.
  403. - `"name"`: (*Body parameter*)
  404. Name or title of the document.
  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 not own 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 document ID of the file.
  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. - `offset`: (*Filter parameter*)
  474. The beginning number of records for paging.
  475. - `keywords`: (*Filter parameter*)
  476. The keywords matches the search key workds;
  477. - `limit`: (*Filter parameter*)
  478. Records number to return.
  479. - `orderby`: (*Filter parameter*)
  480. The field by which the records should be sorted. This specifies the attribute or column used to order the results.
  481. - `desc`: (*Filter parameter*)
  482. A boolean flag indicating whether the sorting should be in descending order.
  483. - `id`: (*Filter parameter*)
  484. The ID of the document to retrieve.
  485. ### Response
  486. A successful response includes a JSON object like the following:
  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. An error response includes a JSON object like the following:
  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*)
  558. The IDs of the documents to delete.
  559. ### Response
  560. A successful response includes a JSON object like the following:
  561. ```json
  562. {
  563. "code": 0
  564. }.
  565. ```
  566. An error response includes a JSON object like the following:
  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. - `"document_ids"`:(*Body parameter*)
  596. The ids of the documents to parse.
  597. ### Response
  598. A successful response includes a JSON object like the following:
  599. ```json
  600. {
  601. "code": 0
  602. }
  603. ```
  604. An error response includes a JSON object like the following:
  605. ```json
  606. {
  607. "code": 102,
  608. "message": "`document_ids` is required"
  609. }
  610. ```
  611. ---
  612. ## Stop parsing documents
  613. **DELETE** `/api/v1/dataset/{dataset_id}/chunk`
  614. Stops parsing specified documents.
  615. ### Request
  616. - Method: DELETE
  617. - URL: `/api/v1/dataset/{dataset_id}/chunk`
  618. - Headers:
  619. - `'content-Type: application/json'`
  620. - `'Authorization: Bearer {YOUR_API_KEY}'`
  621. - Body:
  622. - `document_ids`: `list[string]`
  623. #### Request example
  624. ```bash
  625. curl --request DELETE \
  626. --url http://{address}/api/v1/dataset/{dataset_id}/chunk \
  627. --header 'Content-Type: application/json' \
  628. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  629. --data '{"document_ids": ["97a5f1c2759811efaa500242ac120004","97ad64b6759811ef9fc30242ac120004"]}'
  630. ```
  631. #### Request parameters
  632. - `"dataset_id"`: (*Path parameter*)
  633. - `"document_ids"`:(*Body parameter*)
  634. The IDs of the documents to parse.
  635. ### Response
  636. A successful response includes a JSON object like the following:
  637. ```json
  638. {
  639. "code": 0
  640. }
  641. ```
  642. An error response includes a JSON object like the following:
  643. ```json
  644. {
  645. "code": 102,
  646. "message": "`document_ids` is required"
  647. }
  648. ```
  649. ---
  650. ## Add chunks
  651. **POST** `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk`
  652. Adds a chunk to a specified document in a specified dataset.
  653. ### Request
  654. - Method: POST
  655. - URL: `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk`
  656. - Headers:
  657. - `'content-Type: application/json'`
  658. - `'Authorization: Bearer {YOUR_API_KEY}'`
  659. - Body:
  660. - `content`: string
  661. - `important_keywords`: `list[string]`
  662. #### Request example
  663. ```bash
  664. curl --request POST \
  665. --url http://{address}/api/v1/dataset/{dataset_id}/document/{document_id}/chunk \
  666. --header 'Content-Type: application/json' \
  667. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  668. --data '{
  669. "content": "ragflow content"
  670. }'
  671. ```
  672. #### Request parameters
  673. - `content`:(*Body parameter*)
  674. Contains the main text or information of the chunk.
  675. - `important_keywords`(*Body parameter*)
  676. List the key terms or phrases that are significant or central to the chunk's content.
  677. ### Response
  678. A successful response includes a JSON object like the following:
  679. ```json
  680. {
  681. "code": 0,
  682. "data": {
  683. "chunk": {
  684. "content": "ragflow content",
  685. "create_time": "2024-10-16 08:05:04",
  686. "create_timestamp": 1729065904.581025,
  687. "dataset_id": [
  688. "c7ee74067a2c11efb21c0242ac120006"
  689. ],
  690. "document_id": "5c5999ec7be811ef9cab0242ac120005",
  691. "id": "d78435d142bd5cf6704da62c778795c5",
  692. "important_keywords": []
  693. }
  694. }
  695. }
  696. ```
  697. An error response includes a JSON object like the following:
  698. ```json
  699. {
  700. "code": 102,
  701. "message": "`content` is required"
  702. }
  703. ```
  704. ---
  705. ## List chunks
  706. **GET** `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk?keywords={keywords}&offset={offset}&limit={limit}&id={id}`
  707. Lists chunks in a specified document.
  708. ### Request
  709. - Method: GET
  710. - URL: `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk?keywords={keywords}&offset={offset}&limit={limit}&id={id}`
  711. - Headers:
  712. - `'Authorization: Bearer {YOUR_API_KEY}'`
  713. #### Request example
  714. ```bash
  715. curl --request GET \
  716. --url http://{address}/api/v1/dataset/{dataset_id}/document/{document_id}/chunk?keywords={keywords}&offset={offset}&limit={limit}&id={id} \
  717. --header 'Authorization: Bearer {YOUR_API_KEY}'
  718. ```
  719. #### Request parameters
  720. - `"dataset_id"`: (*Path parameter*)
  721. - `"document_id"`: (*Path parameter*)
  722. - `"offset"`(*Filter parameter*)
  723. The beginning number of records for paging.
  724. - `"keywords"`(*Filter parameter*)
  725. List chunks whose name has the given keywords.
  726. - `"limit"`(*Filter parameter*)
  727. Records number to return.
  728. - `"id"`(*Filter parameter*)
  729. The ID of chunk to retrieve.
  730. ### Response
  731. A successful response includes a JSON object like the following:
  732. ```json
  733. {
  734. "code": 0,
  735. "data": {
  736. "chunks": [],
  737. "doc": {
  738. "chunk_num": 0,
  739. "create_date": "Sun, 29 Sep 2024 03:47:29 GMT",
  740. "create_time": 1727581649216,
  741. "created_by": "69736c5e723611efb51b0242ac120007",
  742. "id": "8cb781ec7e1511ef98ac0242ac120006",
  743. "kb_id": "c7ee74067a2c11efb21c0242ac120006",
  744. "location": "sunny_tomorrow.txt",
  745. "name": "sunny_tomorrow.txt",
  746. "parser_config": {
  747. "pages": [
  748. [
  749. 1,
  750. 1000000
  751. ]
  752. ]
  753. },
  754. "parser_id": "naive",
  755. "process_begin_at": "Tue, 15 Oct 2024 10:23:51 GMT",
  756. "process_duation": 1435.37,
  757. "progress": 0.0370833,
  758. "progress_msg": "\nTask has been received.",
  759. "run": "1",
  760. "size": 24,
  761. "source_type": "local",
  762. "status": "1",
  763. "thumbnail": null,
  764. "token_num": 0,
  765. "type": "doc",
  766. "update_date": "Tue, 15 Oct 2024 10:47:46 GMT",
  767. "update_time": 1728989266371
  768. },
  769. "total": 0
  770. }
  771. }
  772. ```
  773. An error response includes a JSON object like the following:
  774. ```json
  775. {
  776. "code": 102,
  777. "message": "You don't own the document 5c5999ec7be811ef9cab0242ac12000e5."
  778. }
  779. ```
  780. ---
  781. ## Delete chunks
  782. **DELETE** `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk`
  783. Deletes chunks by ID.
  784. ### Request
  785. - Method: DELETE
  786. - URL: `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk`
  787. - Headers:
  788. - `'content-Type: application/json'`
  789. - `'Authorization: Bearer {YOUR_API_KEY}'`
  790. - Body:
  791. - `chunk_ids`: `list[string]`
  792. #### Request example
  793. ```bash
  794. curl --request DELETE \
  795. --url http://{address}/api/v1/dataset/{dataset_id}/document/{document_id}/chunk \
  796. --header 'Content-Type: application/json' \
  797. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  798. --data '{
  799. "chunk_ids": ["test_1", "test_2"]
  800. }'
  801. ```
  802. #### Request parameters
  803. - `"chunk_ids"`:(*Body parameter*)
  804. The chunks of the document to delete.
  805. ### Response
  806. A successful response includes a JSON object like the following:
  807. ```json
  808. {
  809. "code": 0
  810. }
  811. ```
  812. An error response includes a JSON object like the following:
  813. ```json
  814. {
  815. "code": 102,
  816. "message": "`chunk_ids` is required"
  817. }
  818. ```
  819. ---
  820. ## Update chunk
  821. **PUT** `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk/{chunk_id}`
  822. Updates content or configurations for a specified chunk.
  823. ### Request
  824. - Method: PUT
  825. - URL: `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk/{chunk_id}`
  826. - Headers:
  827. - `'content-Type: application/json'`
  828. - `'Authorization: Bearer {YOUR_API_KEY}'`
  829. - Body:
  830. - `content`: `string`
  831. - `important_keywords`: `string`
  832. - `available`: `integer`
  833. #### Request example
  834. ```bash
  835. curl --request PUT \
  836. --url http://{address}/api/v1/dataset/{dataset_id}/document/{document_id}/chunk/{chunk_id} \
  837. --header 'Content-Type: application/json' \
  838. --header 'Authorization: {YOUR_API_KEY}' \
  839. --data '{
  840. "content": "ragflow123",
  841. "important_keywords": [],
  842. }'
  843. ```
  844. #### Request parameters
  845. - `"content"`:(*Body parameter*)
  846. Contains the main text or information of the chunk.
  847. - `"important_keywords"`:(*Body parameter*)
  848. Lists the key terms or phrases that are significant or central to the chunk's content.
  849. - `"available"`:(*Body parameter*)
  850. Indicating the availability status, 0 means unavailable and 1 means available.
  851. ### Response
  852. A successful response includes a JSON object like the following:
  853. ```json
  854. {
  855. "code": 0
  856. }
  857. ```
  858. An error response includes a JSON object like the following:
  859. ```json
  860. {
  861. "code": 102,
  862. "message": "Can't find this chunk 29a2d9987e16ba331fb4d7d30d99b71d2"
  863. }
  864. ```
  865. ---
  866. ## Retrieve chunks
  867. **GET** `/api/v1/retrieval`
  868. Retrieves chunks from specified datasets.
  869. ### Request
  870. - Method: POST
  871. - URL: `/api/v1/retrieval`
  872. - Headers:
  873. - `'content-Type: application/json'`
  874. - `'Authorization: Bearer {YOUR_API_KEY}'`
  875. - Body:
  876. - `question`: `string`
  877. - `datasets`: `list[string]`
  878. - `documents`: `list[string]`
  879. - `offset`: int
  880. - `limit`: int
  881. - `similarity_threshold`: float
  882. - `vector_similarity_weight`: float
  883. - `top_k`: int
  884. - `rerank_id`: string
  885. - `keyword`: bool
  886. - `highlight`: bool
  887. #### Request example
  888. ```bash
  889. curl --request POST \
  890. --url http://{address}/api/v1/retrieval \
  891. --header 'Content-Type: application/json' \
  892. --header 'Authorization: {YOUR_API_KEY}' \
  893. --data '{
  894. "question": "What is advantage of ragflow?",
  895. "datasets": [
  896. "b2a62730759d11ef987d0242ac120004"
  897. ],
  898. "documents": [
  899. "77df9ef4759a11ef8bdd0242ac120004"
  900. ]
  901. }'
  902. ```
  903. #### Request parameter
  904. - `"question"`: (*Body parameter*)
  905. User's question, search keywords
  906. `""`
  907. - `"datasets"`: (*Body parameter*)
  908. The scope of datasets
  909. `None`
  910. - `"documents"`: (*Body parameter*)
  911. The scope of document. `None` means no limitation
  912. `None`
  913. - `"offset"`: (*Body parameter*)
  914. The beginning point of retrieved records
  915. `1`
  916. - `"limit"`: (*Body parameter*)
  917. The maximum number of records needed to return
  918. `30`
  919. - `"similarity_threshold"`: (*Body parameter*)
  920. The minimum similarity score
  921. `0.2`
  922. - `"vector_similarity_weight"`: (*Body parameter*)
  923. The weight of vector cosine similarity, `1 - x` is the term similarity weight
  924. `0.3`
  925. - `"top_k"`: (*Body parameter*)
  926. Number of records engaged in vector cosine computation
  927. `1024`
  928. - `"rerank_id"`: (*Body parameter*)
  929. ID of the rerank model
  930. `None`
  931. - `"keyword"`: (*Body parameter*)
  932. Whether keyword-based matching is enabled
  933. `False`
  934. - `"highlight"`: (*Body parameter*)
  935. Whether to enable highlighting of matched terms in the results
  936. `False`
  937. ### Response
  938. A successful response includes a JSON object like the following:
  939. ```json
  940. {
  941. "code": 0,
  942. "data": {
  943. "chunks": [
  944. {
  945. "content": "ragflow content",
  946. "content_ltks": "ragflow content",
  947. "document_id": "5c5999ec7be811ef9cab0242ac120005",
  948. "document_keyword": "1.txt",
  949. "highlight": "<em>ragflow</em> content",
  950. "id": "d78435d142bd5cf6704da62c778795c5",
  951. "img_id": "",
  952. "important_keywords": [
  953. ""
  954. ],
  955. "kb_id": "c7ee74067a2c11efb21c0242ac120006",
  956. "positions": [
  957. ""
  958. ],
  959. "similarity": 0.9669436601210759,
  960. "term_similarity": 1.0,
  961. "vector_similarity": 0.8898122004035864
  962. }
  963. ],
  964. "doc_aggs": [
  965. {
  966. "count": 1,
  967. "doc_id": "5c5999ec7be811ef9cab0242ac120005",
  968. "doc_name": "1.txt"
  969. }
  970. ],
  971. "total": 1
  972. }
  973. }
  974. ```
  975. An error response includes a JSON object like the following:
  976. ```json
  977. {
  978. "code": 102,
  979. "message": "`datasets` is required."
  980. }
  981. ```
  982. ---
  983. :::tip API GROUPING
  984. Chat Assistant Management
  985. :::
  986. ---
  987. ## Create chat assistant
  988. **POST** `/api/v1/chat`
  989. Creates a chat assistant.
  990. ### Request
  991. - Method: POST
  992. - URL: `/api/v1/chat`
  993. - Headers:
  994. - `'content-Type: application/json'`
  995. - `'Authorization: Bearer {YOUR_API_KEY}'`
  996. - Body:
  997. - `"name"`: `string`
  998. - `"avatar"`: `string`
  999. - `"knowledgebases"`: `List[DataSet]`
  1000. - `"id"`: `string`
  1001. - `"llm"`: `LLM`
  1002. - `"prompt"`: `Prompt`
  1003. #### Request example
  1004. ```shell
  1005. curl --request POST \
  1006. --url http://{address}/api/v1/chat \
  1007. --header 'Content-Type: application/json' \
  1008. --header 'Authorization: Bearer {YOUR_API_KEY}'
  1009. --data-binary '{
  1010. "knowledgebases": [
  1011. {
  1012. "avatar": null,
  1013. "chunk_count": 0,
  1014. "description": null,
  1015. "document_count": 0,
  1016. "embedding_model": "",
  1017. "id": "0b2cbc8c877f11ef89070242ac120005",
  1018. "language": "English",
  1019. "name": "Test_assistant",
  1020. "parse_method": "naive",
  1021. "parser_config": {
  1022. "pages": [
  1023. [
  1024. 1,
  1025. 1000000
  1026. ]
  1027. ]
  1028. },
  1029. "permission": "me",
  1030. "tenant_id": "4fb0cd625f9311efba4a0242ac120006"
  1031. }
  1032. ],
  1033. "name":"new_chat_1"
  1034. }'
  1035. ```
  1036. #### Request parameters
  1037. - `"name"`: (*Body parameter*)
  1038. The name of the created chat.
  1039. - `"assistant"`
  1040. - `"avatar"`: (*Body parameter*)
  1041. The icon of the created chat.
  1042. - `"path"`
  1043. - `"knowledgebases"`: (*Body parameter*)
  1044. Select knowledgebases associated.
  1045. - `["kb1"]`
  1046. - `"id"`: (*Body parameter*)
  1047. The id of the created chat.
  1048. - `""`
  1049. - `"llm"`: (*Body parameter*)
  1050. The LLM of the created chat.
  1051. - If the value is `None`, a dictionary with default values will be generated.
  1052. - `"prompt"`: (*Body parameter*)
  1053. The prompt of the created chat.
  1054. - If the value is `None`, a dictionary with default values will be generated.
  1055. ---
  1056. ##### Chat.LLM parameters
  1057. - `"model_name"`: (*Body parameter*)
  1058. Large language chat model.
  1059. - If it is `None`, it will return the user's default model.
  1060. - `"temperature"`: (*Body parameter*)
  1061. 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.
  1062. - `0.1`
  1063. - `"top_p"`: (*Body parameter*)
  1064. Also known as "nucleus sampling," it focuses on the most likely words, cutting off the less probable ones.
  1065. - `0.3`
  1066. - `"presence_penalty"`: (*Body parameter*)
  1067. Discourages the model from repeating the same information by penalizing repeated content.
  1068. - `0.4`
  1069. - `"frequency_penalty"`: (*Body parameter*)
  1070. Reduces the model’s tendency to repeat words frequently.
  1071. - `0.7`
  1072. - `"max_tokens"`: (*Body parameter*)
  1073. Sets the maximum length of the model’s output, measured in tokens (words or pieces of words).
  1074. - `512`
  1075. ---
  1076. ##### Chat.Prompt parameters
  1077. - `"similarity_threshold"`: (*Body parameter*)
  1078. Filters out chunks with similarity below this threshold.
  1079. - `0.2`
  1080. - `"keywords_similarity_weight"`: (*Body parameter*)
  1081. Weighted keywords similarity and vector cosine similarity; the sum of weights is 1.0.
  1082. - `0.7`
  1083. - `"top_n"`: (*Body parameter*)
  1084. Only the top N chunks above the similarity threshold will be fed to LLMs.
  1085. - `8`
  1086. - `"variables"`: (*Body parameter*)
  1087. Variables help with different chat strategies by filling in the 'System' part of the prompt.
  1088. - `[{"key": "knowledge", "optional": True}]`
  1089. - `"rerank_model"`: (*Body parameter*)
  1090. If empty, it uses vector cosine similarity; otherwise, it uses rerank score.
  1091. - `""`
  1092. - `"empty_response"`: (*Body parameter*)
  1093. If nothing is retrieved, this will be used as the response. Leave blank if LLM should provide its own opinion.
  1094. - `None`
  1095. - `"opener"`: (*Body parameter*)
  1096. The welcome message for clients.
  1097. - `"Hi! I'm your assistant, what can I do for you?"`
  1098. - `"show_quote"`: (*Body parameter*)
  1099. Indicates whether the source of the original text should be displayed.
  1100. - `True`
  1101. - `"prompt"`: (*Body parameter*)
  1102. Instructions for LLM to follow when answering questions, such as character design or answer length.
  1103. - `"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."`
  1104. ### Response
  1105. A successful response includes a JSON object like the following:
  1106. ```json
  1107. {
  1108. "code": 0,
  1109. "data": {
  1110. "avatar": "",
  1111. "create_date": "Fri, 11 Oct 2024 03:23:24 GMT",
  1112. "create_time": 1728617004635,
  1113. "description": "A helpful Assistant",
  1114. "do_refer": "1",
  1115. "id": "2ca4b22e878011ef88fe0242ac120005",
  1116. "knowledgebases": [
  1117. {
  1118. "avatar": null,
  1119. "chunk_count": 0,
  1120. "description": null,
  1121. "document_count": 0,
  1122. "embedding_model": "",
  1123. "id": "0b2cbc8c877f11ef89070242ac120005",
  1124. "language": "English",
  1125. "name": "Test_assistant",
  1126. "parse_method": "naive",
  1127. "parser_config": {
  1128. "pages": [
  1129. [
  1130. 1,
  1131. 1000000
  1132. ]
  1133. ]
  1134. },
  1135. "permission": "me",
  1136. "tenant_id": "4fb0cd625f9311efba4a0242ac120006"
  1137. }
  1138. ],
  1139. "language": "English",
  1140. "llm": {
  1141. "frequency_penalty": 0.7,
  1142. "max_tokens": 512,
  1143. "model_name": "deepseek-chat___OpenAI-API@OpenAI-API-Compatible",
  1144. "presence_penalty": 0.4,
  1145. "temperature": 0.1,
  1146. "top_p": 0.3
  1147. },
  1148. "name": "new_chat_1",
  1149. "prompt": {
  1150. "empty_response": "Sorry! 知识库中未找到相关内容!",
  1151. "keywords_similarity_weight": 0.3,
  1152. "opener": "您好,我是您的助手小樱,长得可爱又善良,can I help you?",
  1153. "prompt": "你是一个智能助手,请总结知识库的内容来回答问题,请列举知识库中的数据详细回答。当所有知识库内容都与问题无关时,你的回答必须包括“知识库中未找到您要的答案!”这句话。回答需要考虑聊天历史。\n 以下是知识库:\n {knowledge}\n 以上是知识库。",
  1154. "rerank_model": "",
  1155. "similarity_threshold": 0.2,
  1156. "top_n": 6,
  1157. "variables": [
  1158. {
  1159. "key": "knowledge",
  1160. "optional": false
  1161. }
  1162. ]
  1163. },
  1164. "prompt_type": "simple",
  1165. "status": "1",
  1166. "tenant_id": "69736c5e723611efb51b0242ac120007",
  1167. "top_k": 1024,
  1168. "update_date": "Fri, 11 Oct 2024 03:23:24 GMT",
  1169. "update_time": 1728617004635
  1170. }
  1171. }
  1172. ```
  1173. An error response includes a JSON object like the following:
  1174. ```json
  1175. {
  1176. "code": 102,
  1177. "message": "Duplicated chat name in creating dataset."
  1178. }
  1179. ```
  1180. ---
  1181. ## Update chat assistant
  1182. **PUT** `/api/v1/chat/{chat_id}`
  1183. Updates configurations for a specified chat assistant.
  1184. ### Request
  1185. - Method: PUT
  1186. - URL: `/api/v1/chat/{chat_id}`
  1187. - Headers:
  1188. - `'content-Type: application/json'`
  1189. - `'Authorization: Bearer {YOUR_API_KEY}'`
  1190. - Body: (Refer to the "Create chat" for the complete structure of the request body.)
  1191. #### Request example
  1192. ```bash
  1193. curl --request PUT \
  1194. --url http://{address}/api/v1/chat/{chat_id} \
  1195. --header 'Content-Type: application/json' \
  1196. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  1197. --data '{
  1198. "name":"Test"
  1199. }'
  1200. ```
  1201. #### Parameters
  1202. Refer to the "Create chat" for the complete structure of the request parameters.
  1203. ### Response
  1204. A successful response includes a JSON object like the following:
  1205. ```json
  1206. {
  1207. "code": 0
  1208. }
  1209. ```
  1210. An error response includes a JSON object like the following:
  1211. ```json
  1212. {
  1213. "code": 102,
  1214. "message": "Duplicated chat name in updating dataset."
  1215. }
  1216. ```
  1217. ---
  1218. ## Delete chat assistants
  1219. **DELETE** `/api/v1/chat`
  1220. Deletes chat assistants by ID.
  1221. ### Request
  1222. - Method: DELETE
  1223. - URL: `/api/v1/chat`
  1224. - Headers:
  1225. - `'content-Type: application/json'`
  1226. - `'Authorization: Bearer {YOUR_API_KEY}'`
  1227. - Body:
  1228. - `ids`: list[string]
  1229. #### Request example
  1230. ```bash
  1231. # Either id or name must be provided, but not both.
  1232. curl --request DELETE \
  1233. --url http://{address}/api/v1/chat \
  1234. --header 'Content-Type: application/json' \
  1235. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  1236. --data '{
  1237. "ids": ["test_1", "test_2"]
  1238. }'
  1239. }'
  1240. ```
  1241. #### Request parameters
  1242. - `"ids"`: (*Body parameter*)
  1243. IDs of the chats to delete.
  1244. - `None`
  1245. ### Response
  1246. A successful response includes a JSON object like the following:
  1247. ```json
  1248. {
  1249. "code": 0
  1250. }
  1251. ```
  1252. An error response includes a JSON object like the following:
  1253. ```json
  1254. {
  1255. "code": 102,
  1256. "message": "ids are required"
  1257. }
  1258. ```
  1259. ---
  1260. ## List chats
  1261. **GET** `/api/v1/chat?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={chat_name}&id={chat_id}`
  1262. Lists chat assistants.
  1263. ### Request
  1264. - Method: GET
  1265. - URL: `/api/v1/chat?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
  1266. - Headers:
  1267. - `'Authorization: Bearer {YOUR_API_KEY}'`
  1268. #### Request example
  1269. ```bash
  1270. curl --request GET \
  1271. --url http://{address}/api/v1/chat?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id} \
  1272. --header 'Authorization: Bearer {YOUR_API_KEY}'
  1273. ```
  1274. #### Request parameters
  1275. - `"page"`: (*Path parameter*)
  1276. The current page number to retrieve from the paginated data. This parameter determines which set of records will be fetched.
  1277. - `1`
  1278. - `"page_size"`: (*Path parameter*)
  1279. The number of records to retrieve per page. This controls how many records will be included in each page.
  1280. - `1024`
  1281. - `"orderby"`: (*Path parameter*)
  1282. The field by which the records should be sorted. This specifies the attribute or column used to order the results.
  1283. - `"create_time"`
  1284. - `"desc"`: (*Path parameter*)
  1285. A boolean flag indicating whether the sorting should be in descending order.
  1286. - `True`
  1287. - `"id"`: (*Path parameter*)
  1288. The ID of the chat to retrieve.
  1289. - `None`
  1290. - `"name"`: (*Path parameter*)
  1291. The name of the chat to retrieve.
  1292. - `None`
  1293. ### Response
  1294. A successful response includes a JSON object like the following:
  1295. ```json
  1296. {
  1297. "code": 0,
  1298. "data": [
  1299. {
  1300. "avatar": "",
  1301. "create_date": "Fri, 11 Oct 2024 03:23:24 GMT",
  1302. "create_time": 1728617004635,
  1303. "description": "A helpful Assistant",
  1304. "do_refer": "1",
  1305. "id": "2ca4b22e878011ef88fe0242ac120005",
  1306. "knowledgebases": [
  1307. {
  1308. "avatar": "",
  1309. "chunk_num": 0,
  1310. "create_date": "Fri, 11 Oct 2024 03:15:18 GMT",
  1311. "create_time": 1728616518986,
  1312. "created_by": "69736c5e723611efb51b0242ac120007",
  1313. "description": "",
  1314. "doc_num": 0,
  1315. "embd_id": "BAAI/bge-large-zh-v1.5",
  1316. "id": "0b2cbc8c877f11ef89070242ac120005",
  1317. "language": "English",
  1318. "name": "test_delete_chat",
  1319. "parser_config": {
  1320. "chunk_token_count": 128,
  1321. "delimiter": "\n!?。;!?",
  1322. "layout_recognize": true,
  1323. "task_page_size": 12
  1324. },
  1325. "parser_id": "naive",
  1326. "permission": "me",
  1327. "similarity_threshold": 0.2,
  1328. "status": "1",
  1329. "tenant_id": "69736c5e723611efb51b0242ac120007",
  1330. "token_num": 0,
  1331. "update_date": "Fri, 11 Oct 2024 04:01:31 GMT",
  1332. "update_time": 1728619291228,
  1333. "vector_similarity_weight": 0.3
  1334. }
  1335. ],
  1336. "language": "English",
  1337. "llm": {
  1338. "frequency_penalty": 0.7,
  1339. "max_tokens": 512,
  1340. "model_name": "deepseek-chat___OpenAI-API@OpenAI-API-Compatible",
  1341. "presence_penalty": 0.4,
  1342. "temperature": 0.1,
  1343. "top_p": 0.3
  1344. },
  1345. "name": "Test",
  1346. "prompt": {
  1347. "empty_response": "Sorry! 知识库中未找到相关内容!",
  1348. "keywords_similarity_weight": 0.3,
  1349. "opener": "您好,我是您的助手小樱,长得可爱又善良,can I help you?",
  1350. "prompt": "你是一个智能助手,请总结知识库的内容来回答问题,请列举知识库中的数据详细回答。当所有知识库内容都与问题无关时,你的回答必须包括“知识库中未找到您要的答案!”这句话。回答需要考虑聊天历史。\n 以下是知识库:\n {knowledge}\n 以上是知识库。",
  1351. "rerank_model": "",
  1352. "similarity_threshold": 0.2,
  1353. "top_n": 6,
  1354. "variables": [
  1355. {
  1356. "key": "knowledge",
  1357. "optional": false
  1358. }
  1359. ]
  1360. },
  1361. "prompt_type": "simple",
  1362. "status": "1",
  1363. "tenant_id": "69736c5e723611efb51b0242ac120007",
  1364. "top_k": 1024,
  1365. "update_date": "Fri, 11 Oct 2024 03:47:58 GMT",
  1366. "update_time": 1728618478392
  1367. }
  1368. ]
  1369. }
  1370. ```
  1371. An error response includes a JSON object like the following:
  1372. ```json
  1373. {
  1374. "code": 102,
  1375. "message": "The chat doesn't exist"
  1376. }
  1377. ```
  1378. ## Create chat session
  1379. **POST** `/api/v1/chat/{chat_id}/session`
  1380. Create a chat session.
  1381. ### Request
  1382. - Method: POST
  1383. - URL: `/api/v1/chat/{chat_id}/session`
  1384. - Headers:
  1385. - `'content-Type: application/json'`
  1386. - `'Authorization: Bearer {YOUR_API_KEY}'`
  1387. - Body:
  1388. - name: `string`
  1389. #### Request example
  1390. ```bash
  1391. curl --request POST \
  1392. --url http://{address}/api/v1/chat/{chat_id}/session \
  1393. --header 'Content-Type: application/json' \
  1394. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  1395. --data '{
  1396. "name": "new session"
  1397. }'
  1398. ```
  1399. #### Request parameters
  1400. - `"id"`: (*Body parameter*)
  1401. The ID of the created session used to identify different sessions.
  1402. - `None`
  1403. - `id` cannot be provided when creating.
  1404. - `"name"`: (*Body parameter*)
  1405. The name of the created session.
  1406. - `"New session"`
  1407. - `"messages"`: (*Body parameter*)
  1408. The messages of the created session.
  1409. - `[{"role": "assistant", "content": "Hi! I am your assistant, can I help you?"}]`
  1410. - `messages` cannot be provided when creating.
  1411. - `"chat_id"`: (*Path parameter*)
  1412. The ID of the associated chat.
  1413. - `""`
  1414. - `chat_id` cannot be changed.
  1415. ### Response
  1416. A successful response includes a JSON object like the following:
  1417. ```json
  1418. {
  1419. "code": 0,
  1420. "data": {
  1421. "chat_id": "2ca4b22e878011ef88fe0242ac120005",
  1422. "create_date": "Fri, 11 Oct 2024 08:46:14 GMT",
  1423. "create_time": 1728636374571,
  1424. "id": "4606b4ec87ad11efbc4f0242ac120006",
  1425. "messages": [
  1426. {
  1427. "content": "Hi! I am your assistant,can I help you?",
  1428. "role": "assistant"
  1429. }
  1430. ],
  1431. "name": "new session",
  1432. "update_date": "Fri, 11 Oct 2024 08:46:14 GMT",
  1433. "update_time": 1728636374571
  1434. }
  1435. }
  1436. ```
  1437. An error response includes a JSON object like the following:
  1438. ```json
  1439. {
  1440. "code": 102,
  1441. "message": "Name can not be empty."
  1442. }
  1443. ```
  1444. ---
  1445. :::tip API GROUPING
  1446. Chat Session APIs
  1447. :::
  1448. ---
  1449. =========MISSING CREATE SESSION API!==============
  1450. ---
  1451. ## Update a chat session
  1452. **PUT** `/api/v1/chat/{chat_id}/session/{session_id}`
  1453. Update a chat session
  1454. ### Request
  1455. - Method: PUT
  1456. - URL: `/api/v1/chat/{chat_id}/session/{session_id}`
  1457. - Headers:
  1458. - `'content-Type: application/json'`
  1459. - `'Authorization: Bearer {YOUR_API_KEY}'`
  1460. - Body:
  1461. - `name`: string
  1462. #### Request example
  1463. ```bash
  1464. curl --request PUT \
  1465. --url http://{address}/api/v1/chat/{chat_id}/session/{session_id} \
  1466. --header 'Content-Type: application/json' \
  1467. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  1468. --data '{
  1469. "name": "Updated session"
  1470. }'
  1471. ```
  1472. #### Request Parameter
  1473. - `name`: (*Body Parameter)
  1474. The name of the created session.
  1475. - `None`
  1476. ### Response
  1477. A successful response includes a JSON object like the following:
  1478. ```json
  1479. {
  1480. "code": 0
  1481. }
  1482. ```
  1483. An error response includes a JSON object like the following:
  1484. ```json
  1485. {
  1486. "code": 102,
  1487. "message": "Name can not be empty."
  1488. }
  1489. ```
  1490. ---
  1491. ## List sessions
  1492. **GET** `/api/v1/chat/{chat_id}/session?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
  1493. Lists sessions associated with a specified????????????? chat assistant.
  1494. ### Request
  1495. - Method: GET
  1496. - URL: `/api/v1/chat/{chat_id}/session?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
  1497. - Headers:
  1498. - `'Authorization: Bearer {YOUR_API_KEY}'`
  1499. #### Request example
  1500. ```bash
  1501. curl --request GET \
  1502. --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} \
  1503. --header 'Authorization: Bearer {YOUR_API_KEY}'
  1504. ```
  1505. #### Request Parameters
  1506. - `"page"`: (*Path parameter*)
  1507. The current page number to retrieve from the paginated data. This parameter determines which set of records will be fetched.
  1508. - `1`
  1509. - `"page_size"`: (*Path parameter*)
  1510. The number of records to retrieve per page. This controls how many records will be included in each page.
  1511. - `1024`
  1512. - `"orderby"`: (*Path parameter*)
  1513. The field by which the records should be sorted. This specifies the attribute or column used to order the results.
  1514. - `"create_time"`
  1515. - `"desc"`: (*Path parameter*)
  1516. A boolean flag indicating whether the sorting should be in descending order.
  1517. - `True`
  1518. - `"id"`: (*Path parameter*)
  1519. The ID of the session to retrieve.
  1520. - `None`
  1521. - `"name"`: (*Path parameter*)
  1522. The name of the session to retrieve.
  1523. - `None`
  1524. ### Response
  1525. A successful response includes a JSON object like the following:
  1526. ```json
  1527. {
  1528. "code": 0,
  1529. "data": [
  1530. {
  1531. "chat": "2ca4b22e878011ef88fe0242ac120005",
  1532. "create_date": "Fri, 11 Oct 2024 08:46:43 GMT",
  1533. "create_time": 1728636403974,
  1534. "id": "578d541e87ad11ef96b90242ac120006",
  1535. "messages": [
  1536. {
  1537. "content": "Hi! I am your assistant,can I help you?",
  1538. "role": "assistant"
  1539. }
  1540. ],
  1541. "name": "new session",
  1542. "update_date": "Fri, 11 Oct 2024 08:46:43 GMT",
  1543. "update_time": 1728636403974
  1544. }
  1545. ]
  1546. }
  1547. ```
  1548. An error response includes a JSON object like the following:
  1549. ```json
  1550. {
  1551. "code": 102,
  1552. "message": "The session doesn't exist"
  1553. }
  1554. ```
  1555. ---
  1556. ## Delete sessions
  1557. **DELETE** `/api/v1/chat/{chat_id}/session`
  1558. Deletes sessions by ID.
  1559. ### Request
  1560. - Method: DELETE
  1561. - URL: `/api/v1/chat/{chat_id}/session`
  1562. - Headers:
  1563. - `'content-Type: application/json'`
  1564. - `'Authorization: Bearer {YOUR_API_KEY}'`
  1565. - Body:
  1566. - `ids`: list[string]
  1567. #### Request example
  1568. ```bash
  1569. # Either id or name must be provided, but not both.
  1570. curl --request DELETE \
  1571. --url http://{address}/api/v1/chat/{chat_id}/session \
  1572. --header 'Content-Type: application/json' \
  1573. --header 'Authorization: Bear {YOUR_API_KEY}' \
  1574. --data '{
  1575. "ids": ["test_1", "test_2"]
  1576. }'
  1577. ```
  1578. #### Request Parameters
  1579. - `ids`: (*Body Parameter*)
  1580. IDs of the sessions to delete.
  1581. - `None`
  1582. ### Response
  1583. A successful response includes a JSON object like the following:
  1584. ```json
  1585. {
  1586. "code": 0
  1587. }
  1588. ```
  1589. An error response includes a JSON object like the following:
  1590. ```json
  1591. {
  1592. "code": 102,
  1593. "message": "The chat doesn't own the session"
  1594. }
  1595. ```
  1596. ---
  1597. ## Chat with a chat session???
  1598. **POST** `/api/v1/chat/{chat_id}/completion`
  1599. Asks a question to start a conversation.
  1600. ### Request
  1601. - Method: POST
  1602. - URL: `/api/v1/chat/{chat_id}/completion`
  1603. - Headers:
  1604. - `'content-Type: application/json'`
  1605. - `'Authorization: Bearer {YOUR_API_KEY}'`
  1606. - Body:
  1607. - `question`: `string`
  1608. - `stream`: `bool`
  1609. - `session_id`: `string`
  1610. #### Request example
  1611. ```bash
  1612. curl --request POST \
  1613. --url http://{address} /api/v1/chat/{chat_id}/completion \
  1614. --header 'Content-Type: application/json' \
  1615. --header 'Authorization: Bearer {YOUR_API_KEY}' \
  1616. --data-binary '{
  1617. "question": "你好!",
  1618. "stream": true
  1619. }'
  1620. ```
  1621. #### Request Parameters
  1622. - `question`:(*Body Parameter*)
  1623. The question you want to ask.
  1624. - question is required.
  1625. `None`
  1626. - `stream`: (*Body Parameter*)
  1627. The approach of streaming text generation.
  1628. `False`
  1629. - `session_id`: (*Body Parameter*)
  1630. The ID of session. If not provided, a new session will be generated.
  1631. ### Response
  1632. A successful response includes a JSON object like the following:
  1633. ```json
  1634. data: {
  1635. "code": 0,
  1636. "data": {
  1637. "answer": "您好!有什么具体的问题或者需要的帮助",
  1638. "reference": {},
  1639. "audio_binary": null,
  1640. "id": "31153052-7bac-4741-a513-ed07d853f29e"
  1641. }
  1642. }
  1643. data: {
  1644. "code": 0,
  1645. "data": {
  1646. "answer": "您好!有什么具体的问题或者需要的帮助可以告诉我吗?我在这里是为了帮助",
  1647. "reference": {},
  1648. "audio_binary": null,
  1649. "id": "31153052-7bac-4741-a513-ed07d853f29e"
  1650. }
  1651. }
  1652. data: {
  1653. "code": 0,
  1654. "data": {
  1655. "answer": "您好!有什么具体的问题或者需要的帮助可以告诉我吗?我在这里是为了帮助您的。如果您有任何疑问或是需要获取",
  1656. "reference": {},
  1657. "audio_binary": null,
  1658. "id": "31153052-7bac-4741-a513-ed07d853f29e"
  1659. }
  1660. }
  1661. data: {
  1662. "code": 0,
  1663. "data": {
  1664. "answer": "您好!有什么具体的问题或者需要的帮助可以告诉我吗?我在这里是为了帮助您的。如果您有任何疑问或是需要获取某些信息,请随时提出。",
  1665. "reference": {},
  1666. "audio_binary": null,
  1667. "id": "31153052-7bac-4741-a513-ed07d853f29e"
  1668. }
  1669. }
  1670. data: {
  1671. "code": 0,
  1672. "data": {
  1673. "answer": "您好!有什么具体的问题或者需要的帮助可以告诉我吗 ##0$$?我在这里是为了帮助您的。如果您有任何疑问或是需要获取某些信息,请随时提出。",
  1674. "reference": {
  1675. "total": 19,
  1676. "chunks": [
  1677. {
  1678. "chunk_id": "9d87f9d70a0d8a7565694a81fd4c5d5f",
  1679. "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整体流程还是比较类似的。 ",
  1680. "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 整体流程还是比较类似的。",
  1681. "doc_id": "5c5999ec7be811ef9cab0242ac120005",
  1682. "docnm_kwd": "1.txt",
  1683. "kb_id": "c7ee74067a2c11efb21c0242ac120006",
  1684. "important_kwd": [],
  1685. "img_id": "",
  1686. "similarity": 0.38337178633282265,
  1687. "vector_similarity": 0.3321336754679629,
  1688. "term_similarity": 0.4053309767034769,
  1689. "positions": [
  1690. ""
  1691. ]
  1692. },
  1693. {
  1694. "chunk_id": "895d34de762e674b43e8613c6fb54c6d",
  1695. "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你是一个智能助手,请总结知识库的内容来回答问题,请列举知识库中的数据详细回答。 ",
  1696. "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你是一个智能助手,请总结知识库的内容来回答问题,请列举知识库中的数据详细回答。",
  1697. "doc_id": "5c5999ec7be811ef9cab0242ac120005",
  1698. "docnm_kwd": "1.txt",
  1699. "kb_id": "c7ee74067a2c11efb21c0242ac120006",
  1700. "important_kwd": [],
  1701. "img_id": "",
  1702. "similarity": 0.2788204323926715,
  1703. "vector_similarity": 0.35489427679953667,
  1704. "term_similarity": 0.2462173562183008,
  1705. "positions": [
  1706. ""
  1707. ]
  1708. }
  1709. ],
  1710. "doc_aggs": [
  1711. {
  1712. "doc_name": "1.txt",
  1713. "doc_id": "5c5999ec7be811ef9cab0242ac120005",
  1714. "count": 2
  1715. }
  1716. ]
  1717. },
  1718. "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",
  1719. "id": "31153052-7bac-4741-a513-ed07d853f29e"
  1720. }
  1721. }
  1722. data:{
  1723. "code": 0,
  1724. "data": true
  1725. }
  1726. ```
  1727. An error response includes a JSON object like the following:
  1728. ```json
  1729. {
  1730. "code": 102,
  1731. "message": "Please input your question."
  1732. }
  1733. ```