template.zh.mdx 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708
  1. import { CodeGroup } from '@/app/components/develop/code.tsx'
  2. import { Row, Col, Properties, Property, Heading, SubProperty, PropertyInstruction, 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. <hr className='ml-0 mr-0' />
  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='doc_form' type='string' key='doc_form'>
  45. 索引内容的形式
  46. - <code>text_model</code> text 文档直接 embedding,经济模式默认为该模式
  47. - <code>hierarchical_model</code> parent-child 模式
  48. - <code>qa_model</code> Q&A 模式:为分片文档生成 Q&A 对,然后对问题进行 embedding
  49. </Property>
  50. <Property name='doc_language' type='string' key='doc_language'>
  51. 在 Q&A 模式下,指定文档的语言,例如:<code>English</code>、<code>Chinese</code>
  52. </Property>
  53. <Property name='process_rule' type='object' key='process_rule'>
  54. 处理规则
  55. - <code>mode</code> (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
  56. - <code>rules</code> (object) 自定义规则(自动模式下,该字段为空)
  57. - <code>pre_processing_rules</code> (array[object]) 预处理规则
  58. - <code>id</code> (string) 预处理规则的唯一标识符
  59. - 枚举:
  60. - <code>remove_extra_spaces</code> 替换连续空格、换行符、制表符
  61. - <code>remove_urls_emails</code> 删除 URL、电子邮件地址
  62. - <code>enabled</code> (bool) 是否选中该规则,不传入文档 ID 时代表默认值
  63. - <code>segmentation</code> (object) 分段规则
  64. - <code>separator</code> 自定义分段标识符,目前仅允许设置一个分隔符。默认为 <code>\n</code>
  65. - <code>max_tokens</code> 最大长度(token)默认为 1000
  66. - <code>parent_mode</code> 父分段的召回模式 <code>full-doc</code> 全文召回 / <code>paragraph</code> 段落召回
  67. - <code>subchunk_segmentation</code> (object) 子分段规则
  68. - <code>separator</code> 分段标识符,目前仅允许设置一个分隔符。默认为 <code>***</code>
  69. - <code>max_tokens</code> 最大长度 (token) 需要校验小于父级的长度
  70. - <code>chunk_overlap</code> 分段重叠指的是在对数据进行分段时,段与段之间存在一定的重叠部分(选填)
  71. </Property>
  72. <PropertyInstruction>当知识库未设置任何参数的时候,首次上传需要提供以下参数,未提供则使用默认选项:</PropertyInstruction>
  73. <Property name='retrieval_model' type='object' key='retrieval_model'>
  74. 检索模式
  75. - <code>search_method</code> (string) 检索方法
  76. - <code>hybrid_search</code> 混合检索
  77. - <code>semantic_search</code> 语义检索
  78. - <code>full_text_search</code> 全文检索
  79. - <code>reranking_enable</code> (bool) 是否开启rerank
  80. - <code>reranking_model</code> (object) Rerank 模型配置
  81. - <code>reranking_provider_name</code> (string) Rerank 模型的提供商
  82. - <code>reranking_model_name</code> (string) Rerank 模型的名称
  83. - <code>top_k</code> (int) 召回条数
  84. - <code>score_threshold_enabled</code> (bool)是否开启召回分数限制
  85. - <code>score_threshold</code> (float) 召回分数限制
  86. </Property>
  87. <Property name='embedding_model' type='string' key='embedding_model'>
  88. Embedding 模型名称
  89. </Property>
  90. <Property name='embedding_model_provider' type='string' key='embedding_model_provider'>
  91. Embedding 模型供应商
  92. </Property>
  93. </Properties>
  94. </Col>
  95. <Col sticky>
  96. <CodeGroup
  97. title="Request"
  98. tag="POST"
  99. label="/datasets/{dataset_id}/document/create-by-text"
  100. 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"}}'`}
  101. >
  102. ```bash {{ title: 'cURL' }}
  103. curl --location --request --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/document/create-by-text' \
  104. --header 'Authorization: Bearer {api_key}' \
  105. --header 'Content-Type: application/json' \
  106. --data-raw '{
  107. "name": "text",
  108. "text": "text",
  109. "indexing_technique": "high_quality",
  110. "process_rule": {
  111. "mode": "automatic"
  112. }
  113. }'
  114. ```
  115. </CodeGroup>
  116. <CodeGroup title="Response">
  117. ```json {{ title: 'Response' }}
  118. {
  119. "document": {
  120. "id": "",
  121. "position": 1,
  122. "data_source_type": "upload_file",
  123. "data_source_info": {
  124. "upload_file_id": ""
  125. },
  126. "dataset_process_rule_id": "",
  127. "name": "text.txt",
  128. "created_from": "api",
  129. "created_by": "",
  130. "created_at": 1695690280,
  131. "tokens": 0,
  132. "indexing_status": "waiting",
  133. "error": null,
  134. "enabled": true,
  135. "disabled_at": null,
  136. "disabled_by": null,
  137. "archived": false,
  138. "display_status": "queuing",
  139. "word_count": 0,
  140. "hit_count": 0,
  141. "doc_form": "text_model"
  142. },
  143. "batch": ""
  144. }
  145. ```
  146. </CodeGroup>
  147. </Col>
  148. </Row>
  149. <hr className='ml-0 mr-0' />
  150. <Heading
  151. url='/datasets/{dataset_id}/document/create-by-file'
  152. method='POST'
  153. title='通过文件创建文档 '
  154. name='#create-by-file'
  155. />
  156. <Row>
  157. <Col>
  158. 此接口基于已存在知识库,在此知识库的基础上通过文件创建新的文档
  159. ### Path
  160. <Properties>
  161. <Property name='dataset_id' type='string' key='dataset_id'>
  162. 知识库 ID
  163. </Property>
  164. </Properties>
  165. ### Request Body
  166. <Properties>
  167. <Property name='data' type='multipart/form-data json string' key='data'>
  168. - <code>original_document_id</code> 源文档 ID(选填)
  169. - 用于重新上传文档或修改文档清洗、分段配置,缺失的信息从源文档复制
  170. - 源文档不可为归档的文档
  171. - 当传入 <code>original_document_id</code> 时,代表文档进行更新操作,<code>process_rule</code> 为可填项目,不填默认使用源文档的分段方式
  172. - 未传入 <code>original_document_id</code> 时,代表文档进行新增操作,<code>process_rule</code> 为必填
  173. - <code>indexing_technique</code> 索引方式
  174. - <code>high_quality</code> 高质量:使用 embedding 模型进行嵌入,构建为向量数据库索引
  175. - <code>economy</code> 经济:使用 keyword table index 的倒排索引进行构建
  176. - <code>doc_form</code> 索引内容的形式
  177. - <code>text_model</code> text 文档直接 embedding,经济模式默认为该模式
  178. - <code>hierarchical_model</code> parent-child 模式
  179. - <code>qa_model</code> Q&A 模式:为分片文档生成 Q&A 对,然后对问题进行 embedding
  180. - <code>doc_language</code> 在 Q&A 模式下,指定文档的语言,例如:<code>English</code>、<code>Chinese</code>
  181. - <code>process_rule</code> 处理规则
  182. - <code>mode</code> (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
  183. - <code>rules</code> (object) 自定义规则(自动模式下,该字段为空)
  184. - <code>pre_processing_rules</code> (array[object]) 预处理规则
  185. - <code>id</code> (string) 预处理规则的唯一标识符
  186. - 枚举:
  187. - <code>remove_extra_spaces</code> 替换连续空格、换行符、制表符
  188. - <code>remove_urls_emails</code> 删除 URL、电子邮件地址
  189. - <code>enabled</code> (bool) 是否选中该规则,不传入文档 ID 时代表默认值
  190. - <code>segmentation</code> (object) 分段规则
  191. - <code>separator</code> 自定义分段标识符,目前仅允许设置一个分隔符。默认为 \n
  192. - <code>max_tokens</code> 最大长度(token)默认为 1000
  193. - <code>parent_mode</code> 父分段的召回模式 <code>full-doc</code> 全文召回 / <code>paragraph</code> 段落召回
  194. - <code>subchunk_segmentation</code> (object) 子分段规则
  195. - <code>separator</code> 分段标识符,目前仅允许设置一个分隔符。默认为 <code>***</code>
  196. - <code>max_tokens</code> 最大长度 (token) 需要校验小于父级的长度
  197. - <code>chunk_overlap</code> 分段重叠指的是在对数据进行分段时,段与段之间存在一定的重叠部分(选填)
  198. </Property>
  199. <Property name='file' type='multipart/form-data' key='file'>
  200. 需要上传的文件。
  201. </Property>
  202. <PropertyInstruction>当知识库未设置任何参数的时候,首次上传需要提供以下参数,未提供则使用默认选项:</PropertyInstruction>
  203. <Property name='retrieval_model' type='object' key='retrieval_model'>
  204. 检索模式
  205. - <code>search_method</code> (string) 检索方法
  206. - <code>hybrid_search</code> 混合检索
  207. - <code>semantic_search</code> 语义检索
  208. - <code>full_text_search</code> 全文检索
  209. - <code>reranking_enable</code> (bool) 是否开启rerank
  210. - <code>reranking_model</code> (object) Rerank 模型配置
  211. - <code>reranking_provider_name</code> (string) Rerank 模型的提供商
  212. - <code>reranking_model_name</code> (string) Rerank 模型的名称
  213. - <code>top_k</code> (int) 召回条数
  214. - <code>score_threshold_enabled</code> (bool)是否开启召回分数限制
  215. - <code>score_threshold</code> (float) 召回分数限制
  216. </Property>
  217. <Property name='embedding_model' type='string' key='embedding_model'>
  218. Embedding 模型名称
  219. </Property>
  220. <Property name='embedding_model_provider' type='string' key='embedding_model_provider'>
  221. Embedding 模型供应商
  222. </Property>
  223. </Properties>
  224. </Col>
  225. <Col sticky>
  226. <CodeGroup
  227. title="Request"
  228. tag="POST"
  229. label="/datasets/{dataset_id}/document/create-by-file"
  230. 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"'`}
  231. >
  232. ```bash {{ title: 'cURL' }}
  233. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/document/create-by-file' \
  234. --header 'Authorization: Bearer {api_key}' \
  235. --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' \
  236. --form 'file=@"/path/to/file"'
  237. ```
  238. </CodeGroup>
  239. <CodeGroup title="Response">
  240. ```json {{ title: 'Response' }}
  241. {
  242. "document": {
  243. "id": "",
  244. "position": 1,
  245. "data_source_type": "upload_file",
  246. "data_source_info": {
  247. "upload_file_id": ""
  248. },
  249. "dataset_process_rule_id": "",
  250. "name": "Dify.txt",
  251. "created_from": "api",
  252. "created_by": "",
  253. "created_at": 1695308667,
  254. "tokens": 0,
  255. "indexing_status": "waiting",
  256. "error": null,
  257. "enabled": true,
  258. "disabled_at": null,
  259. "disabled_by": null,
  260. "archived": false,
  261. "display_status": "queuing",
  262. "word_count": 0,
  263. "hit_count": 0,
  264. "doc_form": "text_model"
  265. },
  266. "batch": ""
  267. }
  268. ```
  269. </CodeGroup>
  270. </Col>
  271. </Row>
  272. <hr className='ml-0 mr-0' />
  273. <Heading
  274. url='/datasets'
  275. method='POST'
  276. title='创建空知识库'
  277. name='#create_empty_dataset'
  278. />
  279. <Row>
  280. <Col>
  281. ### Request Body
  282. <Properties>
  283. <Property name='name' type='string' key='name'>
  284. 知识库名称(必填)
  285. </Property>
  286. <Property name='description' type='string' key='description'>
  287. 知识库描述(选填)
  288. </Property>
  289. <Property name='indexing_technique' type='string' key='indexing_technique'>
  290. 索引模式(选填,建议填写)
  291. - <code>high_quality</code> 高质量
  292. - <code>economy</code> 经济
  293. </Property>
  294. <Property name='permission' type='string' key='permission'>
  295. 权限(选填,默认 only_me)
  296. - <code>only_me</code> 仅自己
  297. - <code>all_team_members</code> 所有团队成员
  298. - <code>partial_members</code> 部分团队成员
  299. </Property>
  300. <Property name='provider' type='string' key='provider'>
  301. Provider(选填,默认 vendor)
  302. - <code>vendor</code> 上传文件
  303. - <code>external</code> 外部知识库
  304. </Property>
  305. <Property name='external_knowledge_api_id' type='str' key='external_knowledge_api_id'>
  306. 外部知识库 API_ID(选填)
  307. </Property>
  308. <Property name='external_knowledge_id' type='str' key='external_knowledge_id'>
  309. 外部知识库 ID(选填)
  310. </Property>
  311. </Properties>
  312. </Col>
  313. <Col sticky>
  314. <CodeGroup
  315. title="Request"
  316. tag="POST"
  317. label="/datasets"
  318. 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", "permission": "only_me"}'`}
  319. >
  320. ```bash {{ title: 'cURL' }}
  321. curl --location --request POST '${props.apiBaseUrl}/datasets' \
  322. --header 'Authorization: Bearer {api_key}' \
  323. --header 'Content-Type: application/json' \
  324. --data-raw '{
  325. "name": "name",
  326. "permission": "only_me"
  327. }'
  328. ```
  329. </CodeGroup>
  330. <CodeGroup title="Response">
  331. ```json {{ title: 'Response' }}
  332. {
  333. "id": "",
  334. "name": "name",
  335. "description": null,
  336. "provider": "vendor",
  337. "permission": "only_me",
  338. "data_source_type": null,
  339. "indexing_technique": null,
  340. "app_count": 0,
  341. "document_count": 0,
  342. "word_count": 0,
  343. "created_by": "",
  344. "created_at": 1695636173,
  345. "updated_by": "",
  346. "updated_at": 1695636173,
  347. "embedding_model": null,
  348. "embedding_model_provider": null,
  349. "embedding_available": null
  350. }
  351. ```
  352. </CodeGroup>
  353. </Col>
  354. </Row>
  355. <hr className='ml-0 mr-0' />
  356. <Heading
  357. url='/datasets'
  358. method='GET'
  359. title='知识库列表'
  360. name='#dataset_list'
  361. />
  362. <Row>
  363. <Col>
  364. ### Query
  365. <Properties>
  366. <Property name='page' type='string' key='page'>
  367. 页码
  368. </Property>
  369. <Property name='limit' type='string' key='limit'>
  370. 返回条数,默认 20,范围 1-100
  371. </Property>
  372. </Properties>
  373. </Col>
  374. <Col sticky>
  375. <CodeGroup
  376. title="Request"
  377. tag="GET"
  378. label="/datasets"
  379. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets?page=1&limit=20' \\\n--header 'Authorization: Bearer {api_key}'`}
  380. >
  381. ```bash {{ title: 'cURL' }}
  382. curl --location --request GET '${props.apiBaseUrl}/datasets?page=1&limit=20' \
  383. --header 'Authorization: Bearer {api_key}'
  384. ```
  385. </CodeGroup>
  386. <CodeGroup title="Response">
  387. ```json {{ title: 'Response' }}
  388. {
  389. "data": [
  390. {
  391. "id": "",
  392. "name": "知识库名称",
  393. "description": "描述信息",
  394. "permission": "only_me",
  395. "data_source_type": "upload_file",
  396. "indexing_technique": "",
  397. "app_count": 2,
  398. "document_count": 10,
  399. "word_count": 1200,
  400. "created_by": "",
  401. "created_at": "",
  402. "updated_by": "",
  403. "updated_at": ""
  404. },
  405. ...
  406. ],
  407. "has_more": true,
  408. "limit": 20,
  409. "total": 50,
  410. "page": 1
  411. }
  412. ```
  413. </CodeGroup>
  414. </Col>
  415. </Row>
  416. <hr className='ml-0 mr-0' />
  417. <Heading
  418. url='/datasets/{dataset_id}'
  419. method='DELETE'
  420. title='删除知识库'
  421. name='#delete_dataset'
  422. />
  423. <Row>
  424. <Col>
  425. ### Path
  426. <Properties>
  427. <Property name='dataset_id' type='string' key='dataset_id'>
  428. 知识库 ID
  429. </Property>
  430. </Properties>
  431. </Col>
  432. <Col sticky>
  433. <CodeGroup
  434. title="Request"
  435. tag="DELETE"
  436. label="/datasets/{dataset_id}"
  437. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  438. >
  439. ```bash {{ title: 'cURL' }}
  440. curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}' \
  441. --header 'Authorization: Bearer {api_key}'
  442. ```
  443. </CodeGroup>
  444. <CodeGroup title="Response">
  445. ```text {{ title: 'Response' }}
  446. 204 No Content
  447. ```
  448. </CodeGroup>
  449. </Col>
  450. </Row>
  451. <hr className='ml-0 mr-0' />
  452. <Heading
  453. url='/datasets/{dataset_id}/documents/{document_id}/update-by-text'
  454. method='POST'
  455. title='通过文本更新文档'
  456. name='#update-by-text'
  457. />
  458. <Row>
  459. <Col>
  460. 此接口基于已存在知识库,在此知识库的基础上通过文本更新文档
  461. ### Path
  462. <Properties>
  463. <Property name='dataset_id' type='string' key='dataset_id'>
  464. 知识库 ID
  465. </Property>
  466. <Property name='document_id' type='string' key='document_id'>
  467. 文档 ID
  468. </Property>
  469. </Properties>
  470. ### Request Body
  471. <Properties>
  472. <Property name='name' type='string' key='name'>
  473. 文档名称(选填)
  474. </Property>
  475. <Property name='text' type='string' key='text'>
  476. 文档内容(选填)
  477. </Property>
  478. <Property name='process_rule' type='object' key='process_rule'>
  479. 处理规则(选填)
  480. - <code>mode</code> (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
  481. - <code>rules</code> (object) 自定义规则(自动模式下,该字段为空)
  482. - <code>pre_processing_rules</code> (array[object]) 预处理规则
  483. - <code>id</code> (string) 预处理规则的唯一标识符
  484. - 枚举:
  485. - <code>remove_extra_spaces</code> 替换连续空格、换行符、制表符
  486. - <code>remove_urls_emails</code> 删除 URL、电子邮件地址
  487. - <code>enabled</code> (bool) 是否选中该规则,不传入文档 ID 时代表默认值
  488. - <code>segmentation</code> (object) 分段规则
  489. - <code>separator</code> 自定义分段标识符,目前仅允许设置一个分隔符。默认为 \n
  490. - <code>max_tokens</code> 最大长度(token)默认为 1000
  491. - <code>parent_mode</code> 父分段的召回模式 <code>full-doc</code> 全文召回 / <code>paragraph</code> 段落召回
  492. - <code>subchunk_segmentation</code> (object) 子分段规则
  493. - <code>separator</code> 分段标识符,目前仅允许设置一个分隔符。默认为 <code>***</code>
  494. - <code>max_tokens</code> 最大长度 (token) 需要校验小于父级的长度
  495. - <code>chunk_overlap</code> 分段重叠指的是在对数据进行分段时,段与段之间存在一定的重叠部分(选填)
  496. </Property>
  497. </Properties>
  498. </Col>
  499. <Col sticky>
  500. <CodeGroup
  501. title="Request"
  502. tag="POST"
  503. label="/datasets/{dataset_id}/documents/{document_id}/update-by-text"
  504. 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"}'`}
  505. >
  506. ```bash {{ title: 'cURL' }}
  507. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/update-by-text' \
  508. --header 'Authorization: Bearer {api_key}' \
  509. --header 'Content-Type: application/json' \
  510. --data-raw '{
  511. "name": "name",
  512. "text": "text"
  513. }'
  514. ```
  515. </CodeGroup>
  516. <CodeGroup title="Response">
  517. ```json {{ title: 'Response' }}
  518. {
  519. "document": {
  520. "id": "",
  521. "position": 1,
  522. "data_source_type": "upload_file",
  523. "data_source_info": {
  524. "upload_file_id": ""
  525. },
  526. "dataset_process_rule_id": "",
  527. "name": "name.txt",
  528. "created_from": "api",
  529. "created_by": "",
  530. "created_at": 1695308667,
  531. "tokens": 0,
  532. "indexing_status": "waiting",
  533. "error": null,
  534. "enabled": true,
  535. "disabled_at": null,
  536. "disabled_by": null,
  537. "archived": false,
  538. "display_status": "queuing",
  539. "word_count": 0,
  540. "hit_count": 0,
  541. "doc_form": "text_model"
  542. },
  543. "batch": ""
  544. }
  545. ```
  546. </CodeGroup>
  547. </Col>
  548. </Row>
  549. <hr className='ml-0 mr-0' />
  550. <Heading
  551. url='/datasets/{dataset_id}/documents/{document_id}/update-by-file'
  552. method='POST'
  553. title='通过文件更新文档'
  554. name='#update-by-file'
  555. />
  556. <Row>
  557. <Col>
  558. 此接口基于已存在知识库,在此知识库的基础上通过文件更新文档的操作。
  559. ### Path
  560. <Properties>
  561. <Property name='dataset_id' type='string' key='dataset_id'>
  562. 知识库 ID
  563. </Property>
  564. <Property name='document_id' type='string' key='document_id'>
  565. 文档 ID
  566. </Property>
  567. </Properties>
  568. ### Request Body
  569. <Properties>
  570. <Property name='name' type='string' key='name'>
  571. 文档名称(选填)
  572. </Property>
  573. <Property name='file' type='multipart/form-data' key='file'>
  574. 需要上传的文件
  575. </Property>
  576. <Property name='process_rule' type='object' key='process_rule'>
  577. 处理规则(选填)
  578. - <code>mode</code> (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
  579. - <code>rules</code> (object) 自定义规则(自动模式下,该字段为空)
  580. - <code>pre_processing_rules</code> (array[object]) 预处理规则
  581. - <code>id</code> (string) 预处理规则的唯一标识符
  582. - 枚举:
  583. - <code>remove_extra_spaces</code> 替换连续空格、换行符、制表符
  584. - <code>remove_urls_emails</code> 删除 URL、电子邮件地址
  585. - <code>enabled</code> (bool) 是否选中该规则,不传入文档 ID 时代表默认值
  586. - <code>segmentation</code> (object) 分段规则
  587. - <code>separator</code> 自定义分段标识符,目前仅允许设置一个分隔符。默认为 \n
  588. - <code>max_tokens</code> 最大长度(token)默认为 1000
  589. - <code>parent_mode</code> 父分段的召回模式 <code>full-doc</code> 全文召回 / <code>paragraph</code> 段落召回
  590. - <code>subchunk_segmentation</code> (object) 子分段规则
  591. - <code>separator</code> 分段标识符,目前仅允许设置一个分隔符。默认为 <code>***</code>
  592. - <code>max_tokens</code> 最大长度 (token) 需要校验小于父级的长度
  593. - <code>chunk_overlap</code> 分段重叠指的是在对数据进行分段时,段与段之间存在一定的重叠部分(选填)
  594. </Property>
  595. </Properties>
  596. </Col>
  597. <Col sticky>
  598. <CodeGroup
  599. title="Request"
  600. tag="POST"
  601. label="/datasets/{dataset_id}/documents/{document_id}/update-by-file"
  602. 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"'`}
  603. >
  604. ```bash {{ title: 'cURL' }}
  605. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/update-by-file' \
  606. --header 'Authorization: Bearer {api_key}' \
  607. --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' \
  608. --form 'file=@"/path/to/file"'
  609. ```
  610. </CodeGroup>
  611. <CodeGroup title="Response">
  612. ```json {{ title: 'Response' }}
  613. {
  614. "document": {
  615. "id": "",
  616. "position": 1,
  617. "data_source_type": "upload_file",
  618. "data_source_info": {
  619. "upload_file_id": ""
  620. },
  621. "dataset_process_rule_id": "",
  622. "name": "Dify.txt",
  623. "created_from": "api",
  624. "created_by": "",
  625. "created_at": 1695308667,
  626. "tokens": 0,
  627. "indexing_status": "waiting",
  628. "error": null,
  629. "enabled": true,
  630. "disabled_at": null,
  631. "disabled_by": null,
  632. "archived": false,
  633. "display_status": "queuing",
  634. "word_count": 0,
  635. "hit_count": 0,
  636. "doc_form": "text_model"
  637. },
  638. "batch": "20230921150427533684"
  639. }
  640. ```
  641. </CodeGroup>
  642. </Col>
  643. </Row>
  644. <hr className='ml-0 mr-0' />
  645. <Heading
  646. url='/datasets/{dataset_id}/documents/{batch}/indexing-status'
  647. method='GET'
  648. title='获取文档嵌入状态(进度)'
  649. name='#indexing_status'
  650. />
  651. <Row>
  652. <Col>
  653. ### Path
  654. <Properties>
  655. <Property name='dataset_id' type='string' key='dataset_id'>
  656. 知识库 ID
  657. </Property>
  658. <Property name='batch' type='string' key='batch'>
  659. 上传文档的批次号
  660. </Property>
  661. </Properties>
  662. </Col>
  663. <Col sticky>
  664. <CodeGroup
  665. title="Request"
  666. tag="GET"
  667. label="/datasets/{dataset_id}/documents/{batch}/indexing-status"
  668. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{batch}/indexing-status' \\\n--header 'Authorization: Bearer {api_key}'`}
  669. >
  670. ```bash {{ title: 'cURL' }}
  671. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{batch}/indexing-status' \
  672. --header 'Authorization: Bearer {api_key}' \
  673. ```
  674. </CodeGroup>
  675. <CodeGroup title="Response">
  676. ```json {{ title: 'Response' }}
  677. {
  678. "data":[{
  679. "id": "",
  680. "indexing_status": "indexing",
  681. "processing_started_at": 1681623462.0,
  682. "parsing_completed_at": 1681623462.0,
  683. "cleaning_completed_at": 1681623462.0,
  684. "splitting_completed_at": 1681623462.0,
  685. "completed_at": null,
  686. "paused_at": null,
  687. "error": null,
  688. "stopped_at": null,
  689. "completed_segments": 24,
  690. "total_segments": 100
  691. }]
  692. }
  693. ```
  694. </CodeGroup>
  695. </Col>
  696. </Row>
  697. <hr className='ml-0 mr-0' />
  698. <Heading
  699. url='/datasets/{dataset_id}/documents/{document_id}'
  700. method='DELETE'
  701. title='删除文档'
  702. name='#delete_document'
  703. />
  704. <Row>
  705. <Col>
  706. ### Path
  707. <Properties>
  708. <Property name='dataset_id' type='string' key='dataset_id'>
  709. 知识库 ID
  710. </Property>
  711. <Property name='document_id' type='string' key='document_id'>
  712. 文档 ID
  713. </Property>
  714. </Properties>
  715. </Col>
  716. <Col sticky>
  717. <CodeGroup
  718. title="Request"
  719. tag="DELETE"
  720. label="/datasets/{dataset_id}/documents/{document_id}"
  721. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  722. >
  723. ```bash {{ title: 'cURL' }}
  724. curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}' \
  725. --header 'Authorization: Bearer {api_key}' \
  726. ```
  727. </CodeGroup>
  728. <CodeGroup title="Response">
  729. ```json {{ title: 'Response' }}
  730. {
  731. "result": "success"
  732. }
  733. ```
  734. </CodeGroup>
  735. </Col>
  736. </Row>
  737. <hr className='ml-0 mr-0' />
  738. <Heading
  739. url='/datasets/{dataset_id}/documents'
  740. method='GET'
  741. title='知识库文档列表'
  742. name='#dataset_document_list'
  743. />
  744. <Row>
  745. <Col>
  746. ### Path
  747. <Properties>
  748. <Property name='dataset_id' type='string' key='dataset_id'>
  749. 知识库 ID
  750. </Property>
  751. </Properties>
  752. ### Query
  753. <Properties>
  754. <Property name='keyword' type='string' key='keyword'>
  755. 搜索关键词,可选,目前仅搜索文档名称
  756. </Property>
  757. <Property name='page' type='string' key='page'>
  758. 页码,可选
  759. </Property>
  760. <Property name='limit' type='string' key='limit'>
  761. 返回条数,可选,默认 20,范围 1-100
  762. </Property>
  763. </Properties>
  764. </Col>
  765. <Col sticky>
  766. <CodeGroup
  767. title="Request"
  768. tag="GET"
  769. label="/datasets/{dataset_id}/documents"
  770. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents' \\\n--header 'Authorization: Bearer {api_key}'`}
  771. >
  772. ```bash {{ title: 'cURL' }}
  773. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents' \
  774. --header 'Authorization: Bearer {api_key}' \
  775. ```
  776. </CodeGroup>
  777. <CodeGroup title="Response">
  778. ```json {{ title: 'Response' }}
  779. {
  780. "data": [
  781. {
  782. "id": "",
  783. "position": 1,
  784. "data_source_type": "file_upload",
  785. "data_source_info": null,
  786. "dataset_process_rule_id": null,
  787. "name": "dify",
  788. "created_from": "",
  789. "created_by": "",
  790. "created_at": 1681623639,
  791. "tokens": 0,
  792. "indexing_status": "waiting",
  793. "error": null,
  794. "enabled": true,
  795. "disabled_at": null,
  796. "disabled_by": null,
  797. "archived": false
  798. },
  799. ],
  800. "has_more": false,
  801. "limit": 20,
  802. "total": 9,
  803. "page": 1
  804. }
  805. ```
  806. </CodeGroup>
  807. </Col>
  808. </Row>
  809. <hr className='ml-0 mr-0' />
  810. <Heading
  811. url='/datasets/{dataset_id}/documents/{document_id}/segments'
  812. method='POST'
  813. title='新增分段'
  814. name='#create_new_segment'
  815. />
  816. <Row>
  817. <Col>
  818. ### Path
  819. <Properties>
  820. <Property name='dataset_id' type='string' key='dataset_id'>
  821. 知识库 ID
  822. </Property>
  823. <Property name='document_id' type='string' key='document_id'>
  824. 文档 ID
  825. </Property>
  826. </Properties>
  827. ### Request Body
  828. <Properties>
  829. <Property name='segments' type='object list' key='segments'>
  830. - <code>content</code> (text) 文本内容/问题内容,必填
  831. - <code>answer</code> (text) 答案内容,非必填,如果知识库的模式为 Q&A 模式则传值
  832. - <code>keywords</code> (list) 关键字,非必填
  833. </Property>
  834. </Properties>
  835. </Col>
  836. <Col sticky>
  837. <CodeGroup
  838. title="Request"
  839. tag="POST"
  840. label="/datasets/{dataset_id}/documents/{document_id}/segments"
  841. 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"]}]}'`}
  842. >
  843. ```bash {{ title: 'cURL' }}
  844. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments' \
  845. --header 'Authorization: Bearer {api_key}' \
  846. --header 'Content-Type: application/json' \
  847. --data-raw '{
  848. "segments": [
  849. {
  850. "content": "1",
  851. "answer": "1",
  852. "keywords": ["a"]
  853. }
  854. ]
  855. }'
  856. ```
  857. </CodeGroup>
  858. <CodeGroup title="Response">
  859. ```json {{ title: 'Response' }}
  860. {
  861. "data": [{
  862. "id": "",
  863. "position": 1,
  864. "document_id": "",
  865. "content": "1",
  866. "answer": "1",
  867. "word_count": 25,
  868. "tokens": 0,
  869. "keywords": [
  870. "a"
  871. ],
  872. "index_node_id": "",
  873. "index_node_hash": "",
  874. "hit_count": 0,
  875. "enabled": true,
  876. "disabled_at": null,
  877. "disabled_by": null,
  878. "status": "completed",
  879. "created_by": "",
  880. "created_at": 1695312007,
  881. "indexing_at": 1695312007,
  882. "completed_at": 1695312007,
  883. "error": null,
  884. "stopped_at": null
  885. }],
  886. "doc_form": "text_model"
  887. }
  888. ```
  889. </CodeGroup>
  890. </Col>
  891. </Row>
  892. <hr className='ml-0 mr-0' />
  893. <Heading
  894. url='/datasets/{dataset_id}/documents/{document_id}/segments'
  895. method='GET'
  896. title='查询文档分段'
  897. name='#get_segment'
  898. />
  899. <Row>
  900. <Col>
  901. ### Path
  902. <Properties>
  903. <Property name='dataset_id' type='string' key='dataset_id'>
  904. 知识库 ID
  905. </Property>
  906. <Property name='document_id' type='string' key='document_id'>
  907. 文档 ID
  908. </Property>
  909. </Properties>
  910. ### Query
  911. <Properties>
  912. <Property name='keyword' type='string' key='keyword'>
  913. 搜索关键词,可选
  914. </Property>
  915. <Property name='status' type='string' key='status'>
  916. 搜索状态,completed
  917. </Property>
  918. <Property name='page' type='string' key='page'>
  919. 页码,可选
  920. </Property>
  921. <Property name='limit' type='string' key='limit'>
  922. 返回条数,可选,默认 20,范围 1-100
  923. </Property>
  924. </Properties>
  925. </Col>
  926. <Col sticky>
  927. <CodeGroup
  928. title="Request"
  929. tag="GET"
  930. label="/datasets/{dataset_id}/documents/{document_id}/segments"
  931. 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'`}
  932. >
  933. ```bash {{ title: 'cURL' }}
  934. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments' \
  935. --header 'Authorization: Bearer {api_key}' \
  936. --header 'Content-Type: application/json'
  937. ```
  938. </CodeGroup>
  939. <CodeGroup title="Response">
  940. ```json {{ title: 'Response' }}
  941. {
  942. "data": [{
  943. "id": "",
  944. "position": 1,
  945. "document_id": "",
  946. "content": "1",
  947. "answer": "1",
  948. "word_count": 25,
  949. "tokens": 0,
  950. "keywords": [
  951. "a"
  952. ],
  953. "index_node_id": "",
  954. "index_node_hash": "",
  955. "hit_count": 0,
  956. "enabled": true,
  957. "disabled_at": null,
  958. "disabled_by": null,
  959. "status": "completed",
  960. "created_by": "",
  961. "created_at": 1695312007,
  962. "indexing_at": 1695312007,
  963. "completed_at": 1695312007,
  964. "error": null,
  965. "stopped_at": null
  966. }],
  967. "doc_form": "text_model",
  968. "has_more": false,
  969. "limit": 20,
  970. "total": 9,
  971. "page": 1
  972. }
  973. ```
  974. </CodeGroup>
  975. </Col>
  976. </Row>
  977. <hr className='ml-0 mr-0' />
  978. <Heading
  979. url='/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}'
  980. method='DELETE'
  981. title='删除文档分段'
  982. name='#delete_segment'
  983. />
  984. <Row>
  985. <Col>
  986. ### Path
  987. <Properties>
  988. <Property name='dataset_id' type='string' key='dataset_id'>
  989. 知识库 ID
  990. </Property>
  991. <Property name='document_id' type='string' key='document_id'>
  992. 文档 ID
  993. </Property>
  994. <Property name='segment_id' type='string' key='segment_id'>
  995. 文档分段ID
  996. </Property>
  997. </Properties>
  998. </Col>
  999. <Col sticky>
  1000. <CodeGroup
  1001. title="Request"
  1002. tag="DELETE"
  1003. label="/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}"
  1004. 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'`}
  1005. >
  1006. ```bash {{ title: 'cURL' }}
  1007. curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}' \
  1008. --header 'Authorization: Bearer {api_key}' \
  1009. --header 'Content-Type: application/json'
  1010. ```
  1011. </CodeGroup>
  1012. <CodeGroup title="Response">
  1013. ```json {{ title: 'Response' }}
  1014. {
  1015. "result": "success"
  1016. }
  1017. ```
  1018. </CodeGroup>
  1019. </Col>
  1020. </Row>
  1021. <hr className='ml-0 mr-0' />
  1022. <Heading
  1023. url='/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}'
  1024. method='POST'
  1025. title='更新文档分段'
  1026. name='#update_segment'
  1027. />
  1028. <Row>
  1029. <Col>
  1030. ### POST
  1031. <Properties>
  1032. <Property name='dataset_id' type='string' key='dataset_id'>
  1033. 知识库 ID
  1034. </Property>
  1035. <Property name='document_id' type='string' key='document_id'>
  1036. 文档 ID
  1037. </Property>
  1038. <Property name='segment_id' type='string' key='segment_id'>
  1039. 文档分段ID
  1040. </Property>
  1041. </Properties>
  1042. ### Request Body
  1043. <Properties>
  1044. <Property name='segment' type='object' key='segment'>
  1045. - <code>content</code> (text) 文本内容/问题内容,必填
  1046. - <code>answer</code> (text) 答案内容,非必填,如果知识库的模式为 Q&A 模式则传值
  1047. - <code>keywords</code> (list) 关键字,非必填
  1048. - <code>enabled</code> (bool) false/true,非必填
  1049. - <code>regenerate_child_chunks</code> (bool) 是否重新生成子分段,非必填
  1050. </Property>
  1051. </Properties>
  1052. </Col>
  1053. <Col sticky>
  1054. <CodeGroup
  1055. title="Request"
  1056. tag="POST"
  1057. label="/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}"
  1058. 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}}'`}
  1059. >
  1060. ```bash {{ title: 'cURL' }}
  1061. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}' \
  1062. --header 'Authorization: Bearer {api_key}' \
  1063. --header 'Content-Type: application/json' \
  1064. --data-raw '{
  1065. "segment": {
  1066. "content": "1",
  1067. "answer": "1",
  1068. "keywords": ["a"],
  1069. "enabled": false
  1070. }
  1071. }'
  1072. ```
  1073. </CodeGroup>
  1074. <CodeGroup title="Response">
  1075. ```json {{ title: 'Response' }}
  1076. {
  1077. "data": {
  1078. "id": "",
  1079. "position": 1,
  1080. "document_id": "",
  1081. "content": "1",
  1082. "answer": "1",
  1083. "word_count": 25,
  1084. "tokens": 0,
  1085. "keywords": [
  1086. "a"
  1087. ],
  1088. "index_node_id": "",
  1089. "index_node_hash": "",
  1090. "hit_count": 0,
  1091. "enabled": true,
  1092. "disabled_at": null,
  1093. "disabled_by": null,
  1094. "status": "completed",
  1095. "created_by": "",
  1096. "created_at": 1695312007,
  1097. "indexing_at": 1695312007,
  1098. "completed_at": 1695312007,
  1099. "error": null,
  1100. "stopped_at": null
  1101. },
  1102. "doc_form": "text_model"
  1103. }
  1104. ```
  1105. </CodeGroup>
  1106. </Col>
  1107. </Row>
  1108. <hr className='ml-0 mr-0' />
  1109. <Heading
  1110. url='/datasets/{dataset_id}/documents/{document_id}/upload-file'
  1111. method='GET'
  1112. title='获取上传文件'
  1113. name='#get_upload_file'
  1114. />
  1115. <Row>
  1116. <Col>
  1117. ### Path
  1118. <Properties>
  1119. <Property name='dataset_id' type='string' key='dataset_id'>
  1120. 知识库 ID
  1121. </Property>
  1122. <Property name='document_id' type='string' key='document_id'>
  1123. 文档 ID
  1124. </Property>
  1125. </Properties>
  1126. </Col>
  1127. <Col sticky>
  1128. <CodeGroup
  1129. title="Request"
  1130. tag="GET"
  1131. label="/datasets/{dataset_id}/documents/{document_id}/upload-file"
  1132. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/upload-file' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json'`}
  1133. >
  1134. ```bash {{ title: 'cURL' }}
  1135. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/upload-file' \
  1136. --header 'Authorization: Bearer {api_key}' \
  1137. --header 'Content-Type: application/json'
  1138. ```
  1139. </CodeGroup>
  1140. <CodeGroup title="Response">
  1141. ```json {{ title: 'Response' }}
  1142. {
  1143. "id": "file_id",
  1144. "name": "file_name",
  1145. "size": 1024,
  1146. "extension": "txt",
  1147. "url": "preview_url",
  1148. "download_url": "download_url",
  1149. "mime_type": "text/plain",
  1150. "created_by": "user_id",
  1151. "created_at": 1728734540,
  1152. }
  1153. ```
  1154. </CodeGroup>
  1155. </Col>
  1156. </Row>
  1157. <hr className='ml-0 mr-0' />
  1158. <Heading
  1159. url='/datasets/{dataset_id}/retrieve'
  1160. method='POST'
  1161. title='检索知识库'
  1162. name='#dataset_retrieval'
  1163. />
  1164. <Row>
  1165. <Col>
  1166. ### Path
  1167. <Properties>
  1168. <Property name='dataset_id' type='string' key='dataset_id'>
  1169. 知识库 ID
  1170. </Property>
  1171. </Properties>
  1172. ### Request Body
  1173. <Properties>
  1174. <Property name='query' type='string' key='query'>
  1175. 检索关键词
  1176. </Property>
  1177. <Property name='retrieval_model' type='object' key='retrieval_model'>
  1178. 检索参数(选填,如不填,按照默认方式召回)
  1179. - <code>search_method</code> (text) 检索方法:以下三个关键字之一,必填
  1180. - <code>keyword_search</code> 关键字检索
  1181. - <code>semantic_search</code> 语义检索
  1182. - <code>full_text_search</code> 全文检索
  1183. - <code>hybrid_search</code> 混合检索
  1184. - <code>reranking_enable</code> (bool) 是否启用 Reranking,非必填,如果检索模式为 semantic_search 模式或者 hybrid_search 则传值
  1185. - <code>reranking_mode</code> (object) Rerank 模型配置,非必填,如果启用了 reranking 则传值
  1186. - <code>reranking_provider_name</code> (string) Rerank 模型提供商
  1187. - <code>reranking_model_name</code> (string) Rerank 模型名称
  1188. - <code>weights</code> (float) 混合检索模式下语意检索的权重设置
  1189. - <code>top_k</code> (integer) 返回结果数量,非必填
  1190. - <code>score_threshold_enabled</code> (bool) 是否开启 score 阈值
  1191. - <code>score_threshold</code> (float) Score 阈值
  1192. </Property>
  1193. <Property name='external_retrieval_model' type='object' key='external_retrieval_model'>
  1194. 未启用字段
  1195. </Property>
  1196. </Properties>
  1197. </Col>
  1198. <Col sticky>
  1199. <CodeGroup
  1200. title="Request"
  1201. tag="POST"
  1202. label="/datasets/{dataset_id}/retrieve"
  1203. targetCode={`curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/retrieve' \\\n--header 'Authorization: Bearer {api_key}'\\\n--header 'Content-Type: application/json'\\\n--data-raw '{
  1204. "query": "test",
  1205. "retrieval_model": {
  1206. "search_method": "keyword_search",
  1207. "reranking_enable": false,
  1208. "reranking_mode": null,
  1209. "reranking_model": {
  1210. "reranking_provider_name": "",
  1211. "reranking_model_name": ""
  1212. },
  1213. "weights": null,
  1214. "top_k": 1,
  1215. "score_threshold_enabled": false,
  1216. "score_threshold": null
  1217. }
  1218. }'`}
  1219. >
  1220. ```bash {{ title: 'cURL' }}
  1221. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/retrieve' \
  1222. --header 'Authorization: Bearer {api_key}' \
  1223. --header 'Content-Type: application/json' \
  1224. --data-raw '{
  1225. "query": "test",
  1226. "retrieval_model": {
  1227. "search_method": "keyword_search",
  1228. "reranking_enable": false,
  1229. "reranking_mode": null,
  1230. "reranking_model": {
  1231. "reranking_provider_name": "",
  1232. "reranking_model_name": ""
  1233. },
  1234. "weights": null,
  1235. "top_k": 2,
  1236. "score_threshold_enabled": false,
  1237. "score_threshold": null
  1238. }
  1239. }'
  1240. ```
  1241. </CodeGroup>
  1242. <CodeGroup title="Response">
  1243. ```json {{ title: 'Response' }}
  1244. {
  1245. "query": {
  1246. "content": "test"
  1247. },
  1248. "records": [
  1249. {
  1250. "segment": {
  1251. "id": "7fa6f24f-8679-48b3-bc9d-bdf28d73f218",
  1252. "position": 1,
  1253. "document_id": "a8c6c36f-9f5d-4d7a-8472-f5d7b75d71d2",
  1254. "content": "Operation guide",
  1255. "answer": null,
  1256. "word_count": 847,
  1257. "tokens": 280,
  1258. "keywords": [
  1259. "install",
  1260. "java",
  1261. "base",
  1262. "scripts",
  1263. "jdk",
  1264. "manual",
  1265. "internal",
  1266. "opens",
  1267. "add",
  1268. "vmoptions"
  1269. ],
  1270. "index_node_id": "39dd8443-d960-45a8-bb46-7275ad7fbc8e",
  1271. "index_node_hash": "0189157697b3c6a418ccf8264a09699f25858975578f3467c76d6bfc94df1d73",
  1272. "hit_count": 0,
  1273. "enabled": true,
  1274. "disabled_at": null,
  1275. "disabled_by": null,
  1276. "status": "completed",
  1277. "created_by": "dbcb1ab5-90c8-41a7-8b78-73b235eb6f6f",
  1278. "created_at": 1728734540,
  1279. "indexing_at": 1728734552,
  1280. "completed_at": 1728734584,
  1281. "error": null,
  1282. "stopped_at": null,
  1283. "document": {
  1284. "id": "a8c6c36f-9f5d-4d7a-8472-f5d7b75d71d2",
  1285. "data_source_type": "upload_file",
  1286. "name": "readme.txt",
  1287. }
  1288. },
  1289. "score": 3.730463140527718e-05,
  1290. "tsne_position": null
  1291. }
  1292. ]
  1293. }
  1294. ```
  1295. </CodeGroup>
  1296. </Col>
  1297. </Row>
  1298. <hr className='ml-0 mr-0' />
  1299. <Heading
  1300. url='/datasets/{dataset_id}/metadata'
  1301. method='POST'
  1302. title='新增元数据'
  1303. name='#create_metadata'
  1304. />
  1305. <Row>
  1306. <Col>
  1307. ### Params
  1308. <Properties>
  1309. <Property name='dataset_id' type='string' key='dataset_id'>
  1310. 知识库 ID
  1311. </Property>
  1312. </Properties>
  1313. ### Request Body
  1314. <Properties>
  1315. <Property name='segment' type='object' key='segment'>
  1316. - <code>type</code> (string) 元数据类型,必填
  1317. - <code>name</code> (string) 元数据名称,必填
  1318. </Property>
  1319. </Properties>
  1320. </Col>
  1321. <Col sticky>
  1322. <CodeGroup
  1323. title="Request"
  1324. tag="POST"
  1325. label="/datasets/{dataset_id}/metadata"
  1326. targetCode={`curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/metadata' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json'\\\n--data-raw '{"type": "string", "name": "test"}'`}
  1327. >
  1328. ```bash {{ title: 'cURL' }}
  1329. ```
  1330. </CodeGroup>
  1331. <CodeGroup title="Response">
  1332. ```json {{ title: 'Response' }}
  1333. {
  1334. "id": "abc",
  1335. "type": "string",
  1336. "name": "test",
  1337. }
  1338. ```
  1339. </CodeGroup>
  1340. </Col>
  1341. </Row>
  1342. <hr className='ml-0 mr-0' />
  1343. <Heading
  1344. url='/datasets/{dataset_id}/metadata/{metadata_id}'
  1345. method='PATCH'
  1346. title='更新元数据'
  1347. name='#update_metadata'
  1348. />
  1349. <Row>
  1350. <Col>
  1351. ### Params
  1352. <Properties>
  1353. <Property name='dataset_id' type='string' key='dataset_id'>
  1354. 知识库 ID
  1355. </Property>
  1356. <Property name='metadata_id' type='string' key='metadata_id'>
  1357. 元数据 ID
  1358. </Property>
  1359. </Properties>
  1360. ### Request Body
  1361. <Properties>
  1362. <Property name='segment' type='object' key='segment'>
  1363. - <code>name</code> (string) 元数据名称,必填
  1364. </Property>
  1365. </Properties>
  1366. </Col>
  1367. <Col sticky>
  1368. <CodeGroup
  1369. title="Request"
  1370. tag="POST"
  1371. label="/datasets/{dataset_id}/metadata/{metadata_id}"
  1372. targetCode={`curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/metadata/{metadata_id}' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json'\\\n--data-raw '{"name": "test"}'`}
  1373. >
  1374. ```bash {{ title: 'cURL' }}
  1375. ```
  1376. </CodeGroup>
  1377. <CodeGroup title="Response">
  1378. ```json {{ title: 'Response' }}
  1379. {
  1380. "id": "abc",
  1381. "type": "string",
  1382. "name": "test",
  1383. }
  1384. ```
  1385. </CodeGroup>
  1386. </Col>
  1387. </Row>
  1388. <hr className='ml-0 mr-0' />
  1389. <Heading
  1390. url='/datasets/{dataset_id}/metadata/{metadata_id}'
  1391. method='DELETE'
  1392. title='删除元数据'
  1393. name='#delete_metadata'
  1394. />
  1395. <Row>
  1396. <Col>
  1397. ### Params
  1398. <Properties>
  1399. <Property name='dataset_id' type='string' key='dataset_id'>
  1400. 知识库 ID
  1401. </Property>
  1402. <Property name='metadata_id' type='string' key='metadata_id'>
  1403. 元数据 ID
  1404. </Property>
  1405. </Properties>
  1406. </Col>
  1407. <Col sticky>
  1408. <CodeGroup
  1409. title="Request"
  1410. tag="DELETE"
  1411. label="/datasets/{dataset_id}/metadata/{metadata_id}"
  1412. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/metadata/{metadata_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  1413. >
  1414. ```bash {{ title: 'cURL' }}
  1415. ```
  1416. </CodeGroup>
  1417. </Col>
  1418. </Row>
  1419. <hr className='ml-0 mr-0' />
  1420. <Heading
  1421. url='/datasets/{dataset_id}/metadata/built-in/{action}'
  1422. method='POST'
  1423. title='启用/禁用内置元数据'
  1424. name='#toggle_metadata'
  1425. />
  1426. <Row>
  1427. <Col>
  1428. ### Params
  1429. <Properties>
  1430. <Property name='dataset_id' type='string' key='dataset_id'>
  1431. 知识库 ID
  1432. </Property>
  1433. <Property name='action' type='string' key='action'>
  1434. disable/enable
  1435. </Property>
  1436. </Properties>
  1437. </Col>
  1438. <Col sticky>
  1439. <CodeGroup
  1440. title="Request"
  1441. tag="POST"
  1442. label="/datasets/{dataset_id}/metadata/built-in/{action}"
  1443. targetCode={`curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/metadata/built-in/{action}' \\\n--header 'Authorization: Bearer {api_key}'`}
  1444. >
  1445. ```bash {{ title: 'cURL' }}
  1446. ```
  1447. </CodeGroup>
  1448. </Col>
  1449. </Row>
  1450. <hr className='ml-0 mr-0' />
  1451. <Heading
  1452. url='/datasets/{dataset_id}/documents/metadata'
  1453. method='POST'
  1454. title='更新文档元数据'
  1455. name='#update_documents_metadata'
  1456. />
  1457. <Row>
  1458. <Col>
  1459. ### Params
  1460. <Properties>
  1461. <Property name='dataset_id' type='string' key='dataset_id'>
  1462. 知识库 ID
  1463. </Property>
  1464. </Properties>
  1465. ### Request Body
  1466. <Properties>
  1467. <Property name='operation_data' type='object list' key='segments'>
  1468. - <code>document_id</code> (string) 文档 ID
  1469. - <code>metadata_list</code> (list) 元数据列表
  1470. - <code>id</code> (string) 元数据 ID
  1471. - <code>type</code> (string) 元数据类型
  1472. - <code>name</code> (string) 元数据名称
  1473. </Property>
  1474. </Properties>
  1475. </Col>
  1476. <Col sticky>
  1477. <CodeGroup
  1478. title="Request"
  1479. tag="POST"
  1480. label="/datasets/{dataset_id}/documents/metadata"
  1481. targetCode={`curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/metadata' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json'\\\n--data-raw '{"operation_data": [{"document_id": "document_id", "metadata_list": [{"id": "id", "value": "value", "name": "name"}]}]}'`}
  1482. >
  1483. ```bash {{ title: 'cURL' }}
  1484. ```
  1485. </CodeGroup>
  1486. </Col>
  1487. </Row>
  1488. <hr className='ml-0 mr-0' />
  1489. <Heading
  1490. url='/datasets/{dataset_id}/metadata'
  1491. method='GET'
  1492. title='查询知识库元数据列表'
  1493. name='#dataset_metadata_list'
  1494. />
  1495. <Row>
  1496. <Col>
  1497. ### Query
  1498. <Properties>
  1499. <Property name='dataset_id' type='string' key='dataset_id'>
  1500. 知识库 ID
  1501. </Property>
  1502. </Properties>
  1503. </Col>
  1504. <Col sticky>
  1505. <CodeGroup
  1506. title="Request"
  1507. tag="GET"
  1508. label="/datasets/{dataset_id}/metadata"
  1509. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/metadata' \\\n--header 'Authorization: Bearer {api_key}'`}
  1510. >
  1511. ```bash {{ title: 'cURL' }}
  1512. ```
  1513. </CodeGroup>
  1514. <CodeGroup title="Response">
  1515. ```json {{ title: 'Response' }}
  1516. {
  1517. "doc_metadata": [
  1518. {
  1519. "id": "",
  1520. "name": "name",
  1521. "type": "string",
  1522. "use_count": 0,
  1523. },
  1524. ...
  1525. ],
  1526. "built_in_field_enabled": true
  1527. }
  1528. ```
  1529. </CodeGroup>
  1530. </Col>
  1531. </Row>
  1532. <hr className='ml-0 mr-0' />
  1533. <Row>
  1534. <Col>
  1535. ### 错误信息
  1536. <Properties>
  1537. <Property name='code' type='string' key='code'>
  1538. 返回的错误代码
  1539. </Property>
  1540. </Properties>
  1541. <Properties>
  1542. <Property name='status' type='number' key='status'>
  1543. 返回的错误状态
  1544. </Property>
  1545. </Properties>
  1546. <Properties>
  1547. <Property name='message' type='string' key='message'>
  1548. 返回的错误信息
  1549. </Property>
  1550. </Properties>
  1551. </Col>
  1552. <Col>
  1553. <CodeGroup title="Example">
  1554. ```json {{ title: 'Response' }}
  1555. {
  1556. "code": "no_file_uploaded",
  1557. "message": "Please upload your file.",
  1558. "status": 400
  1559. }
  1560. ```
  1561. </CodeGroup>
  1562. </Col>
  1563. </Row>
  1564. <table className="max-w-auto border-collapse border border-slate-400" style={{ maxWidth: 'none', width: 'auto' }}>
  1565. <thead style={{ background: '#f9fafc' }}>
  1566. <tr>
  1567. <th className="p-2 border border-slate-300">code</th>
  1568. <th className="p-2 border border-slate-300">status</th>
  1569. <th className="p-2 border border-slate-300">message</th>
  1570. </tr>
  1571. </thead>
  1572. <tbody>
  1573. <tr>
  1574. <td className="p-2 border border-slate-300">no_file_uploaded</td>
  1575. <td className="p-2 border border-slate-300">400</td>
  1576. <td className="p-2 border border-slate-300">Please upload your file.</td>
  1577. </tr>
  1578. <tr>
  1579. <td className="p-2 border border-slate-300">too_many_files</td>
  1580. <td className="p-2 border border-slate-300">400</td>
  1581. <td className="p-2 border border-slate-300">Only one file is allowed.</td>
  1582. </tr>
  1583. <tr>
  1584. <td className="p-2 border border-slate-300">file_too_large</td>
  1585. <td className="p-2 border border-slate-300">413</td>
  1586. <td className="p-2 border border-slate-300">File size exceeded.</td>
  1587. </tr>
  1588. <tr>
  1589. <td className="p-2 border border-slate-300">unsupported_file_type</td>
  1590. <td className="p-2 border border-slate-300">415</td>
  1591. <td className="p-2 border border-slate-300">File type not allowed.</td>
  1592. </tr>
  1593. <tr>
  1594. <td className="p-2 border border-slate-300">high_quality_dataset_only</td>
  1595. <td className="p-2 border border-slate-300">400</td>
  1596. <td className="p-2 border border-slate-300">Current operation only supports 'high-quality' datasets.</td>
  1597. </tr>
  1598. <tr>
  1599. <td className="p-2 border border-slate-300">dataset_not_initialized</td>
  1600. <td className="p-2 border border-slate-300">400</td>
  1601. <td className="p-2 border border-slate-300">The dataset is still being initialized or indexing. Please wait a moment.</td>
  1602. </tr>
  1603. <tr>
  1604. <td className="p-2 border border-slate-300">archived_document_immutable</td>
  1605. <td className="p-2 border border-slate-300">403</td>
  1606. <td className="p-2 border border-slate-300">The archived document is not editable.</td>
  1607. </tr>
  1608. <tr>
  1609. <td className="p-2 border border-slate-300">dataset_name_duplicate</td>
  1610. <td className="p-2 border border-slate-300">409</td>
  1611. <td className="p-2 border border-slate-300">The dataset name already exists. Please modify your dataset name.</td>
  1612. </tr>
  1613. <tr>
  1614. <td className="p-2 border border-slate-300">invalid_action</td>
  1615. <td className="p-2 border border-slate-300">400</td>
  1616. <td className="p-2 border border-slate-300">Invalid action.</td>
  1617. </tr>
  1618. <tr>
  1619. <td className="p-2 border border-slate-300">document_already_finished</td>
  1620. <td className="p-2 border border-slate-300">400</td>
  1621. <td className="p-2 border border-slate-300">The document has been processed. Please refresh the page or go to the document details.</td>
  1622. </tr>
  1623. <tr>
  1624. <td className="p-2 border border-slate-300">document_indexing</td>
  1625. <td className="p-2 border border-slate-300">400</td>
  1626. <td className="p-2 border border-slate-300">The document is being processed and cannot be edited.</td>
  1627. </tr>
  1628. <tr>
  1629. <td className="p-2 border border-slate-300">invalid_metadata</td>
  1630. <td className="p-2 border border-slate-300">400</td>
  1631. <td className="p-2 border border-slate-300">The metadata content is incorrect. Please check and verify.</td>
  1632. </tr>
  1633. </tbody>
  1634. </table>
  1635. <div className="pb-4" />