template.en.mdx 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. import { CodeGroup } from '@/app/components/develop/code.tsx'
  2. import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from '@/app/components/develop/md.tsx'
  3. # Knowledge API
  4. <div>
  5. ### Authentication
  6. Service API of Dify authenticates using an `API-Key`.
  7. It is suggested that developers store the `API-Key` in the backend instead of sharing or storing it in the client side to avoid the leakage of the `API-Key`, which may lead to property loss.
  8. All API requests should include your `API-Key` in the **`Authorization`** HTTP Header, as shown below:
  9. <CodeGroup title="Code">
  10. ```javascript
  11. Authorization: Bearer {API_KEY}
  12. ```
  13. </CodeGroup>
  14. </div>
  15. ---
  16. <Heading
  17. url='/datasets/{dataset_id}/document/create_by_text'
  18. method='POST'
  19. title='Create a document from text'
  20. name='#create_by_text'
  21. />
  22. <Row>
  23. <Col>
  24. This api is based on an existing Knowledge and creates a new document through text based on this Knowledge.
  25. ### Params
  26. <Properties>
  27. <Property name='dataset_id' type='string' key='dataset_id'>
  28. Knowledge ID
  29. </Property>
  30. </Properties>
  31. ### Request Body
  32. <Properties>
  33. <Property name='name' type='string' key='name'>
  34. Document name
  35. </Property>
  36. <Property name='text' type='string' key='text'>
  37. Document content
  38. </Property>
  39. <Property name='indexing_technique' type='string' key='indexing_technique'>
  40. Index mode
  41. - <code>high_quality</code> High quality: embedding using embedding model, built as vector database index
  42. - <code>economy</code> Economy: Build using inverted index of Keyword Table Index
  43. </Property>
  44. <Property name='process_rule' type='object' key='process_rule'>
  45. Processing rules
  46. - <code>mode</code> (string) Cleaning, segmentation mode, automatic / custom
  47. - <code>rules</code> (object) Custom rules (in automatic mode, this field is empty)
  48. - <code>pre_processing_rules</code> (array[object]) Preprocessing rules
  49. - <code>id</code> (string) Unique identifier for the preprocessing rule
  50. - enumerate
  51. - <code>remove_extra_spaces</code> Replace consecutive spaces, newlines, tabs
  52. - <code>remove_urls_emails</code> Delete URL, email address
  53. - <code>enabled</code> (bool) Whether to select this rule or not. If no document ID is passed in, it represents the default value.
  54. - <code>segmentation</code> (object) segmentation rules
  55. - <code>separator</code> Custom segment identifier, currently only allows one delimiter to be set. Default is \n
  56. - <code>max_tokens</code> Maximum length (token) defaults to 1000
  57. </Property>
  58. </Properties>
  59. </Col>
  60. <Col sticky>
  61. <CodeGroup
  62. title="Request"
  63. tag="POST"
  64. label="/datasets/{dataset_id}/document/create_by_text"
  65. targetCode={`curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/document/create_by_text' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{"name": "text","text": "text","indexing_technique": "high_quality","process_rule": {"mode": "automatic"}}'`}
  66. >
  67. ```bash {{ title: 'cURL' }}
  68. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/document/create_by_text' \
  69. --header 'Authorization: Bearer {api_key}' \
  70. --header 'Content-Type: application/json' \
  71. --data-raw '{
  72. "name": "text",
  73. "text": "text",
  74. "indexing_technique": "high_quality",
  75. "process_rule": {
  76. "mode": "automatic"
  77. }
  78. }'
  79. ```
  80. </CodeGroup>
  81. <CodeGroup title="Response">
  82. ```json {{ title: 'Response' }}
  83. {
  84. "document": {
  85. "id": "",
  86. "position": 1,
  87. "data_source_type": "upload_file",
  88. "data_source_info": {
  89. "upload_file_id": ""
  90. },
  91. "dataset_process_rule_id": "",
  92. "name": "text.txt",
  93. "created_from": "api",
  94. "created_by": "",
  95. "created_at": 1695690280,
  96. "tokens": 0,
  97. "indexing_status": "waiting",
  98. "error": null,
  99. "enabled": true,
  100. "disabled_at": null,
  101. "disabled_by": null,
  102. "archived": false,
  103. "display_status": "queuing",
  104. "word_count": 0,
  105. "hit_count": 0,
  106. "doc_form": "text_model"
  107. },
  108. "batch": ""
  109. }
  110. ```
  111. </CodeGroup>
  112. </Col>
  113. </Row>
  114. ---
  115. <Heading
  116. url='/datasets/{dataset_id}/document/create_by_file'
  117. method='POST'
  118. title='Create documents from files'
  119. name='#create_by_file'
  120. />
  121. <Row>
  122. <Col>
  123. This api is based on an existing Knowledge and creates a new document through a file based on this Knowledge.
  124. ### Params
  125. <Properties>
  126. <Property name='dataset_id' type='string' key='dataset_id'>
  127. Knowledge ID
  128. </Property>
  129. </Properties>
  130. ### Request Body
  131. <Properties>
  132. <Property name='data' type='multipart/form-data json string' key='data'>
  133. - original_document_id Source document ID (optional)
  134. - Used to re-upload the document or modify the document cleaning and segmentation configuration. The missing information is copied from the source document
  135. - The source document cannot be an archived document
  136. - When original_document_id is passed in, the update operation is performed on behalf of the document. process_rule is a fillable item. If not filled in, the segmentation method of the source document will be used by defaul
  137. - When original_document_id is not passed in, the new operation is performed on behalf of the document, and process_rule is required
  138. - indexing_technique Index mode
  139. - <code>high_quality</code> High quality: embedding using embedding model, built as vector database index
  140. - <code>economy</code> Economy: Build using inverted index of Keyword Table Index
  141. - process_rule Processing rules
  142. - <code>mode</code> (string) Cleaning, segmentation mode, automatic / custom
  143. - <code>rules</code> (object) Custom rules (in automatic mode, this field is empty)
  144. - <code>pre_processing_rules</code> (array[object]) Preprocessing rules
  145. - <code>id</code> (string) Unique identifier for the preprocessing rule
  146. - enumerate
  147. - <code>remove_extra_spaces</code> Replace consecutive spaces, newlines, tabs
  148. - <code>remove_urls_emails</code> Delete URL, email address
  149. - <code>enabled</code> (bool) Whether to select this rule or not. If no document ID is passed in, it represents the default value.
  150. - <code>segmentation</code> (object) segmentation rules
  151. - <code>separator</code> Custom segment identifier, currently only allows one delimiter to be set. Default is \n
  152. - <code>max_tokens</code> Maximum length (token) defaults to 1000
  153. </Property>
  154. <Property name='file' type='multipart/form-data' key='file'>
  155. Files that need to be uploaded.
  156. </Property>
  157. </Properties>
  158. </Col>
  159. <Col sticky>
  160. <CodeGroup
  161. title="Request"
  162. tag="POST"
  163. label="/datasets/{dataset_id}/document/create_by_file"
  164. targetCode={`curl --location POST '${props.apiBaseUrl}/datasets/{dataset_id}/document/create_by_file' \\\n--header 'Authorization: Bearer {api_key}' \\\n--form 'data="{"indexing_technique":"high_quality","process_rule":{"rules":{"pre_processing_rules":[{"id":"remove_extra_spaces","enabled":true},{"id":"remove_urls_emails","enabled":true}],"segmentation":{"separator":"###","max_tokens":500}},"mode":"custom"}}";type=text/plain' \\\n--form 'file=@"/path/to/file"'`}
  165. >
  166. ```bash {{ title: 'cURL' }}
  167. curl --location POST '${props.apiBaseUrl}/datasets/{dataset_id}/document/create_by_file' \
  168. --header 'Authorization: Bearer {api_key}' \
  169. --form 'data="{\"name\":\"Dify\",\"indexing_technique\":\"high_quality\",\"process_rule\":{\"rules\":{\"pre_processing_rules\":[{\"id\":\"remove_extra_spaces\",\"enabled\":true},{\"id\":\"remove_urls_emails\",\"enabled\":true}],\"segmentation\":{\"separator\":\"###\",\"max_tokens\":500}},\"mode\":\"custom\"}}";type=text/plain' \
  170. --form 'file=@"/path/to/file"'
  171. ```
  172. </CodeGroup>
  173. <CodeGroup title="Response">
  174. ```json {{ title: 'Response' }}
  175. {
  176. "document": {
  177. "id": "",
  178. "position": 1,
  179. "data_source_type": "upload_file",
  180. "data_source_info": {
  181. "upload_file_id": ""
  182. },
  183. "dataset_process_rule_id": "",
  184. "name": "Dify.txt",
  185. "created_from": "api",
  186. "created_by": "",
  187. "created_at": 1695308667,
  188. "tokens": 0,
  189. "indexing_status": "waiting",
  190. "error": null,
  191. "enabled": true,
  192. "disabled_at": null,
  193. "disabled_by": null,
  194. "archived": false,
  195. "display_status": "queuing",
  196. "word_count": 0,
  197. "hit_count": 0,
  198. "doc_form": "text_model"
  199. },
  200. "batch": ""
  201. }
  202. ```
  203. </CodeGroup>
  204. </Col>
  205. </Row>
  206. ---
  207. <Heading
  208. url='/datasets'
  209. method='POST'
  210. title='Create an empty Knowledge'
  211. name='#create_empty_dataset'
  212. />
  213. <Row>
  214. <Col>
  215. ### Request Body
  216. <Properties>
  217. <Property name='name' type='string' key='name'>
  218. Knowledge name
  219. </Property>
  220. </Properties>
  221. </Col>
  222. <Col sticky>
  223. <CodeGroup
  224. title="Request"
  225. tag="POST"
  226. label="/datasets"
  227. targetCode={`curl --location --request POST '${props.apiBaseUrl}/datasets' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{"name": "name"}'`}
  228. >
  229. ```bash {{ title: 'cURL' }}
  230. curl --location --request POST '${apiBaseUrl}/v1/datasets' \
  231. --header 'Authorization: Bearer {api_key}' \
  232. --header 'Content-Type: application/json' \
  233. --data-raw '{
  234. "name": "name"
  235. }'
  236. ```
  237. </CodeGroup>
  238. <CodeGroup title="Response">
  239. ```json {{ title: 'Response' }}
  240. {
  241. "id": "",
  242. "name": "name",
  243. "description": null,
  244. "provider": "vendor",
  245. "permission": "only_me",
  246. "data_source_type": null,
  247. "indexing_technique": null,
  248. "app_count": 0,
  249. "document_count": 0,
  250. "word_count": 0,
  251. "created_by": "",
  252. "created_at": 1695636173,
  253. "updated_by": "",
  254. "updated_at": 1695636173,
  255. "embedding_model": null,
  256. "embedding_model_provider": null,
  257. "embedding_available": null
  258. }
  259. ```
  260. </CodeGroup>
  261. </Col>
  262. </Row>
  263. ---
  264. <Heading
  265. url='/datasets'
  266. method='GET'
  267. title='Knowledge list'
  268. name='#dataset_list'
  269. />
  270. <Row>
  271. <Col>
  272. ### Query
  273. <Properties>
  274. <Property name='page' type='string' key='page'>
  275. Page number
  276. </Property>
  277. <Property name='limit' type='string' key='limit'>
  278. Number of items returned, default 20, range 1-100
  279. </Property>
  280. </Properties>
  281. </Col>
  282. <Col sticky>
  283. <CodeGroup
  284. title="Request"
  285. tag="POST"
  286. label="/datasets"
  287. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets?page=1&limit=20' \\\n--header 'Authorization: Bearer {api_key}'`}
  288. >
  289. ```bash {{ title: 'cURL' }}
  290. curl --location --request GET '${props.apiBaseUrl}/datasets?page=1&limit=20' \
  291. --header 'Authorization: Bearer {api_key}'
  292. ```
  293. </CodeGroup>
  294. <CodeGroup title="Response">
  295. ```json {{ title: 'Response' }}
  296. {
  297. "data": [
  298. {
  299. "id": "",
  300. "name": "name",
  301. "description": "desc",
  302. "permission": "only_me",
  303. "data_source_type": "upload_file",
  304. "indexing_technique": "",
  305. "app_count": 2,
  306. "document_count": 10,
  307. "word_count": 1200,
  308. "created_by": "",
  309. "created_at": "",
  310. "updated_by": "",
  311. "updated_at": ""
  312. },
  313. ...
  314. ],
  315. "has_more": true,
  316. "limit": 20,
  317. "total": 50,
  318. "page": 1
  319. }
  320. ```
  321. </CodeGroup>
  322. </Col>
  323. </Row>
  324. ---
  325. <Heading
  326. url='/datasets/{dataset_id}/documents/{document_id}/update_by_text'
  327. method='POST'
  328. title='Update document via text'
  329. name='#update_by_text'
  330. />
  331. <Row>
  332. <Col>
  333. This api is based on an existing Knowledge and updates the document through text based on this Knowledge.
  334. ### Params
  335. <Properties>
  336. <Property name='dataset_id' type='string' key='dataset_id'>
  337. Knowledge ID
  338. </Property>
  339. <Property name='document_id' type='string' key='document_id'>
  340. Document ID
  341. </Property>
  342. </Properties>
  343. ### Request Body
  344. <Properties>
  345. <Property name='name' type='string' key='name'>
  346. Document name (optional)
  347. </Property>
  348. <Property name='text' type='string' key='text'>
  349. Document content (optional)
  350. </Property>
  351. <Property name='process_rule' type='object' key='process_rule'>
  352. Processing rules
  353. - <code>mode</code> (string) Cleaning, segmentation mode, automatic / custom
  354. - <code>rules</code> (object) Custom rules (in automatic mode, this field is empty)
  355. - <code>pre_processing_rules</code> (array[object]) Preprocessing rules
  356. - <code>id</code> (string) Unique identifier for the preprocessing rule
  357. - enumerate
  358. - <code>remove_extra_spaces</code> Replace consecutive spaces, newlines, tabs
  359. - <code>remove_urls_emails</code> Delete URL, email address
  360. - <code>enabled</code> (bool) Whether to select this rule or not. If no document ID is passed in, it represents the default value.
  361. - <code>segmentation</code> (object) segmentation rules
  362. - <code>separator</code> Custom segment identifier, currently only allows one delimiter to be set. Default is \n
  363. - <code>max_tokens</code> Maximum length (token) defaults to 1000
  364. </Property>
  365. </Properties>
  366. </Col>
  367. <Col sticky>
  368. <CodeGroup
  369. title="Request"
  370. tag="POST"
  371. label="/datasets/{dataset_id}/documents/{document_id}/update_by_text"
  372. targetCode={`curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/update_by_text' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{"name": "name","text": "text"}'`}
  373. >
  374. ```bash {{ title: 'cURL' }}
  375. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/update_by_text' \
  376. --header 'Authorization: Bearer {api_key}' \
  377. --header 'Content-Type: application/json' \
  378. --data-raw '{
  379. "name": "name",
  380. "text": "text"
  381. }'
  382. ```
  383. </CodeGroup>
  384. <CodeGroup title="Response">
  385. ```json {{ title: 'Response' }}
  386. {
  387. "document": {
  388. "id": "",
  389. "position": 1,
  390. "data_source_type": "upload_file",
  391. "data_source_info": {
  392. "upload_file_id": ""
  393. },
  394. "dataset_process_rule_id": "",
  395. "name": "name.txt",
  396. "created_from": "api",
  397. "created_by": "",
  398. "created_at": 1695308667,
  399. "tokens": 0,
  400. "indexing_status": "waiting",
  401. "error": null,
  402. "enabled": true,
  403. "disabled_at": null,
  404. "disabled_by": null,
  405. "archived": false,
  406. "display_status": "queuing",
  407. "word_count": 0,
  408. "hit_count": 0,
  409. "doc_form": "text_model"
  410. },
  411. "batch": ""
  412. }
  413. ```
  414. </CodeGroup>
  415. </Col>
  416. </Row>
  417. ---
  418. <Heading
  419. url='/datasets/{dataset_id}/documents/{document_id}/update_by_file'
  420. method='POST'
  421. title='Update a document from a file'
  422. name='#update_by_file'
  423. />
  424. <Row>
  425. <Col>
  426. This api is based on an existing Knowledge, and updates documents through files based on this Knowledge
  427. ### Params
  428. <Properties>
  429. <Property name='dataset_id' type='string' key='dataset_id'>
  430. Knowledge ID
  431. </Property>
  432. <Property name='document_id' type='string' key='document_id'>
  433. Document ID
  434. </Property>
  435. </Properties>
  436. ### Request Body
  437. <Properties>
  438. <Property name='name' type='string' key='name'>
  439. Document name (optional)
  440. </Property>
  441. <Property name='file' type='multipart/form-data' key='file'>
  442. Files to be uploaded
  443. </Property>
  444. <Property name='process_rule' type='object' key='process_rule'>
  445. Processing rules
  446. - <code>mode</code> (string) Cleaning, segmentation mode, automatic / custom
  447. - <code>rules</code> (object) Custom rules (in automatic mode, this field is empty)
  448. - <code>pre_processing_rules</code> (array[object]) Preprocessing rules
  449. - <code>id</code> (string) Unique identifier for the preprocessing rule
  450. - enumerate
  451. - <code>remove_extra_spaces</code> Replace consecutive spaces, newlines, tabs
  452. - <code>remove_urls_emails</code> Delete URL, email address
  453. - <code>enabled</code> (bool) Whether to select this rule or not. If no document ID is passed in, it represents the default value.
  454. - <code>segmentation</code> (object) segmentation rules
  455. - <code>separator</code> Custom segment identifier, currently only allows one delimiter to be set. Default is \n
  456. - <code>max_tokens</code> Maximum length (token) defaults to 1000
  457. </Property>
  458. </Properties>
  459. </Col>
  460. <Col sticky>
  461. <CodeGroup
  462. title="Request"
  463. tag="POST"
  464. label="/datasets/{dataset_id}/documents/{document_id}/update_by_file"
  465. targetCode={`curl --location POST '${props.apiBaseUrl}/datasets/{dataset_id}/document/{document_id}/create_by_file' \\\n--header 'Authorization: Bearer {api_key}' \\\n--form 'data="{"name":"Dify","indexing_technique":"high_quality","process_rule":{"rules":{"pre_processing_rules":[{"id":"remove_extra_spaces","enabled":true},{"id":"remove_urls_emails","enabled":true}],"segmentation":{"separator":"###","max_tokens":500}},"mode":"custom"}}";type=text/plain' \\\n--form 'file=@"/path/to/file"'`}
  466. >
  467. ```bash {{ title: 'cURL' }}
  468. curl --location POST '${props.apiBaseUrl}/datasets/{dataset_id}/document/{document_id}/create_by_file' \
  469. --header 'Authorization: Bearer {api_key}' \
  470. --form 'data="{\"name\":\"Dify\",\"indexing_technique\":\"high_quality\",\"process_rule\":{\"rules\":{\"pre_processing_rules\":[{\"id\":\"remove_extra_spaces\",\"enabled\":true},{\"id\":\"remove_urls_emails\",\"enabled\":true}],\"segmentation\":{\"separator\":\"###\",\"max_tokens\":500}},\"mode\":\"custom\"}}";type=text/plain' \
  471. --form 'file=@"/path/to/file"'
  472. ```
  473. </CodeGroup>
  474. <CodeGroup title="Response">
  475. ```json {{ title: 'Response' }}
  476. {
  477. "document": {
  478. "id": "",
  479. "position": 1,
  480. "data_source_type": "upload_file",
  481. "data_source_info": {
  482. "upload_file_id": ""
  483. },
  484. "dataset_process_rule_id": "",
  485. "name": "Dify.txt",
  486. "created_from": "api",
  487. "created_by": "",
  488. "created_at": 1695308667,
  489. "tokens": 0,
  490. "indexing_status": "waiting",
  491. "error": null,
  492. "enabled": true,
  493. "disabled_at": null,
  494. "disabled_by": null,
  495. "archived": false,
  496. "display_status": "queuing",
  497. "word_count": 0,
  498. "hit_count": 0,
  499. "doc_form": "text_model"
  500. },
  501. "batch": "20230921150427533684"
  502. }
  503. ```
  504. </CodeGroup>
  505. </Col>
  506. </Row>
  507. ---
  508. <Heading
  509. url='/datasets/{dataset_id}/documents/{batch}/indexing-status'
  510. method='GET'
  511. title='Get document embedding status (progress)'
  512. name='#indexing_status'
  513. />
  514. <Row>
  515. <Col>
  516. ### Params
  517. <Properties>
  518. <Property name='dataset_id' type='string' key='dataset_id'>
  519. Knowledge ID
  520. </Property>
  521. <Property name='batch' type='string' key='batch'>
  522. Batch number of uploaded documents
  523. </Property>
  524. </Properties>
  525. </Col>
  526. <Col sticky>
  527. <CodeGroup
  528. title="Request"
  529. tag="GET"
  530. label="/datasets/{dataset_id}/documents/{batch}/indexing-status"
  531. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{batch}/indexing-status' \\\n--header 'Authorization: Bearer {api_key}'`}
  532. >
  533. ```bash {{ title: 'cURL' }}
  534. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{batch}/indexing-status' \
  535. --header 'Authorization: Bearer {api_key}' \
  536. ```
  537. </CodeGroup>
  538. <CodeGroup title="Response">
  539. ```json {{ title: 'Response' }}
  540. {
  541. "data":[{
  542. "id": "",
  543. "indexing_status": "indexing",
  544. "processing_started_at": 1681623462.0,
  545. "parsing_completed_at": 1681623462.0,
  546. "cleaning_completed_at": 1681623462.0,
  547. "splitting_completed_at": 1681623462.0,
  548. "completed_at": null,
  549. "paused_at": null,
  550. "error": null,
  551. "stopped_at": null,
  552. "completed_segments": 24,
  553. "total_segments": 100
  554. }]
  555. }
  556. ```
  557. </CodeGroup>
  558. </Col>
  559. </Row>
  560. ---
  561. <Heading
  562. url='/datasets/{dataset_id}/documents/{document_id}'
  563. method='DELETE'
  564. title='Delete document'
  565. name='#delete_document'
  566. />
  567. <Row>
  568. <Col>
  569. ### Params
  570. <Properties>
  571. <Property name='dataset_id' type='string' key='dataset_id'>
  572. Knowledge ID
  573. </Property>
  574. <Property name='document_id' type='string' key='document_id'>
  575. Document ID
  576. </Property>
  577. </Properties>
  578. </Col>
  579. <Col sticky>
  580. <CodeGroup
  581. title="Request"
  582. tag="DELETE"
  583. label="/datasets/{dataset_id}/documents/{document_id}"
  584. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  585. >
  586. ```bash {{ title: 'cURL' }}
  587. curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}' \
  588. --header 'Authorization: Bearer {api_key}' \
  589. ```
  590. </CodeGroup>
  591. <CodeGroup title="Response">
  592. ```json {{ title: 'Response' }}
  593. {
  594. "result": "success"
  595. }
  596. ```
  597. </CodeGroup>
  598. </Col>
  599. </Row>
  600. ---
  601. <Heading
  602. url='/datasets/{dataset_id}/documents'
  603. method='GET'
  604. title='Knowledge document list'
  605. name='#dataset_document_list'
  606. />
  607. <Row>
  608. <Col>
  609. ### Params
  610. <Properties>
  611. <Property name='dataset_id' type='string' key='dataset_id'>
  612. Knowledge ID
  613. </Property>
  614. </Properties>
  615. ### Query
  616. <Properties>
  617. <Property name='keyword' type='string' key='keyword'>
  618. Search keywords, currently only search document names(optional)
  619. </Property>
  620. <Property name='page' type='string' key='page'>
  621. Page number(optional)
  622. </Property>
  623. <Property name='limit' type='string' key='limit'>
  624. Number of items returned, default 20, range 1-100(optional)
  625. </Property>
  626. </Properties>
  627. </Col>
  628. <Col sticky>
  629. <CodeGroup
  630. title="Request"
  631. tag="GET"
  632. label="/datasets/{dataset_id}/documents"
  633. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents' \\\n--header 'Authorization: Bearer {api_key}'`}
  634. >
  635. ```bash {{ title: 'cURL' }}
  636. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents' \
  637. --header 'Authorization: Bearer {api_key}' \
  638. ```
  639. </CodeGroup>
  640. <CodeGroup title="Response">
  641. ```json {{ title: 'Response' }}
  642. {
  643. "data": [
  644. {
  645. "id": "",
  646. "position": 1,
  647. "data_source_type": "file_upload",
  648. "data_source_info": null,
  649. "dataset_process_rule_id": null,
  650. "name": "dify",
  651. "created_from": "",
  652. "created_by": "",
  653. "created_at": 1681623639,
  654. "tokens": 0,
  655. "indexing_status": "waiting",
  656. "error": null,
  657. "enabled": true,
  658. "disabled_at": null,
  659. "disabled_by": null,
  660. "archived": false
  661. },
  662. ],
  663. "has_more": false,
  664. "limit": 20,
  665. "total": 9,
  666. "page": 1
  667. }
  668. ```
  669. </CodeGroup>
  670. </Col>
  671. </Row>
  672. ---
  673. <Heading
  674. url='/datasets/{dataset_id}/documents/{document_id}/segments'
  675. method='POST'
  676. title='Add segment'
  677. name='#create_new_segment'
  678. />
  679. <Row>
  680. <Col>
  681. ### Params
  682. <Properties>
  683. <Property name='dataset_id' type='string' key='dataset_id'>
  684. Knowledge ID
  685. </Property>
  686. <Property name='document_id' type='string' key='document_id'>
  687. Document ID
  688. </Property>
  689. </Properties>
  690. ### Request Body
  691. <Properties>
  692. <Property name='segments' type='object list' key='segments'>
  693. - <code>content</code> (text) Text content/question content, required
  694. - <code>answer</code> (text) Answer content, if the mode of the Knowledge is qa mode, pass the value(optional)
  695. - <code>keywords</code> (list) Keywords(optional)
  696. </Property>
  697. </Properties>
  698. </Col>
  699. <Col sticky>
  700. <CodeGroup
  701. title="Request"
  702. tag="POST"
  703. label="/datasets/{dataset_id}/documents/{document_id}/segments"
  704. targetCode={`curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{"segments": [{"content": "1","answer": "1","keywords": ["a"]}]}'`}
  705. >
  706. ```bash {{ title: 'cURL' }}
  707. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments' \
  708. --header 'Authorization: Bearer {api_key}' \
  709. --header 'Content-Type: application/json' \
  710. --data-raw '{
  711. "segments": [
  712. {
  713. "content": "1",
  714. "answer": "1",
  715. "keywords": ["a"]
  716. }
  717. ]
  718. }'
  719. ```
  720. </CodeGroup>
  721. <CodeGroup title="Response">
  722. ```json {{ title: 'Response' }}
  723. {
  724. "data": [{
  725. "id": "",
  726. "position": 1,
  727. "document_id": "",
  728. "content": "1",
  729. "answer": "1",
  730. "word_count": 25,
  731. "tokens": 0,
  732. "keywords": [
  733. "a"
  734. ],
  735. "index_node_id": "",
  736. "index_node_hash": "",
  737. "hit_count": 0,
  738. "enabled": true,
  739. "disabled_at": null,
  740. "disabled_by": null,
  741. "status": "completed",
  742. "created_by": "",
  743. "created_at": 1695312007,
  744. "indexing_at": 1695312007,
  745. "completed_at": 1695312007,
  746. "error": null,
  747. "stopped_at": null
  748. }],
  749. "doc_form": "text_model"
  750. }
  751. ```
  752. </CodeGroup>
  753. </Col>
  754. </Row>
  755. ---
  756. <Heading
  757. url='/datasets/{dataset_id}/documents/{document_id}/segments'
  758. method='GET'
  759. title='get documents segments'
  760. name='#get_segment'
  761. />
  762. <Row>
  763. <Col>
  764. ### Path
  765. <Properties>
  766. <Property name='dataset_id' type='string' key='dataset_id'>
  767. Knowledge ID
  768. </Property>
  769. <Property name='document_id' type='string' key='document_id'>
  770. Document ID
  771. </Property>
  772. </Properties>
  773. ### Query
  774. <Properties>
  775. <Property name='keyword' type='string' key='keyword'>
  776. keyword,choosable
  777. </Property>
  778. <Property name='status' type='string' key='status'>
  779. Search status,completed
  780. </Property>
  781. </Properties>
  782. </Col>
  783. <Col sticky>
  784. <CodeGroup
  785. title="Request"
  786. tag="GET"
  787. label="/datasets/{dataset_id}/documents/{document_id}/segments"
  788. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json'`}
  789. >
  790. ```bash {{ title: 'cURL' }}
  791. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments' \
  792. --header 'Authorization: Bearer {api_key}' \
  793. --header 'Content-Type: application/json'
  794. ```
  795. </CodeGroup>
  796. <CodeGroup title="Response">
  797. ```json {{ title: 'Response' }}
  798. {
  799. "data": [{
  800. "id": "",
  801. "position": 1,
  802. "document_id": "",
  803. "content": "1",
  804. "answer": "1",
  805. "word_count": 25,
  806. "tokens": 0,
  807. "keywords": [
  808. "a"
  809. ],
  810. "index_node_id": "",
  811. "index_node_hash": "",
  812. "hit_count": 0,
  813. "enabled": true,
  814. "disabled_at": null,
  815. "disabled_by": null,
  816. "status": "completed",
  817. "created_by": "",
  818. "created_at": 1695312007,
  819. "indexing_at": 1695312007,
  820. "completed_at": 1695312007,
  821. "error": null,
  822. "stopped_at": null
  823. }],
  824. "doc_form": "text_model"
  825. }
  826. ```
  827. </CodeGroup>
  828. </Col>
  829. </Row>
  830. ---
  831. <Heading
  832. url='/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}'
  833. method='DELETE'
  834. title='delete document segment'
  835. name='#delete_segment'
  836. />
  837. <Row>
  838. <Col>
  839. ### Path
  840. <Properties>
  841. <Property name='dataset_id' type='string' key='dataset_id'>
  842. Knowledge ID
  843. </Property>
  844. <Property name='segment_id' type='string' key='segment_id'>
  845. Document Segment ID
  846. </Property>
  847. </Properties>
  848. </Col>
  849. <Col sticky>
  850. <CodeGroup
  851. title="Request"
  852. tag="DELETE"
  853. label="/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}"
  854. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/segments/{segment_id}' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json'`}
  855. >
  856. ```bash {{ title: 'cURL' }}
  857. curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/segments/{segment_id}' \
  858. --header 'Authorization: Bearer {api_key}' \
  859. --header 'Content-Type: application/json'
  860. ```
  861. </CodeGroup>
  862. <CodeGroup title="Response">
  863. ```json {{ title: 'Response' }}
  864. {
  865. "result": "success"
  866. }
  867. ```
  868. </CodeGroup>
  869. </Col>
  870. </Row>
  871. ---
  872. <Heading
  873. url='/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}'
  874. method='POST'
  875. title='update document segment'
  876. name='#update_segment'
  877. />
  878. <Row>
  879. <Col>
  880. ### POST
  881. <Properties>
  882. <Property name='dataset_id' type='string' key='dataset_id'>
  883. Knowledge ID
  884. </Property>
  885. <Property name='segment_id' type='string' key='segment_id'>
  886. Document Segment ID
  887. </Property>
  888. </Properties>
  889. ### Request Body
  890. <Properties>
  891. <Property name='segments' type='object list' key='segments'>
  892. - <code>content</code> (text) text content/question content,required
  893. - <code>answer</code> (text) Answer content, not required, passed if the Knowledge is in qa mode
  894. - <code>keywords</code> (list) keyword, not required
  895. - <code>enabled</code> (bool) false/true, not required
  896. </Property>
  897. </Properties>
  898. </Col>
  899. <Col sticky>
  900. <CodeGroup
  901. title="Request"
  902. tag="POST"
  903. label="/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}"
  904. targetCode={`curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json'\\\n--data-raw '{\"segments\": {\"content\": \"1\",\"answer\": \"1\", \"keywords\": [\"a\"], \"enabled\": false}}'`}
  905. >
  906. ```bash {{ title: 'cURL' }}
  907. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}' \
  908. --header 'Content-Type: application/json' \
  909. --data-raw '{
  910. "segments": {
  911. "content": "1",
  912. "answer": "1",
  913. "keywords": ["a"],
  914. "enabled": false
  915. }
  916. }'
  917. ```
  918. </CodeGroup>
  919. <CodeGroup title="Response">
  920. ```json {{ title: 'Response' }}
  921. {
  922. "data": [{
  923. "id": "",
  924. "position": 1,
  925. "document_id": "",
  926. "content": "1",
  927. "answer": "1",
  928. "word_count": 25,
  929. "tokens": 0,
  930. "keywords": [
  931. "a"
  932. ],
  933. "index_node_id": "",
  934. "index_node_hash": "",
  935. "hit_count": 0,
  936. "enabled": true,
  937. "disabled_at": null,
  938. "disabled_by": null,
  939. "status": "completed",
  940. "created_by": "",
  941. "created_at": 1695312007,
  942. "indexing_at": 1695312007,
  943. "completed_at": 1695312007,
  944. "error": null,
  945. "stopped_at": null
  946. }],
  947. "doc_form": "text_model"
  948. }
  949. ```
  950. </CodeGroup>
  951. </Col>
  952. </Row>
  953. ---
  954. <Row>
  955. <Col>
  956. ### Error message
  957. <Properties>
  958. <Property name='code' type='string' key='code'>
  959. Error code
  960. </Property>
  961. </Properties>
  962. <Properties>
  963. <Property name='status' type='number' key='status'>
  964. Error status
  965. </Property>
  966. </Properties>
  967. <Properties>
  968. <Property name='message' type='string' key='message'>
  969. Error message
  970. </Property>
  971. </Properties>
  972. </Col>
  973. <Col>
  974. <CodeGroup title="Example">
  975. ```json {{ title: 'Response' }}
  976. {
  977. "code": "no_file_uploaded",
  978. "message": "Please upload your file.",
  979. "status": 400
  980. }
  981. ```
  982. </CodeGroup>
  983. </Col>
  984. </Row>
  985. <table className="max-w-auto border-collapse border border-slate-400" style={{ maxWidth: 'none', width: 'auto' }}>
  986. <thead style={{ background: '#f9fafc' }}>
  987. <tr>
  988. <th className="p-2 border border-slate-300">code</th>
  989. <th className="p-2 border border-slate-300">status</th>
  990. <th className="p-2 border border-slate-300">message</th>
  991. </tr>
  992. </thead>
  993. <tbody>
  994. <tr>
  995. <td className="p-2 border border-slate-300">no_file_uploaded</td>
  996. <td className="p-2 border border-slate-300">400</td>
  997. <td className="p-2 border border-slate-300">Please upload your file.</td>
  998. </tr>
  999. <tr>
  1000. <td className="p-2 border border-slate-300">too_many_files</td>
  1001. <td className="p-2 border border-slate-300">400</td>
  1002. <td className="p-2 border border-slate-300">Only one file is allowed.</td>
  1003. </tr>
  1004. <tr>
  1005. <td className="p-2 border border-slate-300">file_too_large</td>
  1006. <td className="p-2 border border-slate-300">413</td>
  1007. <td className="p-2 border border-slate-300">File size exceeded.</td>
  1008. </tr>
  1009. <tr>
  1010. <td className="p-2 border border-slate-300">unsupported_file_type</td>
  1011. <td className="p-2 border border-slate-300">415</td>
  1012. <td className="p-2 border border-slate-300">File type not allowed.</td>
  1013. </tr>
  1014. <tr>
  1015. <td className="p-2 border border-slate-300">high_quality_dataset_only</td>
  1016. <td className="p-2 border border-slate-300">400</td>
  1017. <td className="p-2 border border-slate-300">Current operation only supports 'high-quality' datasets.</td>
  1018. </tr>
  1019. <tr>
  1020. <td className="p-2 border border-slate-300">dataset_not_initialized</td>
  1021. <td className="p-2 border border-slate-300">400</td>
  1022. <td className="p-2 border border-slate-300">The dataset is still being initialized or indexing. Please wait a moment.</td>
  1023. </tr>
  1024. <tr>
  1025. <td className="p-2 border border-slate-300">archived_document_immutable</td>
  1026. <td className="p-2 border border-slate-300">403</td>
  1027. <td className="p-2 border border-slate-300">The archived document is not editable.</td>
  1028. </tr>
  1029. <tr>
  1030. <td className="p-2 border border-slate-300">dataset_name_duplicate</td>
  1031. <td className="p-2 border border-slate-300">409</td>
  1032. <td className="p-2 border border-slate-300">The dataset name already exists. Please modify your dataset name.</td>
  1033. </tr>
  1034. <tr>
  1035. <td className="p-2 border border-slate-300">invalid_action</td>
  1036. <td className="p-2 border border-slate-300">400</td>
  1037. <td className="p-2 border border-slate-300">Invalid action.</td>
  1038. </tr>
  1039. <tr>
  1040. <td className="p-2 border border-slate-300">document_already_finished</td>
  1041. <td className="p-2 border border-slate-300">400</td>
  1042. <td className="p-2 border border-slate-300">The document has been processed. Please refresh the page or go to the document details.</td>
  1043. </tr>
  1044. <tr>
  1045. <td className="p-2 border border-slate-300">document_indexing</td>
  1046. <td className="p-2 border border-slate-300">400</td>
  1047. <td className="p-2 border border-slate-300">The document is being processed and cannot be edited.</td>
  1048. </tr>
  1049. <tr>
  1050. <td className="p-2 border border-slate-300">invalid_metadata</td>
  1051. <td className="p-2 border border-slate-300">400</td>
  1052. <td className="p-2 border border-slate-300">The metadata content is incorrect. Please check and verify.</td>
  1053. </tr>
  1054. </tbody>
  1055. </table>
  1056. <div className="pb-4" />