template.zh.mdx 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  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. <div>
  5. ### 鉴权
  6. Dify Service API 使用 `API-Key` 进行鉴权。
  7. 建议开发者把 `API-Key` 放在后端存储,而非分享或者放在客户端存储,以免 `API-Key` 泄露,导致财产损失。
  8. 所有 API 请求都应在 **`Authorization`** HTTP Header 中包含您的 `API-Key`,如下所示:
  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='通过文本创建文档'
  20. name='#create_by_text'
  21. />
  22. <Row>
  23. <Col>
  24. 此接口基于已存在知识库,在此知识库的基础上通过文本创建新的文档
  25. ### Path
  26. <Properties>
  27. <Property name='dataset_id' type='string' key='dataset_id'>
  28. 知识库 ID
  29. </Property>
  30. </Properties>
  31. ### Request Body
  32. <Properties>
  33. <Property name='name' type='string' key='name'>
  34. 文档名称
  35. </Property>
  36. <Property name='text' type='string' key='text'>
  37. 文档内容
  38. </Property>
  39. <Property name='indexing_technique' type='string' key='indexing_technique'>
  40. 索引方式
  41. - <code>high_quality</code> 高质量:使用 embedding 模型进行嵌入,构建为向量数据库索引
  42. - <code>economy</code> 经济:使用 Keyword Table Index 的倒排索引进行构建
  43. </Property>
  44. <Property name='process_rule' type='object' key='process_rule'>
  45. 处理规则
  46. - <code>mode</code> (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
  47. - <code>rules</code> (object) 自定义规则(自动模式下,该字段为空)
  48. - <code>pre_processing_rules</code> (array[object]) 预处理规则
  49. - <code>id</code> (string) 预处理规则的唯一标识符
  50. - 枚举:
  51. - <code>remove_extra_spaces</code> 替换连续空格、换行符、制表符
  52. - <code>remove_urls_emails</code> 删除 URL、电子邮件地址
  53. - <code>enabled</code> (bool) 是否选中该规则,不传入文档 ID 时代表默认值
  54. - <code>segmentation</code> (object) 分段规则
  55. - <code>separator</code> 自定义分段标识符,目前仅允许设置一个分隔符。默认为 \n
  56. - <code>max_tokens</code> 最大长度 (token) 默认为 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 --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='通过文件创建文档 '
  119. name='#create_by_file'
  120. />
  121. <Row>
  122. <Col>
  123. 此接口基于已存在知识库,在此知识库的基础上通过文件创建新的文档
  124. ### Path
  125. <Properties>
  126. <Property name='dataset_id' type='string' key='dataset_id'>
  127. 知识库 ID
  128. </Property>
  129. </Properties>
  130. ### Request Bodys
  131. <Properties>
  132. <Property name='data' type='multipart/form-data json string' key='data'>
  133. - original_document_id 源文档 ID (选填)
  134. - 用于重新上传文档或修改文档清洗、分段配置,缺失的信息从源文档复制
  135. - 源文档不可为归档的文档
  136. - 当传入 <code>original_document_id</code> 时,代表文档进行更新操作,<code>process_rule</code> 为可填项目,不填默认使用源文档的分段方式
  137. - 未传入 <code>original_document_id</code> 时,代表文档进行新增操作,<code>process_rule</code> 为必填
  138. - indexing_technique 索引方式
  139. - <code>high_quality</code> 高质量:使用 embedding 模型进行嵌入,构建为向量数据库索引
  140. - <code>economy</code> 经济:使用 Keyword Table Index 的倒排索引进行构建
  141. - process_rule 处理规则
  142. - <code>mode</code> (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
  143. - <code>rules</code> (object) 自定义规则(自动模式下,该字段为空)
  144. - <code>pre_processing_rules</code> (array[object]) 预处理规则
  145. - <code>id</code> (string) 预处理规则的唯一标识符
  146. - 枚举:
  147. - <code>remove_extra_spaces</code> 替换连续空格、换行符、制表符
  148. - <code>remove_urls_emails</code> 删除 URL、电子邮件地址
  149. - <code>enabled</code> (bool) 是否选中该规则,不传入文档 ID 时代表默认值
  150. - <code>segmentation</code> (object) 分段规则
  151. - <code>separator</code> 自定义分段标识符,目前仅允许设置一个分隔符。默认为 \n
  152. - <code>max_tokens</code> 最大长度 (token) 默认为 1000
  153. </Property>
  154. <Property name='file' type='multipart/form-data' key='file'>
  155. 需要上传的文件。
  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 --request 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 --request 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='创建空知识库'
  211. name='#create_empty_dataset'
  212. />
  213. <Row>
  214. <Col>
  215. ### Request Body
  216. <Properties>
  217. <Property name='name' type='string' key='name'>
  218. 知识库名称
  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 '${props.apiBaseUrl}/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='知识库列表'
  268. name='#dataset_list'
  269. />
  270. <Row>
  271. <Col>
  272. ### Query
  273. <Properties>
  274. <Property name='page' type='string' key='page'>
  275. 页码
  276. </Property>
  277. <Property name='limit' type='string' key='limit'>
  278. 返回条数,默认 20,范围 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": "知识库名称",
  301. "description": "描述信息",
  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='通过文本更新文档 '
  329. name='#update_by_text'
  330. />
  331. <Row>
  332. <Col>
  333. 此接口基于已存在知识库,在此知识库的基础上通过文本更新文档
  334. ### Path
  335. <Properties>
  336. <Property name='dataset_id' type='string' key='dataset_id'>
  337. 知识库 ID
  338. </Property>
  339. <Property name='document_id' type='string' key='document_id'>
  340. 文档 ID
  341. </Property>
  342. </Properties>
  343. ### Request Body
  344. <Properties>
  345. <Property name='name' type='string' key='name'>
  346. 文档名称 (选填)
  347. </Property>
  348. <Property name='text' type='string' key='text'>
  349. 文档内容(选填)
  350. </Property>
  351. <Property name='process_rule' type='object' key='process_rule'>
  352. 处理规则(选填)
  353. - <code>mode</code> (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
  354. - <code>rules</code> (object) 自定义规则(自动模式下,该字段为空)
  355. - <code>pre_processing_rules</code> (array[object]) 预处理规则
  356. - <code>id</code> (string) 预处理规则的唯一标识符
  357. - 枚举:
  358. - <code>remove_extra_spaces</code> 替换连续空格、换行符、制表符
  359. - <code>remove_urls_emails</code> 删除 URL、电子邮件地址
  360. - <code>enabled</code> (bool) 是否选中该规则,不传入文档 ID 时代表默认值
  361. - <code>segmentation</code> (object) 分段规则
  362. - <code>separator</code> 自定义分段标识符,目前仅允许设置一个分隔符。默认为 \n
  363. - <code>max_tokens</code> 最大长度 (token) 默认为 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='通过文件更新文档 '
  422. name='#update_by_file'
  423. />
  424. <Row>
  425. <Col>
  426. 此接口基于已存在知识库,在此知识库的基础上通过文件更新文档的操作。
  427. ### Path
  428. <Properties>
  429. <Property name='dataset_id' type='string' key='dataset_id'>
  430. 知识库 ID
  431. </Property>
  432. <Property name='document_id' type='string' key='document_id'>
  433. 文档 ID
  434. </Property>
  435. </Properties>
  436. ### Request Body
  437. <Properties>
  438. <Property name='name' type='string' key='name'>
  439. 文档名称 (选填)
  440. </Property>
  441. <Property name='file' type='multipart/form-data' key='file'>
  442. 需要上传的文件
  443. </Property>
  444. <Property name='process_rule' type='object' key='process_rule'>
  445. 处理规则(选填)
  446. - <code>mode</code> (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
  447. - <code>rules</code> (object) 自定义规则(自动模式下,该字段为空)
  448. - <code>pre_processing_rules</code> (array[object]) 预处理规则
  449. - <code>id</code> (string) 预处理规则的唯一标识符
  450. - 枚举:
  451. - <code>remove_extra_spaces</code> 替换连续空格、换行符、制表符
  452. - <code>remove_urls_emails</code> 删除 URL、电子邮件地址
  453. - <code>enabled</code> (bool) 是否选中该规则,不传入文档 ID 时代表默认值
  454. - <code>segmentation</code> (object) 分段规则
  455. - <code>separator</code> 自定义分段标识符,目前仅允许设置一个分隔符。默认为 \n
  456. - <code>max_tokens</code> 最大长度 (token) 默认为 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 --request 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 --request 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='获取文档嵌入状态(进度)'
  512. name='#indexing_status'
  513. />
  514. <Row>
  515. <Col>
  516. ### Path
  517. <Properties>
  518. <Property name='dataset_id' type='string' key='dataset_id'>
  519. 知识库 ID
  520. </Property>
  521. <Property name='batch' type='string' key='batch'>
  522. 上传文档的批次号
  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='删除文档'
  565. name='#delete_document'
  566. />
  567. <Row>
  568. <Col>
  569. ### Path
  570. <Properties>
  571. <Property name='dataset_id' type='string' key='dataset_id'>
  572. 知识库 ID
  573. </Property>
  574. <Property name='document_id' type='string' key='document_id'>
  575. 文档 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='知识库文档列表'
  605. name='#dataset_document_list'
  606. />
  607. <Row>
  608. <Col>
  609. ### Path
  610. <Properties>
  611. <Property name='dataset_id' type='string' key='dataset_id'>
  612. 知识库 ID
  613. </Property>
  614. </Properties>
  615. ### Query
  616. <Properties>
  617. <Property name='keyword' type='string' key='keyword'>
  618. 搜索关键词,可选,目前仅搜索文档名称
  619. </Property>
  620. <Property name='page' type='string' key='page'>
  621. 页码,可选
  622. </Property>
  623. <Property name='limit' type='string' key='limit'>
  624. 返回条数,可选,默认 20,范围 1-100
  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='新增分段'
  677. name='#create_new_segment'
  678. />
  679. <Row>
  680. <Col>
  681. ### Path
  682. <Properties>
  683. <Property name='dataset_id' type='string' key='dataset_id'>
  684. 知识库 ID
  685. </Property>
  686. <Property name='document_id' type='string' key='document_id'>
  687. 文档 ID
  688. </Property>
  689. </Properties>
  690. ### Request Body
  691. <Properties>
  692. <Property name='segments' type='object list' key='segments'>
  693. - <code>content</code> (text) 文本内容/问题内容,必填
  694. - <code>answer</code> (text) 答案内容,非必填,如果知识库的模式为qa模式则传值
  695. - <code>keywords</code> (list) 关键字,非必填
  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='查询文档分段'
  760. name='#get_segment'
  761. />
  762. <Row>
  763. <Col>
  764. ### Path
  765. <Properties>
  766. <Property name='dataset_id' type='string' key='dataset_id'>
  767. 知识库 ID
  768. </Property>
  769. <Property name='document_id' type='string' key='document_id'>
  770. 文档 ID
  771. </Property>
  772. </Properties>
  773. ### Query
  774. <Properties>
  775. <Property name='keyword' type='string' key='keyword'>
  776. 搜索关键词,可选
  777. </Property>
  778. <Property name='status' type='string' key='status'>
  779. 搜索状态,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='删除文档分段'
  835. name='#delete_segment'
  836. />
  837. <Row>
  838. <Col>
  839. ### Path
  840. <Properties>
  841. <Property name='dataset_id' type='string' key='dataset_id'>
  842. 知识库 ID
  843. </Property>
  844. <Property name='segment_id' type='string' key='segment_id'>
  845. 文档分段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}/documents/{document_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}/documents/{document_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='更新文档分段'
  876. name='#update_segment'
  877. />
  878. <Row>
  879. <Col>
  880. ### POST
  881. <Properties>
  882. <Property name='dataset_id' type='string' key='dataset_id'>
  883. 知识库 ID
  884. </Property>
  885. <Property name='segment_id' type='string' key='segment_id'>
  886. 文档分段ID
  887. </Property>
  888. </Properties>
  889. ### Request Body
  890. <Properties>
  891. <Property name='segment' type='object list' key='segment'>
  892. - <code>content</code> (text) 文本内容/问题内容,必填
  893. - <code>answer</code> (text) 答案内容,非必填,如果知识库的模式为qa模式则传值
  894. - <code>keywords</code> (list) 关键字,非必填
  895. - <code>enabled</code> (bool) false/true,非必填
  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 '{\"segment\": {\"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 'Authorization: Bearer {api_key}' \
  909. --header 'Content-Type: application/json' \
  910. --data-raw '{
  911. "segment": {
  912. "content": "1",
  913. "answer": "1",
  914. "keywords": ["a"],
  915. "enabled": false
  916. }
  917. }'
  918. ```
  919. </CodeGroup>
  920. <CodeGroup title="Response">
  921. ```json {{ title: 'Response' }}
  922. {
  923. "data": [{
  924. "id": "",
  925. "position": 1,
  926. "document_id": "",
  927. "content": "1",
  928. "answer": "1",
  929. "word_count": 25,
  930. "tokens": 0,
  931. "keywords": [
  932. "a"
  933. ],
  934. "index_node_id": "",
  935. "index_node_hash": "",
  936. "hit_count": 0,
  937. "enabled": true,
  938. "disabled_at": null,
  939. "disabled_by": null,
  940. "status": "completed",
  941. "created_by": "",
  942. "created_at": 1695312007,
  943. "indexing_at": 1695312007,
  944. "completed_at": 1695312007,
  945. "error": null,
  946. "stopped_at": null
  947. }],
  948. "doc_form": "text_model"
  949. }
  950. ```
  951. </CodeGroup>
  952. </Col>
  953. </Row>
  954. ---
  955. <Row>
  956. <Col>
  957. ### 错误信息
  958. <Properties>
  959. <Property name='code' type='string' key='code'>
  960. 返回的错误代码
  961. </Property>
  962. </Properties>
  963. <Properties>
  964. <Property name='status' type='number' key='status'>
  965. 返回的错误状态
  966. </Property>
  967. </Properties>
  968. <Properties>
  969. <Property name='message' type='string' key='message'>
  970. 返回的错误信息
  971. </Property>
  972. </Properties>
  973. </Col>
  974. <Col>
  975. <CodeGroup title="Example">
  976. ```json {{ title: 'Response' }}
  977. {
  978. "code": "no_file_uploaded",
  979. "message": "Please upload your file.",
  980. "status": 400
  981. }
  982. ```
  983. </CodeGroup>
  984. </Col>
  985. </Row>
  986. <table className="max-w-auto border-collapse border border-slate-400" style={{ maxWidth: 'none', width: 'auto' }}>
  987. <thead style={{ background: '#f9fafc' }}>
  988. <tr>
  989. <th className="p-2 border border-slate-300">code</th>
  990. <th className="p-2 border border-slate-300">status</th>
  991. <th className="p-2 border border-slate-300">message</th>
  992. </tr>
  993. </thead>
  994. <tbody>
  995. <tr>
  996. <td className="p-2 border border-slate-300">no_file_uploaded</td>
  997. <td className="p-2 border border-slate-300">400</td>
  998. <td className="p-2 border border-slate-300">Please upload your file.</td>
  999. </tr>
  1000. <tr>
  1001. <td className="p-2 border border-slate-300">too_many_files</td>
  1002. <td className="p-2 border border-slate-300">400</td>
  1003. <td className="p-2 border border-slate-300">Only one file is allowed.</td>
  1004. </tr>
  1005. <tr>
  1006. <td className="p-2 border border-slate-300">file_too_large</td>
  1007. <td className="p-2 border border-slate-300">413</td>
  1008. <td className="p-2 border border-slate-300">File size exceeded.</td>
  1009. </tr>
  1010. <tr>
  1011. <td className="p-2 border border-slate-300">unsupported_file_type</td>
  1012. <td className="p-2 border border-slate-300">415</td>
  1013. <td className="p-2 border border-slate-300">File type not allowed.</td>
  1014. </tr>
  1015. <tr>
  1016. <td className="p-2 border border-slate-300">high_quality_dataset_only</td>
  1017. <td className="p-2 border border-slate-300">400</td>
  1018. <td className="p-2 border border-slate-300">Current operation only supports 'high-quality' datasets.</td>
  1019. </tr>
  1020. <tr>
  1021. <td className="p-2 border border-slate-300">dataset_not_initialized</td>
  1022. <td className="p-2 border border-slate-300">400</td>
  1023. <td className="p-2 border border-slate-300">The dataset is still being initialized or indexing. Please wait a moment.</td>
  1024. </tr>
  1025. <tr>
  1026. <td className="p-2 border border-slate-300">archived_document_immutable</td>
  1027. <td className="p-2 border border-slate-300">403</td>
  1028. <td className="p-2 border border-slate-300">The archived document is not editable.</td>
  1029. </tr>
  1030. <tr>
  1031. <td className="p-2 border border-slate-300">dataset_name_duplicate</td>
  1032. <td className="p-2 border border-slate-300">409</td>
  1033. <td className="p-2 border border-slate-300">The dataset name already exists. Please modify your dataset name.</td>
  1034. </tr>
  1035. <tr>
  1036. <td className="p-2 border border-slate-300">invalid_action</td>
  1037. <td className="p-2 border border-slate-300">400</td>
  1038. <td className="p-2 border border-slate-300">Invalid action.</td>
  1039. </tr>
  1040. <tr>
  1041. <td className="p-2 border border-slate-300">document_already_finished</td>
  1042. <td className="p-2 border border-slate-300">400</td>
  1043. <td className="p-2 border border-slate-300">The document has been processed. Please refresh the page or go to the document details.</td>
  1044. </tr>
  1045. <tr>
  1046. <td className="p-2 border border-slate-300">document_indexing</td>
  1047. <td className="p-2 border border-slate-300">400</td>
  1048. <td className="p-2 border border-slate-300">The document is being processed and cannot be edited.</td>
  1049. </tr>
  1050. <tr>
  1051. <td className="p-2 border border-slate-300">invalid_metadata</td>
  1052. <td className="p-2 border border-slate-300">400</td>
  1053. <td className="p-2 border border-slate-300">The metadata content is incorrect. Please check and verify.</td>
  1054. </tr>
  1055. </tbody>
  1056. </table>
  1057. <div className="pb-4" />