template.en.mdx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  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. # Dataset API
  4. <br/>
  5. <br/>
  6. <Heading
  7. url='/datasets'
  8. method='POST'
  9. title='Create an empty dataset'
  10. name='#create_empty_dataset'
  11. />
  12. <Row>
  13. <Col>
  14. ### Request Body
  15. <Properties>
  16. <Property name='name' type='string' key='name'>
  17. Dataset name
  18. </Property>
  19. </Properties>
  20. </Col>
  21. <Col sticky>
  22. <CodeGroup
  23. title="Request"
  24. tag="POST"
  25. label="/datasets"
  26. 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"}'`}
  27. >
  28. ```bash {{ title: 'cURL' }}
  29. curl --location --request POST '${apiBaseUrl}/v1/datasets' \
  30. --header 'Authorization: Bearer {api_key}' \
  31. --header 'Content-Type: application/json' \
  32. --data-raw '{
  33. "name": "name"
  34. }'
  35. ```
  36. </CodeGroup>
  37. <CodeGroup title="Response">
  38. ```json {{ title: 'Response' }}
  39. {
  40. "id": "",
  41. "name": "name",
  42. "description": null,
  43. "provider": "vendor",
  44. "permission": "only_me",
  45. "data_source_type": null,
  46. "indexing_technique": null,
  47. "app_count": 0,
  48. "document_count": 0,
  49. "word_count": 0,
  50. "created_by": "",
  51. "created_at": 1695636173,
  52. "updated_by": "",
  53. "updated_at": 1695636173,
  54. "embedding_model": null,
  55. "embedding_model_provider": null,
  56. "embedding_available": null
  57. }
  58. ```
  59. </CodeGroup>
  60. </Col>
  61. </Row>
  62. ---
  63. <Heading
  64. url='/datasets'
  65. method='GET'
  66. title='Dataset list'
  67. name='#dataset_list'
  68. />
  69. <Row>
  70. <Col>
  71. ### Path Query
  72. <Properties>
  73. <Property name='page' type='string' key='page'>
  74. Page number
  75. </Property>
  76. <Property name='limit' type='string' key='limit'>
  77. Number of items returned, default 20, range 1-100
  78. </Property>
  79. </Properties>
  80. </Col>
  81. <Col sticky>
  82. <CodeGroup
  83. title="Request"
  84. tag="POST"
  85. label="/datasets"
  86. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets?page=1&limit=20' \\\n--header 'Authorization: Bearer {api_key}'`}
  87. >
  88. ```bash {{ title: 'cURL' }}
  89. curl --location --request GET 'https://api.dify.ai/v1/datasets?page=1&limit=20' \
  90. --header 'Authorization: Bearer {api_key}'
  91. ```
  92. </CodeGroup>
  93. <CodeGroup title="Response">
  94. ```json {{ title: 'Response' }}
  95. {
  96. "data": [
  97. {
  98. "id": "",
  99. "name": "name",
  100. "description": "desc",
  101. "permission": "only_me",
  102. "data_source_type": "upload_file",
  103. "indexing_technique": "",
  104. "app_count": 2,
  105. "document_count": 10,
  106. "word_count": 1200,
  107. "created_by": "",
  108. "created_at": "",
  109. "updated_by": "",
  110. "updated_at": ""
  111. },
  112. ...
  113. ],
  114. "has_more": true,
  115. "limit": 20,
  116. "total": 50,
  117. "page": 1
  118. }
  119. ```
  120. </CodeGroup>
  121. </Col>
  122. </Row>
  123. ---
  124. <Heading
  125. url='/datasets/{dataset_id}/document/create_by_text'
  126. method='POST'
  127. title='Create a document from text'
  128. name='#create_by_text'
  129. />
  130. <Row>
  131. <Col>
  132. This api is based on an existing dataset and creates a new document through text based on this dataset.
  133. ### Path Params
  134. <Properties>
  135. <Property name='dataset_id' type='string' key='dataset_id'>
  136. Dataset ID
  137. </Property>
  138. </Properties>
  139. ### Request Body
  140. <Properties>
  141. <Property name='name' type='string' key='name'>
  142. Document name
  143. </Property>
  144. <Property name='text' type='string' key='text'>
  145. Document content
  146. </Property>
  147. <Property name='indexing_technique' type='string' key='indexing_technique'>
  148. Index mode
  149. - high_quality High quality: embedding using embedding model, built as vector database index
  150. - economy Economy: Build using inverted index of Keyword Table Index
  151. </Property>
  152. <Property name='process_rule' type='object' key='process_rule'>
  153. Processing rules
  154. - mode (string) Cleaning, segmentation mode, automatic / custom
  155. - rules (text) Custom rules (in automatic mode, this field is empty)
  156. - pre_processing_rules (array[object]) Preprocessing rules
  157. - id (string) Unique identifier for the preprocessing rule
  158. - enumerate
  159. - remove_extra_spaces Replace consecutive spaces, newlines, tabs
  160. - remove_urls_emails Delete URL, email address
  161. - enabled (bool) Whether to select this rule or not. If no document ID is passed in, it represents the default value.
  162. - segmentation (object) segmentation rules
  163. - separator Custom segment identifier, currently only allows one delimiter to be set. Default is \n
  164. - max_tokens Maximum length (token) defaults to 1000
  165. </Property>
  166. </Properties>
  167. </Col>
  168. <Col sticky>
  169. <CodeGroup
  170. title="Request"
  171. tag="POST"
  172. label="/datasets/{dataset_id}/document/create_by_text"
  173. 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"}}'`}
  174. >
  175. ```bash {{ title: 'cURL' }}
  176. curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/document/create_by_text' \
  177. --header 'Authorization: Bearer {api_key}' \
  178. --header 'Content-Type: application/json' \
  179. --data-raw '{
  180. "name": "text",
  181. "text": "text",
  182. "indexing_technique": "high_quality",
  183. "process_rule": {
  184. "mode": "automatic"
  185. }
  186. }'
  187. ```
  188. </CodeGroup>
  189. <CodeGroup title="Response">
  190. ```json {{ title: 'Response' }}
  191. {
  192. "document": {
  193. "id": "",
  194. "position": 1,
  195. "data_source_type": "upload_file",
  196. "data_source_info": {
  197. "upload_file_id": ""
  198. },
  199. "dataset_process_rule_id": "",
  200. "name": "text.txt",
  201. "created_from": "api",
  202. "created_by": "",
  203. "created_at": 1695690280,
  204. "tokens": 0,
  205. "indexing_status": "waiting",
  206. "error": null,
  207. "enabled": true,
  208. "disabled_at": null,
  209. "disabled_by": null,
  210. "archived": false,
  211. "display_status": "queuing",
  212. "word_count": 0,
  213. "hit_count": 0,
  214. "doc_form": "text_model"
  215. },
  216. "batch": ""
  217. }
  218. ```
  219. </CodeGroup>
  220. </Col>
  221. </Row>
  222. ---
  223. <Heading
  224. url='/datasets/{dataset_id}/document/create_by_file'
  225. method='POST'
  226. title='Create documents from files'
  227. name='#create_by_file'
  228. />
  229. <Row>
  230. <Col>
  231. This api is based on an existing dataset and creates a new document through a file based on this dataset.
  232. ### Path Params
  233. <Properties>
  234. <Property name='dataset_id' type='string' key='dataset_id'>
  235. Dataset ID
  236. </Property>
  237. </Properties>
  238. ### Request Body
  239. <Properties>
  240. <Property name='original_document_id' type='string' key='original_document_id'>
  241. Source document ID (optional)
  242. - Used to re-upload the document or modify the document cleaning and segmentation configuration. The missing information is copied from the source document
  243. - The source document cannot be an archived document
  244. - 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
  245. - When original_document_id is not passed in, the new operation is performed on behalf of the document, and process_rule is required
  246. </Property>
  247. <Property name='file' type='multipart/form-data' key='file'>
  248. Files that need to be uploaded.
  249. </Property>
  250. <Property name='indexing_technique' type='string' key='indexing_technique'>
  251. Index mode
  252. - high_quality High quality: embedding using embedding model, built as vector database index
  253. - economy Economy: Build using inverted index of Keyword Table Index
  254. </Property>
  255. <Property name='process_rule' type='object' key='process_rule'>
  256. Processing rules
  257. - mode (string) Cleaning, segmentation mode, automatic / custom
  258. - rules (text) Custom rules (in automatic mode, this field is empty)
  259. - pre_processing_rules (array[object]) Preprocessing rules
  260. - id (string) Unique identifier for the preprocessing rule
  261. - enumerate
  262. - remove_extra_spaces Replace consecutive spaces, newlines, tabs
  263. - remove_urls_emails Delete URL, email address
  264. - enabled (bool) Whether to select this rule or not. If no document ID is passed in, it represents the default value.
  265. - segmentation (object) segmentation rules
  266. - separator Custom segment identifier, currently only allows one delimiter to be set. Default is \n
  267. - max_tokens Maximum length (token) defaults to 1000
  268. </Property>
  269. </Properties>
  270. </Col>
  271. <Col sticky>
  272. <CodeGroup
  273. title="Request"
  274. tag="POST"
  275. label="/datasets/{dataset_id}/document/create_by_file"
  276. targetCode={`curl --location POST '${props.apiBaseUrl}/datasets/{dataset_id}/document/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"'`}
  277. >
  278. ```bash {{ title: 'cURL' }}
  279. curl --location POST 'https://api.dify.ai/v1/datasets/{dataset_id}/document/create_by_file' \
  280. --header 'Authorization: Bearer {api_key}' \
  281. --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' \
  282. --form 'file=@"/path/to/file"'
  283. ```
  284. </CodeGroup>
  285. <CodeGroup title="Response">
  286. ```json {{ title: 'Response' }}
  287. {
  288. "document": {
  289. "id": "",
  290. "position": 1,
  291. "data_source_type": "upload_file",
  292. "data_source_info": {
  293. "upload_file_id": ""
  294. },
  295. "dataset_process_rule_id": "",
  296. "name": "Dify.txt",
  297. "created_from": "api",
  298. "created_by": "",
  299. "created_at": 1695308667,
  300. "tokens": 0,
  301. "indexing_status": "waiting",
  302. "error": null,
  303. "enabled": true,
  304. "disabled_at": null,
  305. "disabled_by": null,
  306. "archived": false,
  307. "display_status": "queuing",
  308. "word_count": 0,
  309. "hit_count": 0,
  310. "doc_form": "text_model"
  311. },
  312. "batch": ""
  313. }
  314. ```
  315. </CodeGroup>
  316. </Col>
  317. </Row>
  318. ---
  319. <Heading
  320. url='/datasets/{dataset_id}/documents/{document_id}/update_by_text'
  321. method='POST'
  322. title='Update document via text'
  323. name='#update_by_text'
  324. />
  325. <Row>
  326. <Col>
  327. This api is based on an existing dataset and updates the document through text based on this dataset.
  328. ### Path Params
  329. <Properties>
  330. <Property name='dataset_id' type='string' key='dataset_id'>
  331. Dataset ID
  332. </Property>
  333. <Property name='document_id' type='string' key='document_id'>
  334. Document ID
  335. </Property>
  336. </Properties>
  337. ### Request Body
  338. <Properties>
  339. <Property name='name' type='string' key='name'>
  340. Document name (optional)
  341. </Property>
  342. <Property name='text' type='string' key='text'>
  343. Document content (optional)
  344. </Property>
  345. <Property name='process_rule' type='object' key='process_rule'>
  346. Processing rules
  347. - mode (string) Cleaning, segmentation mode, automatic / custom
  348. - rules (text) Custom rules (in automatic mode, this field is empty)
  349. - pre_processing_rules (array[object]) Preprocessing rules
  350. - id (string) Unique identifier for the preprocessing rule
  351. - enumerate
  352. - remove_extra_spaces Replace consecutive spaces, newlines, tabs
  353. - remove_urls_emails Delete URL, email address
  354. - enabled (bool) Whether to select this rule or not. If no document ID is passed in, it represents the default value.
  355. - segmentation (object) segmentation rules
  356. - separator Custom segment identifier, currently only allows one delimiter to be set. Default is \n
  357. - max_tokens Maximum length (token) defaults to 1000
  358. </Property>
  359. </Properties>
  360. </Col>
  361. <Col sticky>
  362. <CodeGroup
  363. title="Request"
  364. tag="POST"
  365. label="/datasets/{dataset_id}/documents/{document_id}/update_by_text"
  366. 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"}'`}
  367. >
  368. ```bash {{ title: 'cURL' }}
  369. curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}/update_by_text' \
  370. --header 'Authorization: Bearer {api_key}' \
  371. --header 'Content-Type: application/json' \
  372. --data-raw '{
  373. "name": "name",
  374. "text": "text"
  375. }'
  376. ```
  377. </CodeGroup>
  378. <CodeGroup title="Response">
  379. ```json {{ title: 'Response' }}
  380. {
  381. "document": {
  382. "id": "",
  383. "position": 1,
  384. "data_source_type": "upload_file",
  385. "data_source_info": {
  386. "upload_file_id": ""
  387. },
  388. "dataset_process_rule_id": "",
  389. "name": "name.txt",
  390. "created_from": "api",
  391. "created_by": "",
  392. "created_at": 1695308667,
  393. "tokens": 0,
  394. "indexing_status": "waiting",
  395. "error": null,
  396. "enabled": true,
  397. "disabled_at": null,
  398. "disabled_by": null,
  399. "archived": false,
  400. "display_status": "queuing",
  401. "word_count": 0,
  402. "hit_count": 0,
  403. "doc_form": "text_model"
  404. },
  405. "batch": ""
  406. }
  407. ```
  408. </CodeGroup>
  409. </Col>
  410. </Row>
  411. ---
  412. <Heading
  413. url='/datasets/{dataset_id}/documents/{document_id}/update_by_file'
  414. method='POST'
  415. title='Update a document from a file'
  416. name='#update_by_file'
  417. />
  418. <Row>
  419. <Col>
  420. This api is based on an existing dataset, and updates documents through files based on this dataset
  421. ### Path Params
  422. <Properties>
  423. <Property name='dataset_id' type='string' key='dataset_id'>
  424. Dataset ID
  425. </Property>
  426. <Property name='document_id' type='string' key='document_id'>
  427. Document ID
  428. </Property>
  429. </Properties>
  430. ### Request Body
  431. <Properties>
  432. <Property name='name' type='string' key='name'>
  433. Document name (optional)
  434. </Property>
  435. <Property name='file' type='multipart/form-data' key='file'>
  436. Files to be uploaded
  437. </Property>
  438. <Property name='process_rule' type='object' key='process_rule'>
  439. Processing rules
  440. - mode (string) Cleaning, segmentation mode, automatic / custom
  441. - rules (text) Custom rules (in automatic mode, this field is empty)
  442. - pre_processing_rules (array[object]) Preprocessing rules
  443. - id (string) Unique identifier for the preprocessing rule
  444. - enumerate
  445. - remove_extra_spaces Replace consecutive spaces, newlines, tabs
  446. - remove_urls_emails Delete URL, email address
  447. - enabled (bool) Whether to select this rule or not. If no document ID is passed in, it represents the default value.
  448. - segmentation (object) segmentation rules
  449. - separator Custom segment identifier, currently only allows one delimiter to be set. Default is \n
  450. - max_tokens Maximum length (token) defaults to 1000
  451. </Property>
  452. </Properties>
  453. </Col>
  454. <Col sticky>
  455. <CodeGroup
  456. title="Request"
  457. tag="POST"
  458. label="/datasets/{dataset_id}/documents/{document_id}/update_by_file"
  459. 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"'`}
  460. >
  461. ```bash {{ title: 'cURL' }}
  462. curl --location POST 'https://api.dify.ai/v1/datasets/{dataset_id}/document/{document_id}/create_by_file' \
  463. --header 'Authorization: Bearer {api_key}' \
  464. --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' \
  465. --form 'file=@"/path/to/file"'
  466. ```
  467. </CodeGroup>
  468. <CodeGroup title="Response">
  469. ```json {{ title: 'Response' }}
  470. {
  471. "document": {
  472. "id": "",
  473. "position": 1,
  474. "data_source_type": "upload_file",
  475. "data_source_info": {
  476. "upload_file_id": ""
  477. },
  478. "dataset_process_rule_id": "",
  479. "name": "Dify.txt",
  480. "created_from": "api",
  481. "created_by": "",
  482. "created_at": 1695308667,
  483. "tokens": 0,
  484. "indexing_status": "waiting",
  485. "error": null,
  486. "enabled": true,
  487. "disabled_at": null,
  488. "disabled_by": null,
  489. "archived": false,
  490. "display_status": "queuing",
  491. "word_count": 0,
  492. "hit_count": 0,
  493. "doc_form": "text_model"
  494. },
  495. "batch": "20230921150427533684"
  496. }
  497. ```
  498. </CodeGroup>
  499. </Col>
  500. </Row>
  501. ---
  502. <Heading
  503. url='/datasets/{dataset_id}/batch/{batch}/indexing-status'
  504. method='GET'
  505. title='Get document embedding status (progress)'
  506. name='#indexing_status'
  507. />
  508. <Row>
  509. <Col>
  510. ### Path Params
  511. <Properties>
  512. <Property name='dataset_id' type='string' key='dataset_id'>
  513. Dataset ID
  514. </Property>
  515. <Property name='batch' type='string' key='batch'>
  516. Batch number of uploaded documents
  517. </Property>
  518. </Properties>
  519. </Col>
  520. <Col sticky>
  521. <CodeGroup
  522. title="Request"
  523. tag="GET"
  524. label="/datasets/{dataset_id}/batch/{batch}/indexing-status"
  525. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{batch}/indexing-status' \\\n--header 'Authorization: Bearer {api_key}'`}
  526. >
  527. ```bash {{ title: 'cURL' }}
  528. curl --location --request GET 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/{batch}/indexing-status' \
  529. --header 'Authorization: Bearer {api_key}' \
  530. ```
  531. </CodeGroup>
  532. <CodeGroup title="Response">
  533. ```json {{ title: 'Response' }}
  534. {
  535. "data":[{
  536. "id": "",
  537. "indexing_status": "indexing",
  538. "processing_started_at": 1681623462.0,
  539. "parsing_completed_at": 1681623462.0,
  540. "cleaning_completed_at": 1681623462.0,
  541. "splitting_completed_at": 1681623462.0,
  542. "completed_at": null,
  543. "paused_at": null,
  544. "error": null,
  545. "stopped_at": null,
  546. "completed_segments": 24,
  547. "total_segments": 100
  548. }]
  549. }
  550. ```
  551. </CodeGroup>
  552. </Col>
  553. </Row>
  554. ---
  555. <Heading
  556. url='/datasets/{dataset_id}/documents/{document_id}'
  557. method='DELETE'
  558. title='Delete document'
  559. name='#delete_document'
  560. />
  561. <Row>
  562. <Col>
  563. ### Path Params
  564. <Properties>
  565. <Property name='dataset_id' type='string' key='dataset_id'>
  566. Dataset ID
  567. </Property>
  568. <Property name='document_id' type='string' key='document_id'>
  569. Document ID
  570. </Property>
  571. </Properties>
  572. </Col>
  573. <Col sticky>
  574. <CodeGroup
  575. title="Request"
  576. tag="DELETE"
  577. label="/datasets/{dataset_id}/documents/{document_id}"
  578. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  579. >
  580. ```bash {{ title: 'cURL' }}
  581. curl --location --request DELETE 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}' \
  582. --header 'Authorization: Bearer {api_key}' \
  583. ```
  584. </CodeGroup>
  585. <CodeGroup title="Response">
  586. ```json {{ title: 'Response' }}
  587. {
  588. "result": "success"
  589. }
  590. ```
  591. </CodeGroup>
  592. </Col>
  593. </Row>
  594. ---
  595. <Heading
  596. url='/datasets/{dataset_id}/documents'
  597. method='GET'
  598. title='Dataset document list'
  599. name='#dataset_document_list'
  600. />
  601. <Row>
  602. <Col>
  603. ### Path Params
  604. <Properties>
  605. <Property name='dataset_id' type='string' key='dataset_id'>
  606. Dataset ID
  607. </Property>
  608. </Properties>
  609. ### Path Query
  610. <Properties>
  611. <Property name='keyword' type='string' key='keyword'>
  612. Search keywords, currently only search document names(optional)
  613. </Property>
  614. <Property name='page' type='string' key='page'>
  615. Page number(optional)
  616. </Property>
  617. <Property name='limit' type='string' key='limit'>
  618. Number of items returned, default 20, range 1-100(optional)
  619. </Property>
  620. </Properties>
  621. </Col>
  622. <Col sticky>
  623. <CodeGroup
  624. title="Request"
  625. tag="GET"
  626. label="/datasets/{dataset_id}/documents"
  627. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents' \\\n--header 'Authorization: Bearer {api_key}'`}
  628. >
  629. ```bash {{ title: 'cURL' }}
  630. curl --location --request GET 'https://api.dify.ai/v1/datasets/{dataset_id}/documents' \
  631. --header 'Authorization: Bearer {api_key}' \
  632. ```
  633. </CodeGroup>
  634. <CodeGroup title="Response">
  635. ```json {{ title: 'Response' }}
  636. {
  637. "data": [
  638. {
  639. "id": "",
  640. "position": 1,
  641. "data_source_type": "file_upload",
  642. "data_source_info": null,
  643. "dataset_process_rule_id": null,
  644. "name": "dify",
  645. "created_from": "",
  646. "created_by": "",
  647. "created_at": 1681623639,
  648. "tokens": 0,
  649. "indexing_status": "waiting",
  650. "error": null,
  651. "enabled": true,
  652. "disabled_at": null,
  653. "disabled_by": null,
  654. "archived": false
  655. },
  656. ],
  657. "has_more": false,
  658. "limit": 20,
  659. "total": 9,
  660. "page": 1
  661. }
  662. ```
  663. </CodeGroup>
  664. </Col>
  665. </Row>
  666. ---
  667. <Heading
  668. url='/datasets/{dataset_id}/documents/{document_id}/segments'
  669. method='POST'
  670. title='Add segment'
  671. name='#create_new_segment'
  672. />
  673. <Row>
  674. <Col>
  675. ### Path Params
  676. <Properties>
  677. <Property name='dataset_id' type='string' key='dataset_id'>
  678. Dataset ID
  679. </Property>
  680. <Property name='document_id' type='string' key='document_id'>
  681. Document ID
  682. </Property>
  683. </Properties>
  684. ### Request Body
  685. <Properties>
  686. <Property name='segments' type='object list' key='segments'>
  687. segments (object list) Segmented content
  688. - content (text) Text content/question content, required
  689. - answer(text) Answer content, if the mode of the data set is qa mode, pass the value(optional)
  690. - keywords(list) Keywords(optional)
  691. </Property>
  692. </Properties>
  693. </Col>
  694. <Col sticky>
  695. <CodeGroup
  696. title="Request"
  697. tag="POST"
  698. label="/datasets/{dataset_id}/documents/{document_id}/segments"
  699. 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"]}]}'`}
  700. >
  701. ```bash {{ title: 'cURL' }}
  702. curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}/segments' \
  703. --header 'Authorization: Bearer {api_key}' \
  704. --header 'Content-Type: application/json' \
  705. --data-raw '{
  706. "segments": [
  707. {
  708. "content": "1",
  709. "answer": "1",
  710. "keywords": ["a"]
  711. }
  712. ]
  713. }'
  714. ```
  715. </CodeGroup>
  716. <CodeGroup title="Response">
  717. ```json {{ title: 'Response' }}
  718. {
  719. "data": [{
  720. "id": "",
  721. "position": 1,
  722. "document_id": "",
  723. "content": "1",
  724. "answer": "1",
  725. "word_count": 25,
  726. "tokens": 0,
  727. "keywords": [
  728. "a"
  729. ],
  730. "index_node_id": "",
  731. "index_node_hash": "",
  732. "hit_count": 0,
  733. "enabled": true,
  734. "disabled_at": null,
  735. "disabled_by": null,
  736. "status": "completed",
  737. "created_by": "",
  738. "created_at": 1695312007,
  739. "indexing_at": 1695312007,
  740. "completed_at": 1695312007,
  741. "error": null,
  742. "stopped_at": null
  743. }],
  744. "doc_form": "text_model"
  745. }
  746. ```
  747. </CodeGroup>
  748. </Col>
  749. </Row>
  750. ---
  751. Error message
  752. - **document_indexing**: Document indexing failed
  753. - **provider_not_initialize**: Embedding model is not configured
  754. - **not_found**, Document does not exist
  755. - **dataset_name_duplicate**: Duplicate dataset name
  756. - **provider_quota_exceeded**: Model quota exceeds limit
  757. - **dataset_not_initialized**: The dataset has not been initialized yet
  758. - **unsupported_file_type**: Unsupported file types.
  759. - Currently only supports, txt, markdown, md, pdf, html, htm, xlsx, docx, csv
  760. - **too_many_files**: There are too many files. Currently, only a single file is uploaded
  761. - **file_too_large*: The file is too large, support below 15M based on you environment configuration