Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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