template.zh.mdx 67 KB

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