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

http_api_reference.md 58KB

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