template.zh.mdx 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  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}'
  327. method='DELETE'
  328. title='删除知识库'
  329. name='#delete_dataset'
  330. />
  331. <Row>
  332. <Col>
  333. ### Path
  334. <Properties>
  335. <Property name='dataset_id' type='string' key='dataset_id'>
  336. 知识库 ID
  337. </Property>
  338. </Properties>
  339. </Col>
  340. <Col sticky>
  341. <CodeGroup
  342. title="Request"
  343. tag="DELETE"
  344. label="/datasets/{dataset_id}"
  345. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  346. >
  347. ```bash {{ title: 'cURL' }}
  348. curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}' \
  349. --header 'Authorization: Bearer {api_key}'
  350. ```
  351. </CodeGroup>
  352. <CodeGroup title="Response">
  353. ```text {{ title: 'Response' }}
  354. 204 No Content
  355. ```
  356. </CodeGroup>
  357. </Col>
  358. </Row>
  359. ---
  360. <Heading
  361. url='/datasets/{dataset_id}/documents/{document_id}/update_by_text'
  362. method='POST'
  363. title='通过文本更新文档 '
  364. name='#update_by_text'
  365. />
  366. <Row>
  367. <Col>
  368. 此接口基于已存在知识库,在此知识库的基础上通过文本更新文档
  369. ### Path
  370. <Properties>
  371. <Property name='dataset_id' type='string' key='dataset_id'>
  372. 知识库 ID
  373. </Property>
  374. <Property name='document_id' type='string' key='document_id'>
  375. 文档 ID
  376. </Property>
  377. </Properties>
  378. ### Request Body
  379. <Properties>
  380. <Property name='name' type='string' key='name'>
  381. 文档名称 (选填)
  382. </Property>
  383. <Property name='text' type='string' key='text'>
  384. 文档内容(选填)
  385. </Property>
  386. <Property name='process_rule' type='object' key='process_rule'>
  387. 处理规则(选填)
  388. - <code>mode</code> (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
  389. - <code>rules</code> (object) 自定义规则(自动模式下,该字段为空)
  390. - <code>pre_processing_rules</code> (array[object]) 预处理规则
  391. - <code>id</code> (string) 预处理规则的唯一标识符
  392. - 枚举:
  393. - <code>remove_extra_spaces</code> 替换连续空格、换行符、制表符
  394. - <code>remove_urls_emails</code> 删除 URL、电子邮件地址
  395. - <code>enabled</code> (bool) 是否选中该规则,不传入文档 ID 时代表默认值
  396. - <code>segmentation</code> (object) 分段规则
  397. - <code>separator</code> 自定义分段标识符,目前仅允许设置一个分隔符。默认为 \n
  398. - <code>max_tokens</code> 最大长度 (token) 默认为 1000
  399. </Property>
  400. </Properties>
  401. </Col>
  402. <Col sticky>
  403. <CodeGroup
  404. title="Request"
  405. tag="POST"
  406. label="/datasets/{dataset_id}/documents/{document_id}/update_by_text"
  407. 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"}'`}
  408. >
  409. ```bash {{ title: 'cURL' }}
  410. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/update_by_text' \
  411. --header 'Authorization: Bearer {api_key}' \
  412. --header 'Content-Type: application/json' \
  413. --data-raw '{
  414. "name": "name",
  415. "text": "text"
  416. }'
  417. ```
  418. </CodeGroup>
  419. <CodeGroup title="Response">
  420. ```json {{ title: 'Response' }}
  421. {
  422. "document": {
  423. "id": "",
  424. "position": 1,
  425. "data_source_type": "upload_file",
  426. "data_source_info": {
  427. "upload_file_id": ""
  428. },
  429. "dataset_process_rule_id": "",
  430. "name": "name.txt",
  431. "created_from": "api",
  432. "created_by": "",
  433. "created_at": 1695308667,
  434. "tokens": 0,
  435. "indexing_status": "waiting",
  436. "error": null,
  437. "enabled": true,
  438. "disabled_at": null,
  439. "disabled_by": null,
  440. "archived": false,
  441. "display_status": "queuing",
  442. "word_count": 0,
  443. "hit_count": 0,
  444. "doc_form": "text_model"
  445. },
  446. "batch": ""
  447. }
  448. ```
  449. </CodeGroup>
  450. </Col>
  451. </Row>
  452. ---
  453. <Heading
  454. url='/datasets/{dataset_id}/documents/{document_id}/update_by_file'
  455. method='POST'
  456. title='通过文件更新文档 '
  457. name='#update_by_file'
  458. />
  459. <Row>
  460. <Col>
  461. 此接口基于已存在知识库,在此知识库的基础上通过文件更新文档的操作。
  462. ### Path
  463. <Properties>
  464. <Property name='dataset_id' type='string' key='dataset_id'>
  465. 知识库 ID
  466. </Property>
  467. <Property name='document_id' type='string' key='document_id'>
  468. 文档 ID
  469. </Property>
  470. </Properties>
  471. ### Request Body
  472. <Properties>
  473. <Property name='name' type='string' key='name'>
  474. 文档名称 (选填)
  475. </Property>
  476. <Property name='file' type='multipart/form-data' key='file'>
  477. 需要上传的文件
  478. </Property>
  479. <Property name='process_rule' type='object' key='process_rule'>
  480. 处理规则(选填)
  481. - <code>mode</code> (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
  482. - <code>rules</code> (object) 自定义规则(自动模式下,该字段为空)
  483. - <code>pre_processing_rules</code> (array[object]) 预处理规则
  484. - <code>id</code> (string) 预处理规则的唯一标识符
  485. - 枚举:
  486. - <code>remove_extra_spaces</code> 替换连续空格、换行符、制表符
  487. - <code>remove_urls_emails</code> 删除 URL、电子邮件地址
  488. - <code>enabled</code> (bool) 是否选中该规则,不传入文档 ID 时代表默认值
  489. - <code>segmentation</code> (object) 分段规则
  490. - <code>separator</code> 自定义分段标识符,目前仅允许设置一个分隔符。默认为 \n
  491. - <code>max_tokens</code> 最大长度 (token) 默认为 1000
  492. </Property>
  493. </Properties>
  494. </Col>
  495. <Col sticky>
  496. <CodeGroup
  497. title="Request"
  498. tag="POST"
  499. label="/datasets/{dataset_id}/documents/{document_id}/update_by_file"
  500. targetCode={`curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/update_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"'`}
  501. >
  502. ```bash {{ title: 'cURL' }}
  503. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/update_by_file' \
  504. --header 'Authorization: Bearer {api_key}' \
  505. --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' \
  506. --form 'file=@"/path/to/file"'
  507. ```
  508. </CodeGroup>
  509. <CodeGroup title="Response">
  510. ```json {{ title: 'Response' }}
  511. {
  512. "document": {
  513. "id": "",
  514. "position": 1,
  515. "data_source_type": "upload_file",
  516. "data_source_info": {
  517. "upload_file_id": ""
  518. },
  519. "dataset_process_rule_id": "",
  520. "name": "Dify.txt",
  521. "created_from": "api",
  522. "created_by": "",
  523. "created_at": 1695308667,
  524. "tokens": 0,
  525. "indexing_status": "waiting",
  526. "error": null,
  527. "enabled": true,
  528. "disabled_at": null,
  529. "disabled_by": null,
  530. "archived": false,
  531. "display_status": "queuing",
  532. "word_count": 0,
  533. "hit_count": 0,
  534. "doc_form": "text_model"
  535. },
  536. "batch": "20230921150427533684"
  537. }
  538. ```
  539. </CodeGroup>
  540. </Col>
  541. </Row>
  542. ---
  543. <Heading
  544. url='/datasets/{dataset_id}/documents/{batch}/indexing-status'
  545. method='GET'
  546. title='获取文档嵌入状态(进度)'
  547. name='#indexing_status'
  548. />
  549. <Row>
  550. <Col>
  551. ### Path
  552. <Properties>
  553. <Property name='dataset_id' type='string' key='dataset_id'>
  554. 知识库 ID
  555. </Property>
  556. <Property name='batch' type='string' key='batch'>
  557. 上传文档的批次号
  558. </Property>
  559. </Properties>
  560. </Col>
  561. <Col sticky>
  562. <CodeGroup
  563. title="Request"
  564. tag="GET"
  565. label="/datasets/{dataset_id}/documents/{batch}/indexing-status"
  566. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{batch}/indexing-status' \\\n--header 'Authorization: Bearer {api_key}'`}
  567. >
  568. ```bash {{ title: 'cURL' }}
  569. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{batch}/indexing-status' \
  570. --header 'Authorization: Bearer {api_key}' \
  571. ```
  572. </CodeGroup>
  573. <CodeGroup title="Response">
  574. ```json {{ title: 'Response' }}
  575. {
  576. "data":[{
  577. "id": "",
  578. "indexing_status": "indexing",
  579. "processing_started_at": 1681623462.0,
  580. "parsing_completed_at": 1681623462.0,
  581. "cleaning_completed_at": 1681623462.0,
  582. "splitting_completed_at": 1681623462.0,
  583. "completed_at": null,
  584. "paused_at": null,
  585. "error": null,
  586. "stopped_at": null,
  587. "completed_segments": 24,
  588. "total_segments": 100
  589. }]
  590. }
  591. ```
  592. </CodeGroup>
  593. </Col>
  594. </Row>
  595. ---
  596. <Heading
  597. url='/datasets/{dataset_id}/documents/{document_id}'
  598. method='DELETE'
  599. title='删除文档'
  600. name='#delete_document'
  601. />
  602. <Row>
  603. <Col>
  604. ### Path
  605. <Properties>
  606. <Property name='dataset_id' type='string' key='dataset_id'>
  607. 知识库 ID
  608. </Property>
  609. <Property name='document_id' type='string' key='document_id'>
  610. 文档 ID
  611. </Property>
  612. </Properties>
  613. </Col>
  614. <Col sticky>
  615. <CodeGroup
  616. title="Request"
  617. tag="DELETE"
  618. label="/datasets/{dataset_id}/documents/{document_id}"
  619. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  620. >
  621. ```bash {{ title: 'cURL' }}
  622. curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}' \
  623. --header 'Authorization: Bearer {api_key}' \
  624. ```
  625. </CodeGroup>
  626. <CodeGroup title="Response">
  627. ```json {{ title: 'Response' }}
  628. {
  629. "result": "success"
  630. }
  631. ```
  632. </CodeGroup>
  633. </Col>
  634. </Row>
  635. ---
  636. <Heading
  637. url='/datasets/{dataset_id}/documents'
  638. method='GET'
  639. title='知识库文档列表'
  640. name='#dataset_document_list'
  641. />
  642. <Row>
  643. <Col>
  644. ### Path
  645. <Properties>
  646. <Property name='dataset_id' type='string' key='dataset_id'>
  647. 知识库 ID
  648. </Property>
  649. </Properties>
  650. ### Query
  651. <Properties>
  652. <Property name='keyword' type='string' key='keyword'>
  653. 搜索关键词,可选,目前仅搜索文档名称
  654. </Property>
  655. <Property name='page' type='string' key='page'>
  656. 页码,可选
  657. </Property>
  658. <Property name='limit' type='string' key='limit'>
  659. 返回条数,可选,默认 20,范围 1-100
  660. </Property>
  661. </Properties>
  662. </Col>
  663. <Col sticky>
  664. <CodeGroup
  665. title="Request"
  666. tag="GET"
  667. label="/datasets/{dataset_id}/documents"
  668. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents' \\\n--header 'Authorization: Bearer {api_key}'`}
  669. >
  670. ```bash {{ title: 'cURL' }}
  671. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents' \
  672. --header 'Authorization: Bearer {api_key}' \
  673. ```
  674. </CodeGroup>
  675. <CodeGroup title="Response">
  676. ```json {{ title: 'Response' }}
  677. {
  678. "data": [
  679. {
  680. "id": "",
  681. "position": 1,
  682. "data_source_type": "file_upload",
  683. "data_source_info": null,
  684. "dataset_process_rule_id": null,
  685. "name": "dify",
  686. "created_from": "",
  687. "created_by": "",
  688. "created_at": 1681623639,
  689. "tokens": 0,
  690. "indexing_status": "waiting",
  691. "error": null,
  692. "enabled": true,
  693. "disabled_at": null,
  694. "disabled_by": null,
  695. "archived": false
  696. },
  697. ],
  698. "has_more": false,
  699. "limit": 20,
  700. "total": 9,
  701. "page": 1
  702. }
  703. ```
  704. </CodeGroup>
  705. </Col>
  706. </Row>
  707. ---
  708. <Heading
  709. url='/datasets/{dataset_id}/documents/{document_id}/segments'
  710. method='POST'
  711. title='新增分段'
  712. name='#create_new_segment'
  713. />
  714. <Row>
  715. <Col>
  716. ### Path
  717. <Properties>
  718. <Property name='dataset_id' type='string' key='dataset_id'>
  719. 知识库 ID
  720. </Property>
  721. <Property name='document_id' type='string' key='document_id'>
  722. 文档 ID
  723. </Property>
  724. </Properties>
  725. ### Request Body
  726. <Properties>
  727. <Property name='segments' type='object list' key='segments'>
  728. - <code>content</code> (text) 文本内容/问题内容,必填
  729. - <code>answer</code> (text) 答案内容,非必填,如果知识库的模式为qa模式则传值
  730. - <code>keywords</code> (list) 关键字,非必填
  731. </Property>
  732. </Properties>
  733. </Col>
  734. <Col sticky>
  735. <CodeGroup
  736. title="Request"
  737. tag="POST"
  738. label="/datasets/{dataset_id}/documents/{document_id}/segments"
  739. 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"]}]}'`}
  740. >
  741. ```bash {{ title: 'cURL' }}
  742. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments' \
  743. --header 'Authorization: Bearer {api_key}' \
  744. --header 'Content-Type: application/json' \
  745. --data-raw '{
  746. "segments": [
  747. {
  748. "content": "1",
  749. "answer": "1",
  750. "keywords": ["a"]
  751. }
  752. ]
  753. }'
  754. ```
  755. </CodeGroup>
  756. <CodeGroup title="Response">
  757. ```json {{ title: 'Response' }}
  758. {
  759. "data": [{
  760. "id": "",
  761. "position": 1,
  762. "document_id": "",
  763. "content": "1",
  764. "answer": "1",
  765. "word_count": 25,
  766. "tokens": 0,
  767. "keywords": [
  768. "a"
  769. ],
  770. "index_node_id": "",
  771. "index_node_hash": "",
  772. "hit_count": 0,
  773. "enabled": true,
  774. "disabled_at": null,
  775. "disabled_by": null,
  776. "status": "completed",
  777. "created_by": "",
  778. "created_at": 1695312007,
  779. "indexing_at": 1695312007,
  780. "completed_at": 1695312007,
  781. "error": null,
  782. "stopped_at": null
  783. }],
  784. "doc_form": "text_model"
  785. }
  786. ```
  787. </CodeGroup>
  788. </Col>
  789. </Row>
  790. ---
  791. <Heading
  792. url='/datasets/{dataset_id}/documents/{document_id}/segments'
  793. method='GET'
  794. title='查询文档分段'
  795. name='#get_segment'
  796. />
  797. <Row>
  798. <Col>
  799. ### Path
  800. <Properties>
  801. <Property name='dataset_id' type='string' key='dataset_id'>
  802. 知识库 ID
  803. </Property>
  804. <Property name='document_id' type='string' key='document_id'>
  805. 文档 ID
  806. </Property>
  807. </Properties>
  808. ### Query
  809. <Properties>
  810. <Property name='keyword' type='string' key='keyword'>
  811. 搜索关键词,可选
  812. </Property>
  813. <Property name='status' type='string' key='status'>
  814. 搜索状态,completed
  815. </Property>
  816. </Properties>
  817. </Col>
  818. <Col sticky>
  819. <CodeGroup
  820. title="Request"
  821. tag="GET"
  822. label="/datasets/{dataset_id}/documents/{document_id}/segments"
  823. 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'`}
  824. >
  825. ```bash {{ title: 'cURL' }}
  826. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments' \
  827. --header 'Authorization: Bearer {api_key}' \
  828. --header 'Content-Type: application/json'
  829. ```
  830. </CodeGroup>
  831. <CodeGroup title="Response">
  832. ```json {{ title: 'Response' }}
  833. {
  834. "data": [{
  835. "id": "",
  836. "position": 1,
  837. "document_id": "",
  838. "content": "1",
  839. "answer": "1",
  840. "word_count": 25,
  841. "tokens": 0,
  842. "keywords": [
  843. "a"
  844. ],
  845. "index_node_id": "",
  846. "index_node_hash": "",
  847. "hit_count": 0,
  848. "enabled": true,
  849. "disabled_at": null,
  850. "disabled_by": null,
  851. "status": "completed",
  852. "created_by": "",
  853. "created_at": 1695312007,
  854. "indexing_at": 1695312007,
  855. "completed_at": 1695312007,
  856. "error": null,
  857. "stopped_at": null
  858. }],
  859. "doc_form": "text_model"
  860. }
  861. ```
  862. </CodeGroup>
  863. </Col>
  864. </Row>
  865. ---
  866. <Heading
  867. url='/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}'
  868. method='DELETE'
  869. title='删除文档分段'
  870. name='#delete_segment'
  871. />
  872. <Row>
  873. <Col>
  874. ### Path
  875. <Properties>
  876. <Property name='dataset_id' type='string' key='dataset_id'>
  877. 知识库 ID
  878. </Property>
  879. <Property name='document_id' type='string' key='document_id'>
  880. 文档 ID
  881. </Property>
  882. <Property name='segment_id' type='string' key='segment_id'>
  883. 文档分段ID
  884. </Property>
  885. </Properties>
  886. </Col>
  887. <Col sticky>
  888. <CodeGroup
  889. title="Request"
  890. tag="DELETE"
  891. label="/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}"
  892. 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'`}
  893. >
  894. ```bash {{ title: 'cURL' }}
  895. curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}' \
  896. --header 'Authorization: Bearer {api_key}' \
  897. --header 'Content-Type: application/json'
  898. ```
  899. </CodeGroup>
  900. <CodeGroup title="Response">
  901. ```json {{ title: 'Response' }}
  902. {
  903. "result": "success"
  904. }
  905. ```
  906. </CodeGroup>
  907. </Col>
  908. </Row>
  909. ---
  910. <Heading
  911. url='/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}'
  912. method='POST'
  913. title='更新文档分段'
  914. name='#update_segment'
  915. />
  916. <Row>
  917. <Col>
  918. ### POST
  919. <Properties>
  920. <Property name='dataset_id' type='string' key='dataset_id'>
  921. 知识库 ID
  922. </Property>
  923. <Property name='document_id' type='string' key='document_id'>
  924. 文档 ID
  925. </Property>
  926. <Property name='segment_id' type='string' key='segment_id'>
  927. 文档分段ID
  928. </Property>
  929. </Properties>
  930. ### Request Body
  931. <Properties>
  932. <Property name='segment' type='object list' key='segment'>
  933. - <code>content</code> (text) 文本内容/问题内容,必填
  934. - <code>answer</code> (text) 答案内容,非必填,如果知识库的模式为qa模式则传值
  935. - <code>keywords</code> (list) 关键字,非必填
  936. - <code>enabled</code> (bool) false/true,非必填
  937. </Property>
  938. </Properties>
  939. </Col>
  940. <Col sticky>
  941. <CodeGroup
  942. title="Request"
  943. tag="POST"
  944. label="/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}"
  945. 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}}'`}
  946. >
  947. ```bash {{ title: 'cURL' }}
  948. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}' \
  949. --header 'Authorization: Bearer {api_key}' \
  950. --header 'Content-Type: application/json' \
  951. --data-raw '{
  952. "segment": {
  953. "content": "1",
  954. "answer": "1",
  955. "keywords": ["a"],
  956. "enabled": false
  957. }
  958. }'
  959. ```
  960. </CodeGroup>
  961. <CodeGroup title="Response">
  962. ```json {{ title: 'Response' }}
  963. {
  964. "data": [{
  965. "id": "",
  966. "position": 1,
  967. "document_id": "",
  968. "content": "1",
  969. "answer": "1",
  970. "word_count": 25,
  971. "tokens": 0,
  972. "keywords": [
  973. "a"
  974. ],
  975. "index_node_id": "",
  976. "index_node_hash": "",
  977. "hit_count": 0,
  978. "enabled": true,
  979. "disabled_at": null,
  980. "disabled_by": null,
  981. "status": "completed",
  982. "created_by": "",
  983. "created_at": 1695312007,
  984. "indexing_at": 1695312007,
  985. "completed_at": 1695312007,
  986. "error": null,
  987. "stopped_at": null
  988. }],
  989. "doc_form": "text_model"
  990. }
  991. ```
  992. </CodeGroup>
  993. </Col>
  994. </Row>
  995. ---
  996. <Row>
  997. <Col>
  998. ### 错误信息
  999. <Properties>
  1000. <Property name='code' type='string' key='code'>
  1001. 返回的错误代码
  1002. </Property>
  1003. </Properties>
  1004. <Properties>
  1005. <Property name='status' type='number' key='status'>
  1006. 返回的错误状态
  1007. </Property>
  1008. </Properties>
  1009. <Properties>
  1010. <Property name='message' type='string' key='message'>
  1011. 返回的错误信息
  1012. </Property>
  1013. </Properties>
  1014. </Col>
  1015. <Col>
  1016. <CodeGroup title="Example">
  1017. ```json {{ title: 'Response' }}
  1018. {
  1019. "code": "no_file_uploaded",
  1020. "message": "Please upload your file.",
  1021. "status": 400
  1022. }
  1023. ```
  1024. </CodeGroup>
  1025. </Col>
  1026. </Row>
  1027. <table className="max-w-auto border-collapse border border-slate-400" style={{ maxWidth: 'none', width: 'auto' }}>
  1028. <thead style={{ background: '#f9fafc' }}>
  1029. <tr>
  1030. <th className="p-2 border border-slate-300">code</th>
  1031. <th className="p-2 border border-slate-300">status</th>
  1032. <th className="p-2 border border-slate-300">message</th>
  1033. </tr>
  1034. </thead>
  1035. <tbody>
  1036. <tr>
  1037. <td className="p-2 border border-slate-300">no_file_uploaded</td>
  1038. <td className="p-2 border border-slate-300">400</td>
  1039. <td className="p-2 border border-slate-300">Please upload your file.</td>
  1040. </tr>
  1041. <tr>
  1042. <td className="p-2 border border-slate-300">too_many_files</td>
  1043. <td className="p-2 border border-slate-300">400</td>
  1044. <td className="p-2 border border-slate-300">Only one file is allowed.</td>
  1045. </tr>
  1046. <tr>
  1047. <td className="p-2 border border-slate-300">file_too_large</td>
  1048. <td className="p-2 border border-slate-300">413</td>
  1049. <td className="p-2 border border-slate-300">File size exceeded.</td>
  1050. </tr>
  1051. <tr>
  1052. <td className="p-2 border border-slate-300">unsupported_file_type</td>
  1053. <td className="p-2 border border-slate-300">415</td>
  1054. <td className="p-2 border border-slate-300">File type not allowed.</td>
  1055. </tr>
  1056. <tr>
  1057. <td className="p-2 border border-slate-300">high_quality_dataset_only</td>
  1058. <td className="p-2 border border-slate-300">400</td>
  1059. <td className="p-2 border border-slate-300">Current operation only supports 'high-quality' datasets.</td>
  1060. </tr>
  1061. <tr>
  1062. <td className="p-2 border border-slate-300">dataset_not_initialized</td>
  1063. <td className="p-2 border border-slate-300">400</td>
  1064. <td className="p-2 border border-slate-300">The dataset is still being initialized or indexing. Please wait a moment.</td>
  1065. </tr>
  1066. <tr>
  1067. <td className="p-2 border border-slate-300">archived_document_immutable</td>
  1068. <td className="p-2 border border-slate-300">403</td>
  1069. <td className="p-2 border border-slate-300">The archived document is not editable.</td>
  1070. </tr>
  1071. <tr>
  1072. <td className="p-2 border border-slate-300">dataset_name_duplicate</td>
  1073. <td className="p-2 border border-slate-300">409</td>
  1074. <td className="p-2 border border-slate-300">The dataset name already exists. Please modify your dataset name.</td>
  1075. </tr>
  1076. <tr>
  1077. <td className="p-2 border border-slate-300">invalid_action</td>
  1078. <td className="p-2 border border-slate-300">400</td>
  1079. <td className="p-2 border border-slate-300">Invalid action.</td>
  1080. </tr>
  1081. <tr>
  1082. <td className="p-2 border border-slate-300">document_already_finished</td>
  1083. <td className="p-2 border border-slate-300">400</td>
  1084. <td className="p-2 border border-slate-300">The document has been processed. Please refresh the page or go to the document details.</td>
  1085. </tr>
  1086. <tr>
  1087. <td className="p-2 border border-slate-300">document_indexing</td>
  1088. <td className="p-2 border border-slate-300">400</td>
  1089. <td className="p-2 border border-slate-300">The document is being processed and cannot be edited.</td>
  1090. </tr>
  1091. <tr>
  1092. <td className="p-2 border border-slate-300">invalid_metadata</td>
  1093. <td className="p-2 border border-slate-300">400</td>
  1094. <td className="p-2 border border-slate-300">The metadata content is incorrect. Please check and verify.</td>
  1095. </tr>
  1096. </tbody>
  1097. </table>
  1098. <div className="pb-4" />