template.zh.mdx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  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. # 数据集 API
  4. <br/>
  5. <br/>
  6. <Heading
  7. url='/datasets'
  8. method='POST'
  9. title='创建空数据集'
  10. name='#create_empty_dataset'
  11. />
  12. <Row>
  13. <Col>
  14. ### Request Body
  15. <Properties>
  16. <Property name='name' type='string' key='name'>
  17. 数据集名称
  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 'https://api.dify.ai/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='数据集列表'
  67. name='#dataset_list'
  68. />
  69. <Row>
  70. <Col>
  71. ### Path Query
  72. <Properties>
  73. <Property name='page' type='string' key='page'>
  74. 页码
  75. </Property>
  76. <Property name='limit' type='string' key='limit'>
  77. 返回条数,默认 20,范围 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": "数据集名称",
  100. "description": "描述信息",
  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='通过文本创建文档'
  128. name='#create_by_text'
  129. />
  130. <Row>
  131. <Col>
  132. 此接口基于已存在数据集,在此数据集的基础上通过文本创建新的文档
  133. ### Path Params
  134. <Properties>
  135. <Property name='dataset_id' type='string' key='dataset_id'>
  136. 数据集 ID
  137. </Property>
  138. </Properties>
  139. ### Request Body
  140. <Properties>
  141. <Property name='name' type='string' key='name'>
  142. 文档名称
  143. </Property>
  144. <Property name='text' type='string' key='text'>
  145. 文档内容
  146. </Property>
  147. <Property name='indexing_technique' type='string' key='indexing_technique'>
  148. 索引方式
  149. - high_quality 高质量:使用 embedding 模型进行嵌入,构建为向量数据库索引
  150. - economy 经济:使用 Keyword Table Index 的倒排索引进行构建
  151. </Property>
  152. <Property name='process_rule' type='object' key='process_rule'>
  153. 处理规则
  154. - mode (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
  155. - rules (text) 自定义规则(自动模式下,该字段为空)
  156. - pre_processing_rules (array[object]) 预处理规则
  157. - id (string) 预处理规则的唯一标识符
  158. - 枚举:
  159. - remove_extra_spaces 替换连续空格、换行符、制表符
  160. - remove_urls_emails 删除 URL、电子邮件地址
  161. - enabled (bool) 是否选中该规则,不传入文档 ID 时代表默认值
  162. - segmentation (object) 分段规则
  163. - separator 自定义分段标识符,目前仅允许设置一个分隔符。默认为 \n
  164. - max_tokens 最大长度 (token) 默认为 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='通过文件创建文档 '
  227. name='#create_by_file'
  228. />
  229. <Row>
  230. <Col>
  231. 此接口基于已存在数据集,在此数据集的基础上通过文件创建新的文档
  232. ### Path Params
  233. <Properties>
  234. <Property name='dataset_id' type='string' key='dataset_id'>
  235. 数据集 ID
  236. </Property>
  237. </Properties>
  238. ### Request Body
  239. <Properties>
  240. <Property name='original_document_id' type='string' key='original_document_id'>
  241. 源文档 ID (选填)
  242. - 用于重新上传文档或修改文档清洗、分段配置,缺失的信息从源文档复制
  243. - 源文档不可为归档的文档
  244. - 当传入 original_document_id 时,代表文档进行更新操作,process_rule 为可填项目,不填默认使用源文档的分段方式
  245. - 未传入 original_document_id 时,代表文档进行新增操作,process_rule 为必填
  246. </Property>
  247. <Property name='file' type='multipart/form-data' key='file'>
  248. 需要上传的文件。
  249. </Property>
  250. <Property name='indexing_technique' type='string' key='indexing_technique'>
  251. 索引方式
  252. - high_quality 高质量:使用 embedding 模型进行嵌入,构建为向量数据库索引
  253. - economy 经济:使用 Keyword Table Index 的倒排索引进行构建
  254. </Property>
  255. <Property name='process_rule' type='object' key='process_rule'>
  256. 处理规则
  257. - mode (string) 清洗、分段模式 ,automatic 自动 / custom 自定义。
  258. - rules (text) 自定义规则(自动模式下,该字段为空)
  259. - pre_processing_rules (array[object]) 预处理规则
  260. - id (string) 预处理规则的唯一标识符
  261. - 枚举:
  262. - remove_extra_spaces 替换连续空格、换行符、制表符
  263. - remove_urls_emails 删除 URL、电子邮件地址
  264. - enabled (bool) 是否选中该规则,不传入文档 ID 时代表默认值。
  265. - segmentation (object) 分段规则
  266. - separator 自定义分段标识符,目前仅允许设置一个分隔符,默认为 \n
  267. - max_tokens 最大长度 (token) 默认为 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='通过文本更新文档 '
  323. name='#update_by_text'
  324. />
  325. <Row>
  326. <Col>
  327. 此接口基于已存在数据集,在此数据集的基础上通过文本更新文档
  328. ### Path Params
  329. <Properties>
  330. <Property name='dataset_id' type='string' key='dataset_id'>
  331. 数据集 ID
  332. </Property>
  333. <Property name='document_id' type='string' key='document_id'>
  334. 文档 ID
  335. </Property>
  336. </Properties>
  337. ### Request Body
  338. <Properties>
  339. <Property name='name' type='string' key='name'>
  340. 文档名称 (选填)
  341. </Property>
  342. <Property name='text' type='string' key='text'>
  343. 文档内容(选填)
  344. </Property>
  345. <Property name='process_rule' type='object' key='process_rule'>
  346. 处理规则(选填)
  347. - mode (string) 清洗、分段模式 ,automatic 自动 / custom 自定义。
  348. - rules (text) 自定义规则(自动模式下,该字段为空)
  349. - pre_processing_rules (array[object]) 预处理规则
  350. - id (string) 预处理规则的唯一标识符
  351. - 枚举:
  352. - remove_extra_spaces 替换连续空格、换行符、制表符
  353. - remove_urls_emails 删除 URL、电子邮件地址
  354. - enabled (bool) 是否选中该规则,不传入文档 ID 时代表默认值。
  355. - segmentation (object) 分段规则
  356. - separator 自定义分段标识符,目前仅允许设置一个分隔符。默认为 \n
  357. - max_tokens 最大长度 (token) 默认为 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='通过文件更新文档 '
  416. name='#update_by_file'
  417. />
  418. <Row>
  419. <Col>
  420. 此接口基于已存在数据集,在此数据集的基础上通过文件更新文档的操作。
  421. ### Path Params
  422. <Properties>
  423. <Property name='dataset_id' type='string' key='dataset_id'>
  424. 数据集 ID
  425. </Property>
  426. <Property name='document_id' type='string' key='document_id'>
  427. 文档 ID
  428. </Property>
  429. </Properties>
  430. ### Request Body
  431. <Properties>
  432. <Property name='name' type='string' key='name'>
  433. 文档名称 (选填)
  434. </Property>
  435. <Property name='file' type='multipart/form-data' key='file'>
  436. 需要上传的文件
  437. </Property>
  438. <Property name='process_rule' type='object' key='process_rule'>
  439. 处理规则(选填)
  440. - mode (string) 清洗、分段模式 ,automatic 自动 / custom 自定义。
  441. - rules (text) 自定义规则(自动模式下,该字段为空)
  442. - pre_processing_rules (array[object]) 预处理规则
  443. - id (string) 预处理规则的唯一标识符
  444. - 枚举:
  445. - remove_extra_spaces 替换连续空格、换行符、制表符
  446. - remove_urls_emails 删除 URL、电子邮件地址
  447. - enabled (bool) 是否选中该规则,不传入文档 ID 时代表默认值
  448. - segmentation (object) 分段规则
  449. - separator 自定义分段标识符,目前仅允许设置一个分隔符,默认为 \n
  450. - max_tokens 最大长度 (token) 默认为 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='获取文档嵌入状态(进度)'
  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. 数据集 ID
  514. </Property>
  515. <Property name='batch' type='string' key='batch'>
  516. 上传文档的批次号
  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='删除文档'
  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. 数据集 ID
  567. </Property>
  568. <Property name='document_id' type='string' key='document_id'>
  569. 文档 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='数据集文档列表'
  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. 数据集 ID
  607. </Property>
  608. </Properties>
  609. ### Path Query
  610. <Properties>
  611. <Property name='keyword' type='string' key='keyword'>
  612. 搜索关键词,可选,目前仅搜索文档名称
  613. </Property>
  614. <Property name='page' type='string' key='page'>
  615. 页码,可选
  616. </Property>
  617. <Property name='limit' type='string' key='limit'>
  618. 返回条数,可选,默认 20,范围 1-100
  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='新增分段'
  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. 数据集 ID
  679. </Property>
  680. <Property name='document_id' type='string' key='document_id'>
  681. 文档 ID
  682. </Property>
  683. </Properties>
  684. ### Request Body
  685. <Properties>
  686. <Property name='segments' type='object list' key='segments'>
  687. segments (object list) 分段内容
  688. - content (text) 文本内容/问题内容,必填
  689. - answer(text) 答案内容,非必填,如果数据集的模式为qa模式则传值
  690. - keywords(list) 关键字,非必填
  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. 错误信息
  752. - **document_indexing**: 文档索引失败
  753. - **provider_not_initialize**: Embedding 模型未配置
  754. - **not_found**,文档不存在
  755. - **dataset_name_duplicate**: 数据集名称重复
  756. - **provider_quota_exceeded**: 模型额度超过限制
  757. - **dataset_not_initialized**: 数据集还未初始化
  758. - **unsupported_file_type**: 不支持的文件类型
  759. - 目前只支持:txt, markdown, md, pdf, html, htm, xlsx, docx, csv
  760. - **too_many_files**: 文件数量过多,暂时只支持单一文件上传
  761. - **file_too_large*: 文件太大,默认支持15M以下, 具体需要参考环境变量配置