template.zh.mdx 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012
  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}/segments/{segment_id}/child_chunks'
  1111. method='POST'
  1112. title='新增文档子分段'
  1113. name='#create_child_chunk'
  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. <Property name='segment_id' type='string' key='segment_id'>
  1126. 分段 ID
  1127. </Property>
  1128. </Properties>
  1129. ### Request Body
  1130. <Properties>
  1131. <Property name='content' type='string' key='content'>
  1132. 子分段内容
  1133. </Property>
  1134. </Properties>
  1135. </Col>
  1136. <Col sticky>
  1137. <CodeGroup
  1138. title="Request"
  1139. tag="POST"
  1140. label="/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks"
  1141. targetCode={`curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{"content": "子分段内容"}'`}
  1142. >
  1143. ```bash {{ title: 'cURL' }}
  1144. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks' \
  1145. --header 'Authorization: Bearer {api_key}' \
  1146. --header 'Content-Type: application/json' \
  1147. --data-raw '{
  1148. "content": "子分段内容"
  1149. }'
  1150. ```
  1151. </CodeGroup>
  1152. <CodeGroup title="Response">
  1153. ```json {{ title: 'Response' }}
  1154. {
  1155. "data": {
  1156. "id": "",
  1157. "segment_id": "",
  1158. "content": "子分段内容",
  1159. "word_count": 25,
  1160. "tokens": 0,
  1161. "index_node_id": "",
  1162. "index_node_hash": "",
  1163. "status": "completed",
  1164. "created_by": "",
  1165. "created_at": 1695312007,
  1166. "indexing_at": 1695312007,
  1167. "completed_at": 1695312007,
  1168. "error": null,
  1169. "stopped_at": null
  1170. }
  1171. }
  1172. ```
  1173. </CodeGroup>
  1174. </Col>
  1175. </Row>
  1176. <hr className='ml-0 mr-0' />
  1177. <Heading
  1178. url='/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks'
  1179. method='GET'
  1180. title='查询文档子分段'
  1181. name='#get_child_chunks'
  1182. />
  1183. <Row>
  1184. <Col>
  1185. ### Path
  1186. <Properties>
  1187. <Property name='dataset_id' type='string' key='dataset_id'>
  1188. 知识库 ID
  1189. </Property>
  1190. <Property name='document_id' type='string' key='document_id'>
  1191. 文档 ID
  1192. </Property>
  1193. <Property name='segment_id' type='string' key='segment_id'>
  1194. 分段 ID
  1195. </Property>
  1196. </Properties>
  1197. ### Query
  1198. <Properties>
  1199. <Property name='keyword' type='string' key='keyword'>
  1200. 搜索关键词(选填)
  1201. </Property>
  1202. <Property name='page' type='integer' key='page'>
  1203. 页码(选填,默认1)
  1204. </Property>
  1205. <Property name='limit' type='integer' key='limit'>
  1206. 每页数量(选填,默认20,最大100)
  1207. </Property>
  1208. </Properties>
  1209. </Col>
  1210. <Col sticky>
  1211. <CodeGroup
  1212. title="Request"
  1213. tag="GET"
  1214. label="/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks"
  1215. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks?page=1&limit=20' \\\n--header 'Authorization: Bearer {api_key}'`}
  1216. >
  1217. ```bash {{ title: 'cURL' }}
  1218. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks?page=1&limit=20' \
  1219. --header 'Authorization: Bearer {api_key}'
  1220. ```
  1221. </CodeGroup>
  1222. <CodeGroup title="Response">
  1223. ```json {{ title: 'Response' }}
  1224. {
  1225. "data": [{
  1226. "id": "",
  1227. "segment_id": "",
  1228. "content": "子分段内容",
  1229. "word_count": 25,
  1230. "tokens": 0,
  1231. "index_node_id": "",
  1232. "index_node_hash": "",
  1233. "status": "completed",
  1234. "created_by": "",
  1235. "created_at": 1695312007,
  1236. "indexing_at": 1695312007,
  1237. "completed_at": 1695312007,
  1238. "error": null,
  1239. "stopped_at": null
  1240. }],
  1241. "total": 1,
  1242. "total_pages": 1,
  1243. "page": 1,
  1244. "limit": 20
  1245. }
  1246. ```
  1247. </CodeGroup>
  1248. </Col>
  1249. </Row>
  1250. <hr className='ml-0 mr-0' />
  1251. <Heading
  1252. url='/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks/{child_chunk_id}'
  1253. method='DELETE'
  1254. title='删除文档子分段'
  1255. name='#delete_child_chunk'
  1256. />
  1257. <Row>
  1258. <Col>
  1259. ### Path
  1260. <Properties>
  1261. <Property name='dataset_id' type='string' key='dataset_id'>
  1262. 知识库 ID
  1263. </Property>
  1264. <Property name='document_id' type='string' key='document_id'>
  1265. 文档 ID
  1266. </Property>
  1267. <Property name='segment_id' type='string' key='segment_id'>
  1268. 分段 ID
  1269. </Property>
  1270. <Property name='child_chunk_id' type='string' key='child_chunk_id'>
  1271. 子分段 ID
  1272. </Property>
  1273. </Properties>
  1274. </Col>
  1275. <Col sticky>
  1276. <CodeGroup
  1277. title="Request"
  1278. tag="DELETE"
  1279. label="/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks/{child_chunk_id}"
  1280. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks/{child_chunk_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  1281. >
  1282. ```bash {{ title: 'cURL' }}
  1283. curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks/{child_chunk_id}' \
  1284. --header 'Authorization: Bearer {api_key}'
  1285. ```
  1286. </CodeGroup>
  1287. <CodeGroup title="Response">
  1288. ```json {{ title: 'Response' }}
  1289. {
  1290. "result": "success"
  1291. }
  1292. ```
  1293. </CodeGroup>
  1294. </Col>
  1295. </Row>
  1296. <hr className='ml-0 mr-0' />
  1297. <Row>
  1298. <Col>
  1299. ### 错误信息
  1300. <Properties>
  1301. <Property name='code' type='string' key='code'>
  1302. 返回的错误代码
  1303. </Property>
  1304. </Properties>
  1305. <Properties>
  1306. <Property name='status' type='number' key='status'>
  1307. 返回的错误状态
  1308. </Property>
  1309. </Properties>
  1310. <Properties>
  1311. <Property name='message' type='string' key='message'>
  1312. 返回的错误信息
  1313. </Property>
  1314. </Properties>
  1315. </Col>
  1316. <Col>
  1317. <CodeGroup title="Example">
  1318. ```json {{ title: 'Response' }}
  1319. {
  1320. "code": "no_file_uploaded",
  1321. "message": "Please upload your file.",
  1322. "status": 400
  1323. }
  1324. ```
  1325. </CodeGroup>
  1326. </Col>
  1327. </Row>
  1328. <hr className='ml-0 mr-0' />
  1329. <Heading
  1330. url='/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks/{child_chunk_id}'
  1331. method='PATCH'
  1332. title='更新文档子分段'
  1333. name='#update_child_chunk'
  1334. />
  1335. <Row>
  1336. <Col>
  1337. ### Path
  1338. <Properties>
  1339. <Property name='dataset_id' type='string' key='dataset_id'>
  1340. 知识库 ID
  1341. </Property>
  1342. <Property name='document_id' type='string' key='document_id'>
  1343. 文档 ID
  1344. </Property>
  1345. <Property name='segment_id' type='string' key='segment_id'>
  1346. 分段 ID
  1347. </Property>
  1348. <Property name='child_chunk_id' type='string' key='child_chunk_id'>
  1349. 子分段 ID
  1350. </Property>
  1351. </Properties>
  1352. ### Request Body
  1353. <Properties>
  1354. <Property name='content' type='string' key='content'>
  1355. 子分段内容
  1356. </Property>
  1357. </Properties>
  1358. </Col>
  1359. <Col sticky>
  1360. <CodeGroup
  1361. title="Request"
  1362. tag="PATCH"
  1363. label="/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks/{child_chunk_id}"
  1364. targetCode={`curl --location --request PATCH '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks/{child_chunk_id}' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{"content": "更新的子分段内容"}'`}
  1365. >
  1366. ```bash {{ title: 'cURL' }}
  1367. curl --location --request PATCH '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks/{child_chunk_id}' \
  1368. --header 'Authorization: Bearer {api_key}' \
  1369. --header 'Content-Type: application/json' \
  1370. --data-raw '{
  1371. "content": "更新的子分段内容"
  1372. }'
  1373. ```
  1374. </CodeGroup>
  1375. <CodeGroup title="Response">
  1376. ```json {{ title: 'Response' }}
  1377. {
  1378. "data": {
  1379. "id": "",
  1380. "segment_id": "",
  1381. "content": "更新的子分段内容",
  1382. "word_count": 25,
  1383. "tokens": 0,
  1384. "index_node_id": "",
  1385. "index_node_hash": "",
  1386. "status": "completed",
  1387. "created_by": "",
  1388. "created_at": 1695312007,
  1389. "indexing_at": 1695312007,
  1390. "completed_at": 1695312007,
  1391. "error": null,
  1392. "stopped_at": null
  1393. }
  1394. }
  1395. ```
  1396. </CodeGroup>
  1397. </Col>
  1398. </Row>
  1399. <hr className='ml-0 mr-0' />
  1400. <Heading
  1401. url='/datasets/{dataset_id}/documents/{document_id}/upload-file'
  1402. method='GET'
  1403. title='获取上传文件'
  1404. name='#get_upload_file'
  1405. />
  1406. <Row>
  1407. <Col>
  1408. ### Path
  1409. <Properties>
  1410. <Property name='dataset_id' type='string' key='dataset_id'>
  1411. 知识库 ID
  1412. </Property>
  1413. <Property name='document_id' type='string' key='document_id'>
  1414. 文档 ID
  1415. </Property>
  1416. </Properties>
  1417. </Col>
  1418. <Col sticky>
  1419. <CodeGroup
  1420. title="Request"
  1421. tag="GET"
  1422. label="/datasets/{dataset_id}/documents/{document_id}/upload-file"
  1423. 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'`}
  1424. >
  1425. ```bash {{ title: 'cURL' }}
  1426. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/upload-file' \
  1427. --header 'Authorization: Bearer {api_key}' \
  1428. --header 'Content-Type: application/json'
  1429. ```
  1430. </CodeGroup>
  1431. <CodeGroup title="Response">
  1432. ```json {{ title: 'Response' }}
  1433. {
  1434. "id": "file_id",
  1435. "name": "file_name",
  1436. "size": 1024,
  1437. "extension": "txt",
  1438. "url": "preview_url",
  1439. "download_url": "download_url",
  1440. "mime_type": "text/plain",
  1441. "created_by": "user_id",
  1442. "created_at": 1728734540,
  1443. }
  1444. ```
  1445. </CodeGroup>
  1446. </Col>
  1447. </Row>
  1448. <hr className='ml-0 mr-0' />
  1449. <Heading
  1450. url='/datasets/{dataset_id}/retrieve'
  1451. method='POST'
  1452. title='检索知识库'
  1453. name='#dataset_retrieval'
  1454. />
  1455. <Row>
  1456. <Col>
  1457. ### Path
  1458. <Properties>
  1459. <Property name='dataset_id' type='string' key='dataset_id'>
  1460. 知识库 ID
  1461. </Property>
  1462. </Properties>
  1463. ### Request Body
  1464. <Properties>
  1465. <Property name='query' type='string' key='query'>
  1466. 检索关键词
  1467. </Property>
  1468. <Property name='retrieval_model' type='object' key='retrieval_model'>
  1469. 检索参数(选填,如不填,按照默认方式召回)
  1470. - <code>search_method</code> (text) 检索方法:以下三个关键字之一,必填
  1471. - <code>keyword_search</code> 关键字检索
  1472. - <code>semantic_search</code> 语义检索
  1473. - <code>full_text_search</code> 全文检索
  1474. - <code>hybrid_search</code> 混合检索
  1475. - <code>reranking_enable</code> (bool) 是否启用 Reranking,非必填,如果检索模式为 semantic_search 模式或者 hybrid_search 则传值
  1476. - <code>reranking_mode</code> (object) Rerank 模型配置,非必填,如果启用了 reranking 则传值
  1477. - <code>reranking_provider_name</code> (string) Rerank 模型提供商
  1478. - <code>reranking_model_name</code> (string) Rerank 模型名称
  1479. - <code>weights</code> (float) 混合检索模式下语意检索的权重设置
  1480. - <code>top_k</code> (integer) 返回结果数量,非必填
  1481. - <code>score_threshold_enabled</code> (bool) 是否开启 score 阈值
  1482. - <code>score_threshold</code> (float) Score 阈值
  1483. </Property>
  1484. <Property name='external_retrieval_model' type='object' key='external_retrieval_model'>
  1485. 未启用字段
  1486. </Property>
  1487. </Properties>
  1488. </Col>
  1489. <Col sticky>
  1490. <CodeGroup
  1491. title="Request"
  1492. tag="POST"
  1493. label="/datasets/{dataset_id}/retrieve"
  1494. 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 '{
  1495. "query": "test",
  1496. "retrieval_model": {
  1497. "search_method": "keyword_search",
  1498. "reranking_enable": false,
  1499. "reranking_mode": null,
  1500. "reranking_model": {
  1501. "reranking_provider_name": "",
  1502. "reranking_model_name": ""
  1503. },
  1504. "weights": null,
  1505. "top_k": 1,
  1506. "score_threshold_enabled": false,
  1507. "score_threshold": null
  1508. }
  1509. }'`}
  1510. >
  1511. ```bash {{ title: 'cURL' }}
  1512. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/retrieve' \
  1513. --header 'Authorization: Bearer {api_key}' \
  1514. --header 'Content-Type: application/json' \
  1515. --data-raw '{
  1516. "query": "test",
  1517. "retrieval_model": {
  1518. "search_method": "keyword_search",
  1519. "reranking_enable": false,
  1520. "reranking_mode": null,
  1521. "reranking_model": {
  1522. "reranking_provider_name": "",
  1523. "reranking_model_name": ""
  1524. },
  1525. "weights": null,
  1526. "top_k": 2,
  1527. "score_threshold_enabled": false,
  1528. "score_threshold": null
  1529. }
  1530. }'
  1531. ```
  1532. </CodeGroup>
  1533. <CodeGroup title="Response">
  1534. ```json {{ title: 'Response' }}
  1535. {
  1536. "query": {
  1537. "content": "test"
  1538. },
  1539. "records": [
  1540. {
  1541. "segment": {
  1542. "id": "7fa6f24f-8679-48b3-bc9d-bdf28d73f218",
  1543. "position": 1,
  1544. "document_id": "a8c6c36f-9f5d-4d7a-8472-f5d7b75d71d2",
  1545. "content": "Operation guide",
  1546. "answer": null,
  1547. "word_count": 847,
  1548. "tokens": 280,
  1549. "keywords": [
  1550. "install",
  1551. "java",
  1552. "base",
  1553. "scripts",
  1554. "jdk",
  1555. "manual",
  1556. "internal",
  1557. "opens",
  1558. "add",
  1559. "vmoptions"
  1560. ],
  1561. "index_node_id": "39dd8443-d960-45a8-bb46-7275ad7fbc8e",
  1562. "index_node_hash": "0189157697b3c6a418ccf8264a09699f25858975578f3467c76d6bfc94df1d73",
  1563. "hit_count": 0,
  1564. "enabled": true,
  1565. "disabled_at": null,
  1566. "disabled_by": null,
  1567. "status": "completed",
  1568. "created_by": "dbcb1ab5-90c8-41a7-8b78-73b235eb6f6f",
  1569. "created_at": 1728734540,
  1570. "indexing_at": 1728734552,
  1571. "completed_at": 1728734584,
  1572. "error": null,
  1573. "stopped_at": null,
  1574. "document": {
  1575. "id": "a8c6c36f-9f5d-4d7a-8472-f5d7b75d71d2",
  1576. "data_source_type": "upload_file",
  1577. "name": "readme.txt",
  1578. }
  1579. },
  1580. "score": 3.730463140527718e-05,
  1581. "tsne_position": null
  1582. }
  1583. ]
  1584. }
  1585. ```
  1586. </CodeGroup>
  1587. </Col>
  1588. </Row>
  1589. <hr className='ml-0 mr-0' />
  1590. <Heading
  1591. url='/datasets/{dataset_id}/metadata'
  1592. method='POST'
  1593. title='新增元数据'
  1594. name='#create_metadata'
  1595. />
  1596. <Row>
  1597. <Col>
  1598. ### Params
  1599. <Properties>
  1600. <Property name='dataset_id' type='string' key='dataset_id'>
  1601. 知识库 ID
  1602. </Property>
  1603. </Properties>
  1604. ### Request Body
  1605. <Properties>
  1606. <Property name='segment' type='object' key='segment'>
  1607. - <code>type</code> (string) 元数据类型,必填
  1608. - <code>name</code> (string) 元数据名称,必填
  1609. </Property>
  1610. </Properties>
  1611. </Col>
  1612. <Col sticky>
  1613. <CodeGroup
  1614. title="Request"
  1615. tag="POST"
  1616. label="/datasets/{dataset_id}/metadata"
  1617. 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"}'`}
  1618. >
  1619. ```bash {{ title: 'cURL' }}
  1620. ```
  1621. </CodeGroup>
  1622. <CodeGroup title="Response">
  1623. ```json {{ title: 'Response' }}
  1624. {
  1625. "id": "abc",
  1626. "type": "string",
  1627. "name": "test",
  1628. }
  1629. ```
  1630. </CodeGroup>
  1631. </Col>
  1632. </Row>
  1633. <hr className='ml-0 mr-0' />
  1634. <Heading
  1635. url='/datasets/{dataset_id}/metadata/{metadata_id}'
  1636. method='PATCH'
  1637. title='更新元数据'
  1638. name='#update_metadata'
  1639. />
  1640. <Row>
  1641. <Col>
  1642. ### Params
  1643. <Properties>
  1644. <Property name='dataset_id' type='string' key='dataset_id'>
  1645. 知识库 ID
  1646. </Property>
  1647. <Property name='metadata_id' type='string' key='metadata_id'>
  1648. 元数据 ID
  1649. </Property>
  1650. </Properties>
  1651. ### Request Body
  1652. <Properties>
  1653. <Property name='segment' type='object' key='segment'>
  1654. - <code>name</code> (string) 元数据名称,必填
  1655. </Property>
  1656. </Properties>
  1657. </Col>
  1658. <Col sticky>
  1659. <CodeGroup
  1660. title="Request"
  1661. tag="POST"
  1662. label="/datasets/{dataset_id}/metadata/{metadata_id}"
  1663. 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"}'`}
  1664. >
  1665. ```bash {{ title: 'cURL' }}
  1666. ```
  1667. </CodeGroup>
  1668. <CodeGroup title="Response">
  1669. ```json {{ title: 'Response' }}
  1670. {
  1671. "id": "abc",
  1672. "type": "string",
  1673. "name": "test",
  1674. }
  1675. ```
  1676. </CodeGroup>
  1677. </Col>
  1678. </Row>
  1679. <hr className='ml-0 mr-0' />
  1680. <Heading
  1681. url='/datasets/{dataset_id}/metadata/{metadata_id}'
  1682. method='DELETE'
  1683. title='删除元数据'
  1684. name='#delete_metadata'
  1685. />
  1686. <Row>
  1687. <Col>
  1688. ### Params
  1689. <Properties>
  1690. <Property name='dataset_id' type='string' key='dataset_id'>
  1691. 知识库 ID
  1692. </Property>
  1693. <Property name='metadata_id' type='string' key='metadata_id'>
  1694. 元数据 ID
  1695. </Property>
  1696. </Properties>
  1697. </Col>
  1698. <Col sticky>
  1699. <CodeGroup
  1700. title="Request"
  1701. tag="DELETE"
  1702. label="/datasets/{dataset_id}/metadata/{metadata_id}"
  1703. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/metadata/{metadata_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  1704. >
  1705. ```bash {{ title: 'cURL' }}
  1706. ```
  1707. </CodeGroup>
  1708. </Col>
  1709. </Row>
  1710. <hr className='ml-0 mr-0' />
  1711. <Heading
  1712. url='/datasets/{dataset_id}/metadata/built-in/{action}'
  1713. method='POST'
  1714. title='启用/禁用内置元数据'
  1715. name='#toggle_metadata'
  1716. />
  1717. <Row>
  1718. <Col>
  1719. ### Params
  1720. <Properties>
  1721. <Property name='dataset_id' type='string' key='dataset_id'>
  1722. 知识库 ID
  1723. </Property>
  1724. <Property name='action' type='string' key='action'>
  1725. disable/enable
  1726. </Property>
  1727. </Properties>
  1728. </Col>
  1729. <Col sticky>
  1730. <CodeGroup
  1731. title="Request"
  1732. tag="POST"
  1733. label="/datasets/{dataset_id}/metadata/built-in/{action}"
  1734. targetCode={`curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/metadata/built-in/{action}' \\\n--header 'Authorization: Bearer {api_key}'`}
  1735. >
  1736. ```bash {{ title: 'cURL' }}
  1737. ```
  1738. </CodeGroup>
  1739. </Col>
  1740. </Row>
  1741. <hr className='ml-0 mr-0' />
  1742. <Heading
  1743. url='/datasets/{dataset_id}/documents/metadata'
  1744. method='POST'
  1745. title='更新文档元数据'
  1746. name='#update_documents_metadata'
  1747. />
  1748. <Row>
  1749. <Col>
  1750. ### Params
  1751. <Properties>
  1752. <Property name='dataset_id' type='string' key='dataset_id'>
  1753. 知识库 ID
  1754. </Property>
  1755. </Properties>
  1756. ### Request Body
  1757. <Properties>
  1758. <Property name='operation_data' type='object list' key='segments'>
  1759. - <code>document_id</code> (string) 文档 ID
  1760. - <code>metadata_list</code> (list) 元数据列表
  1761. - <code>id</code> (string) 元数据 ID
  1762. - <code>type</code> (string) 元数据类型
  1763. - <code>name</code> (string) 元数据名称
  1764. </Property>
  1765. </Properties>
  1766. </Col>
  1767. <Col sticky>
  1768. <CodeGroup
  1769. title="Request"
  1770. tag="POST"
  1771. label="/datasets/{dataset_id}/documents/metadata"
  1772. 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"}]}]}'`}
  1773. >
  1774. ```bash {{ title: 'cURL' }}
  1775. ```
  1776. </CodeGroup>
  1777. </Col>
  1778. </Row>
  1779. <hr className='ml-0 mr-0' />
  1780. <Heading
  1781. url='/datasets/{dataset_id}/metadata'
  1782. method='GET'
  1783. title='查询知识库元数据列表'
  1784. name='#dataset_metadata_list'
  1785. />
  1786. <Row>
  1787. <Col>
  1788. ### Query
  1789. <Properties>
  1790. <Property name='dataset_id' type='string' key='dataset_id'>
  1791. 知识库 ID
  1792. </Property>
  1793. </Properties>
  1794. </Col>
  1795. <Col sticky>
  1796. <CodeGroup
  1797. title="Request"
  1798. tag="GET"
  1799. label="/datasets/{dataset_id}/metadata"
  1800. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/metadata' \\\n--header 'Authorization: Bearer {api_key}'`}
  1801. >
  1802. ```bash {{ title: 'cURL' }}
  1803. ```
  1804. </CodeGroup>
  1805. <CodeGroup title="Response">
  1806. ```json {{ title: 'Response' }}
  1807. {
  1808. "doc_metadata": [
  1809. {
  1810. "id": "",
  1811. "name": "name",
  1812. "type": "string",
  1813. "use_count": 0,
  1814. },
  1815. ...
  1816. ],
  1817. "built_in_field_enabled": true
  1818. }
  1819. ```
  1820. </CodeGroup>
  1821. </Col>
  1822. </Row>
  1823. <hr className='ml-0 mr-0' />
  1824. <Row>
  1825. <Col>
  1826. ### 错误信息
  1827. <Properties>
  1828. <Property name='code' type='string' key='code'>
  1829. 返回的错误代码
  1830. </Property>
  1831. </Properties>
  1832. <Properties>
  1833. <Property name='status' type='number' key='status'>
  1834. 返回的错误状态
  1835. </Property>
  1836. </Properties>
  1837. <Properties>
  1838. <Property name='message' type='string' key='message'>
  1839. 返回的错误信息
  1840. </Property>
  1841. </Properties>
  1842. </Col>
  1843. <Col>
  1844. <CodeGroup title="Example">
  1845. ```json {{ title: 'Response' }}
  1846. {
  1847. "code": "no_file_uploaded",
  1848. "message": "Please upload your file.",
  1849. "status": 400
  1850. }
  1851. ```
  1852. </CodeGroup>
  1853. </Col>
  1854. </Row>
  1855. <table className="max-w-auto border-collapse border border-slate-400" style={{ maxWidth: 'none', width: 'auto' }}>
  1856. <thead style={{ background: '#f9fafc' }}>
  1857. <tr>
  1858. <th className="p-2 border border-slate-300">code</th>
  1859. <th className="p-2 border border-slate-300">status</th>
  1860. <th className="p-2 border border-slate-300">message</th>
  1861. </tr>
  1862. </thead>
  1863. <tbody>
  1864. <tr>
  1865. <td className="p-2 border border-slate-300">no_file_uploaded</td>
  1866. <td className="p-2 border border-slate-300">400</td>
  1867. <td className="p-2 border border-slate-300">Please upload your file.</td>
  1868. </tr>
  1869. <tr>
  1870. <td className="p-2 border border-slate-300">too_many_files</td>
  1871. <td className="p-2 border border-slate-300">400</td>
  1872. <td className="p-2 border border-slate-300">Only one file is allowed.</td>
  1873. </tr>
  1874. <tr>
  1875. <td className="p-2 border border-slate-300">file_too_large</td>
  1876. <td className="p-2 border border-slate-300">413</td>
  1877. <td className="p-2 border border-slate-300">File size exceeded.</td>
  1878. </tr>
  1879. <tr>
  1880. <td className="p-2 border border-slate-300">unsupported_file_type</td>
  1881. <td className="p-2 border border-slate-300">415</td>
  1882. <td className="p-2 border border-slate-300">File type not allowed.</td>
  1883. </tr>
  1884. <tr>
  1885. <td className="p-2 border border-slate-300">high_quality_dataset_only</td>
  1886. <td className="p-2 border border-slate-300">400</td>
  1887. <td className="p-2 border border-slate-300">Current operation only supports 'high-quality' datasets.</td>
  1888. </tr>
  1889. <tr>
  1890. <td className="p-2 border border-slate-300">dataset_not_initialized</td>
  1891. <td className="p-2 border border-slate-300">400</td>
  1892. <td className="p-2 border border-slate-300">The dataset is still being initialized or indexing. Please wait a moment.</td>
  1893. </tr>
  1894. <tr>
  1895. <td className="p-2 border border-slate-300">archived_document_immutable</td>
  1896. <td className="p-2 border border-slate-300">403</td>
  1897. <td className="p-2 border border-slate-300">The archived document is not editable.</td>
  1898. </tr>
  1899. <tr>
  1900. <td className="p-2 border border-slate-300">dataset_name_duplicate</td>
  1901. <td className="p-2 border border-slate-300">409</td>
  1902. <td className="p-2 border border-slate-300">The dataset name already exists. Please modify your dataset name.</td>
  1903. </tr>
  1904. <tr>
  1905. <td className="p-2 border border-slate-300">invalid_action</td>
  1906. <td className="p-2 border border-slate-300">400</td>
  1907. <td className="p-2 border border-slate-300">Invalid action.</td>
  1908. </tr>
  1909. <tr>
  1910. <td className="p-2 border border-slate-300">document_already_finished</td>
  1911. <td className="p-2 border border-slate-300">400</td>
  1912. <td className="p-2 border border-slate-300">The document has been processed. Please refresh the page or go to the document details.</td>
  1913. </tr>
  1914. <tr>
  1915. <td className="p-2 border border-slate-300">document_indexing</td>
  1916. <td className="p-2 border border-slate-300">400</td>
  1917. <td className="p-2 border border-slate-300">The document is being processed and cannot be edited.</td>
  1918. </tr>
  1919. <tr>
  1920. <td className="p-2 border border-slate-300">invalid_metadata</td>
  1921. <td className="p-2 border border-slate-300">400</td>
  1922. <td className="p-2 border border-slate-300">The metadata content is incorrect. Please check and verify.</td>
  1923. </tr>
  1924. </tbody>
  1925. </table>
  1926. <div className="pb-4" />