template.zh.mdx 46 KB

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