template.en.mdx 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407
  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. # Knowledge API
  4. <div>
  5. ### Authentication
  6. Service API of Dify authenticates using an `API-Key`.
  7. It is suggested that developers store the `API-Key` in the backend instead of sharing or storing it in the client side to avoid the leakage of the `API-Key`, which may lead to property loss.
  8. All API requests should include your `API-Key` in the **`Authorization`** HTTP Header, as shown below:
  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='Create a Document from Text'
  20. name='#create-by-text'
  21. />
  22. <Row>
  23. <Col>
  24. This API is based on an existing knowledge and creates a new document through text based on this knowledge.
  25. ### Params
  26. <Properties>
  27. <Property name='dataset_id' type='string' key='dataset_id'>
  28. Knowledge ID
  29. </Property>
  30. </Properties>
  31. ### Request Body
  32. <Properties>
  33. <Property name='name' type='string' key='name'>
  34. Document name
  35. </Property>
  36. <Property name='text' type='string' key='text'>
  37. Document content
  38. </Property>
  39. <Property name='indexing_technique' type='string' key='indexing_technique'>
  40. Index mode
  41. - <code>high_quality</code> High quality: embedding using embedding model, built as vector database index
  42. - <code>economy</code> Economy: Build using inverted index of keyword table index
  43. </Property>
  44. <Property name='doc_form' type='string' key='doc_form'>
  45. Format of indexed content
  46. - <code>text_model</code> Text documents are directly embedded; `economy` mode defaults to using this form
  47. - <code>hierarchical_model</code> Parent-child mode
  48. - <code>qa_model</code> Q&A Mode: Generates Q&A pairs for segmented documents and then embeds the questions
  49. </Property>
  50. <Property name='doc_language' type='string' key='doc_language'>
  51. In Q&A mode, specify the language of the document, for example: <code>English</code>, <code>Chinese</code>
  52. </Property>
  53. <Property name='process_rule' type='object' key='process_rule'>
  54. Processing rules
  55. - <code>mode</code> (string) Cleaning, segmentation mode, automatic / custom
  56. - <code>rules</code> (object) Custom rules (in automatic mode, this field is empty)
  57. - <code>pre_processing_rules</code> (array[object]) Preprocessing rules
  58. - <code>id</code> (string) Unique identifier for the preprocessing rule
  59. - enumerate
  60. - <code>remove_extra_spaces</code> Replace consecutive spaces, newlines, tabs
  61. - <code>remove_urls_emails</code> Delete URL, email address
  62. - <code>enabled</code> (bool) Whether to select this rule or not. If no document ID is passed in, it represents the default value.
  63. - <code>segmentation</code> (object) Segmentation rules
  64. - <code>separator</code> Custom segment identifier, currently only allows one delimiter to be set. Default is \n
  65. - <code>max_tokens</code> Maximum length (token) defaults to 1000
  66. - <code>parent_mode</code> Retrieval mode of parent chunks: <code>full-doc</code> full text retrieval / <code>paragraph</code> paragraph retrieval
  67. - <code>subchunk_segmentation</code> (object) Child chunk rules
  68. - <code>separator</code> Segmentation identifier. Currently, only one delimiter is allowed. The default is <code>***</code>
  69. - <code>max_tokens</code> The maximum length (tokens) must be validated to be shorter than the length of the parent chunk
  70. - <code>chunk_overlap</code> Define the overlap between adjacent chunks (optional)
  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 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='Create a Document from a File'
  133. name='#create-by-file'
  134. />
  135. <Row>
  136. <Col>
  137. This API is based on an existing knowledge and creates a new document through a file based on this knowledge.
  138. ### Params
  139. <Properties>
  140. <Property name='dataset_id' type='string' key='dataset_id'>
  141. Knowledge 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> Source document ID (optional)
  148. - Used to re-upload the document or modify the document cleaning and segmentation configuration. The missing information is copied from the source document
  149. - The source document cannot be an archived document
  150. - When original_document_id is passed in, the update operation is performed on behalf of the document. process_rule is a fillable item. If not filled in, the segmentation method of the source document will be used by default
  151. - When original_document_id is not passed in, the new operation is performed on behalf of the document, and process_rule is required
  152. - <code>indexing_technique</code> Index mode
  153. - <code>high_quality</code> High quality: embedding using embedding model, built as vector database index
  154. - <code>economy</code> Economy: Build using inverted index of keyword table index
  155. - <code>doc_form</code> Format of indexed content
  156. - <code>text_model</code> Text documents are directly embedded; `economy` mode defaults to using this form
  157. - <code>hierarchical_model</code> Parent-child mode
  158. - <code>qa_model</code> Q&A Mode: Generates Q&A pairs for segmented documents and then embeds the questions
  159. - <code>doc_language</code> In Q&A mode, specify the language of the document, for example: <code>English</code>, <code>Chinese</code>
  160. - <code>process_rule</code> Processing rules
  161. - <code>mode</code> (string) Cleaning, segmentation mode, automatic / custom
  162. - <code>rules</code> (object) Custom rules (in automatic mode, this field is empty)
  163. - <code>pre_processing_rules</code> (array[object]) Preprocessing rules
  164. - <code>id</code> (string) Unique identifier for the preprocessing rule
  165. - enumerate
  166. - <code>remove_extra_spaces</code> Replace consecutive spaces, newlines, tabs
  167. - <code>remove_urls_emails</code> Delete URL, email address
  168. - <code>enabled</code> (bool) Whether to select this rule or not. If no document ID is passed in, it represents the default value.
  169. - <code>segmentation</code> (object) Segmentation rules
  170. - <code>separator</code> Custom segment identifier, currently only allows one delimiter to be set. Default is \n
  171. - <code>max_tokens</code> Maximum length (token) defaults to 1000
  172. - <code>parent_mode</code> Retrieval mode of parent chunks: <code>full-doc</code> full text retrieval / <code>paragraph</code> paragraph retrieval
  173. - <code>subchunk_segmentation</code> (object) Child chunk rules
  174. - <code>separator</code> Segmentation identifier. Currently, only one delimiter is allowed. The default is <code>***</code>
  175. - <code>max_tokens</code> The maximum length (tokens) must be validated to be shorter than the length of the parent chunk
  176. - <code>chunk_overlap</code> Define the overlap between adjacent chunks (optional)
  177. </Property>
  178. <Property name='file' type='multipart/form-data' key='file'>
  179. Files that need to be uploaded.
  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='Create an Empty Knowledge Base'
  235. name='#create_empty_dataset'
  236. />
  237. <Row>
  238. <Col>
  239. ### Request Body
  240. <Properties>
  241. <Property name='name' type='string' key='name'>
  242. Knowledge name
  243. </Property>
  244. <Property name='description' type='string' key='description'>
  245. Knowledge description (optional)
  246. </Property>
  247. <Property name='indexing_technique' type='string' key='indexing_technique'>
  248. Index technique (optional)
  249. - <code>high_quality</code> High quality
  250. - <code>economy</code> Economy
  251. </Property>
  252. <Property name='permission' type='string' key='permission'>
  253. Permission
  254. - <code>only_me</code> Only me
  255. - <code>all_team_members</code> All team members
  256. - <code>partial_members</code> Partial members
  257. </Property>
  258. <Property name='provider' type='string' key='provider'>
  259. Provider (optional, default: vendor)
  260. - <code>vendor</code> Vendor
  261. - <code>external</code> External knowledge
  262. </Property>
  263. <Property name='external_knowledge_api_id' type='str' key='external_knowledge_api_id'>
  264. External knowledge API ID (optional)
  265. </Property>
  266. <Property name='external_knowledge_id' type='str' key='external_knowledge_id'>
  267. External knowledge ID (optional)
  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 '${apiBaseUrl}/v1/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='Get Knowledge Base List'
  318. name='#dataset_list'
  319. />
  320. <Row>
  321. <Col>
  322. ### Query
  323. <Properties>
  324. <Property name='page' type='string' key='page'>
  325. Page number
  326. </Property>
  327. <Property name='limit' type='string' key='limit'>
  328. Number of items returned, default 20, range 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": "name",
  351. "description": "desc",
  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='Delete a Knowledge Base'
  379. name='#delete_dataset'
  380. />
  381. <Row>
  382. <Col>
  383. ### Params
  384. <Properties>
  385. <Property name='dataset_id' type='string' key='dataset_id'>
  386. Knowledge 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='Update a Document with Text'
  414. name='#update-by-text'
  415. />
  416. <Row>
  417. <Col>
  418. This API is based on an existing knowledge and updates the document through text based on this knowledge.
  419. ### Params
  420. <Properties>
  421. <Property name='dataset_id' type='string' key='dataset_id'>
  422. Knowledge ID
  423. </Property>
  424. <Property name='document_id' type='string' key='document_id'>
  425. Document ID
  426. </Property>
  427. </Properties>
  428. ### Request Body
  429. <Properties>
  430. <Property name='name' type='string' key='name'>
  431. Document name (optional)
  432. </Property>
  433. <Property name='text' type='string' key='text'>
  434. Document content (optional)
  435. </Property>
  436. <Property name='process_rule' type='object' key='process_rule'>
  437. Processing rules
  438. - <code>mode</code> (string) Cleaning, segmentation mode, automatic / custom
  439. - <code>rules</code> (object) Custom rules (in automatic mode, this field is empty)
  440. - <code>pre_processing_rules</code> (array[object]) Preprocessing rules
  441. - <code>id</code> (string) Unique identifier for the preprocessing rule
  442. - enumerate
  443. - <code>remove_extra_spaces</code> Replace consecutive spaces, newlines, tabs
  444. - <code>remove_urls_emails</code> Delete URL, email address
  445. - <code>enabled</code> (bool) Whether to select this rule or not. If no document ID is passed in, it represents the default value.
  446. - <code>segmentation</code> (object) Segmentation rules
  447. - <code>separator</code> Custom segment identifier, currently only allows one delimiter to be set. Default is \n
  448. - <code>max_tokens</code> Maximum length (token) defaults to 1000
  449. - <code>parent_mode</code> Retrieval mode of parent chunks: <code>full-doc</code> full text retrieval / <code>paragraph</code> paragraph retrieval
  450. - <code>subchunk_segmentation</code> (object) Child chunk rules
  451. - <code>separator</code> Segmentation identifier. Currently, only one delimiter is allowed. The default is <code>***</code>
  452. - <code>max_tokens</code> The maximum length (tokens) must be validated to be shorter than the length of the parent chunk
  453. - <code>chunk_overlap</code> Define the overlap between adjacent chunks (optional)
  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='Update a Document with a File'
  512. name='#update-by-file'
  513. />
  514. <Row>
  515. <Col>
  516. This API is based on an existing knowledge, and updates documents through files based on this knowledge
  517. ### Params
  518. <Properties>
  519. <Property name='dataset_id' type='string' key='dataset_id'>
  520. Knowledge ID
  521. </Property>
  522. <Property name='document_id' type='string' key='document_id'>
  523. Document ID
  524. </Property>
  525. </Properties>
  526. ### Request Body
  527. <Properties>
  528. <Property name='name' type='string' key='name'>
  529. Document name (optional)
  530. </Property>
  531. <Property name='file' type='multipart/form-data' key='file'>
  532. Files to be uploaded
  533. </Property>
  534. <Property name='process_rule' type='object' key='process_rule'>
  535. Processing rules
  536. - <code>mode</code> (string) Cleaning, segmentation mode, automatic / custom
  537. - <code>rules</code> (object) Custom rules (in automatic mode, this field is empty)
  538. - <code>pre_processing_rules</code> (array[object]) Preprocessing rules
  539. - <code>id</code> (string) Unique identifier for the preprocessing rule
  540. - enumerate
  541. - <code>remove_extra_spaces</code> Replace consecutive spaces, newlines, tabs
  542. - <code>remove_urls_emails</code> Delete URL, email address
  543. - <code>enabled</code> (bool) Whether to select this rule or not. If no document ID is passed in, it represents the default value.
  544. - <code>segmentation</code> (object) Segmentation rules
  545. - <code>separator</code> Custom segment identifier, currently only allows one delimiter to be set. Default is \n
  546. - <code>max_tokens</code> Maximum length (token) defaults to 1000
  547. - <code>parent_mode</code> Retrieval mode of parent chunks: <code>full-doc</code> full text retrieval / <code>paragraph</code> paragraph retrieval
  548. - <code>subchunk_segmentation</code> (object) Child chunk rules
  549. - <code>separator</code> Segmentation identifier. Currently, only one delimiter is allowed. The default is <code>***</code>
  550. - <code>max_tokens</code> The maximum length (tokens) must be validated to be shorter than the length of the parent chunk
  551. - <code>chunk_overlap</code> Define the overlap between adjacent chunks (optional)
  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='Get Document Embedding Status (Progress)'
  607. name='#indexing_status'
  608. />
  609. <Row>
  610. <Col>
  611. ### Params
  612. <Properties>
  613. <Property name='dataset_id' type='string' key='dataset_id'>
  614. Knowledge ID
  615. </Property>
  616. <Property name='batch' type='string' key='batch'>
  617. Batch number of uploaded documents
  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='Delete a Document'
  660. name='#delete_document'
  661. />
  662. <Row>
  663. <Col>
  664. ### Params
  665. <Properties>
  666. <Property name='dataset_id' type='string' key='dataset_id'>
  667. Knowledge ID
  668. </Property>
  669. <Property name='document_id' type='string' key='document_id'>
  670. Document 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='Get the Document List of a Knowledge Base'
  700. name='#dataset_document_list'
  701. />
  702. <Row>
  703. <Col>
  704. ### Params
  705. <Properties>
  706. <Property name='dataset_id' type='string' key='dataset_id'>
  707. Knowledge ID
  708. </Property>
  709. </Properties>
  710. ### Query
  711. <Properties>
  712. <Property name='keyword' type='string' key='keyword'>
  713. Search keywords, currently only search document names (optional)
  714. </Property>
  715. <Property name='page' type='string' key='page'>
  716. Page number (optional)
  717. </Property>
  718. <Property name='limit' type='string' key='limit'>
  719. Number of items returned, default 20, range 1-100 (optional)
  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='Add Chunks to a Document'
  772. name='#create_new_segment'
  773. />
  774. <Row>
  775. <Col>
  776. ### Params
  777. <Properties>
  778. <Property name='dataset_id' type='string' key='dataset_id'>
  779. Knowledge ID
  780. </Property>
  781. <Property name='document_id' type='string' key='document_id'>
  782. Document ID
  783. </Property>
  784. </Properties>
  785. ### Request Body
  786. <Properties>
  787. <Property name='segments' type='object list' key='segments'>
  788. - <code>content</code> (text) Text content / question content, required
  789. - <code>answer</code> (text) Answer content, if the mode of the knowledge is Q&A mode, pass the value (optional)
  790. - <code>keywords</code> (list) Keywords (optional)
  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='Get Chunks from a Document'
  855. name='#get_segment'
  856. />
  857. <Row>
  858. <Col>
  859. ### Path
  860. <Properties>
  861. <Property name='dataset_id' type='string' key='dataset_id'>
  862. Knowledge ID
  863. </Property>
  864. <Property name='document_id' type='string' key='document_id'>
  865. Document ID
  866. </Property>
  867. </Properties>
  868. ### Query
  869. <Properties>
  870. <Property name='keyword' type='string' key='keyword'>
  871. Keyword (optional)
  872. </Property>
  873. <Property name='status' type='string' key='status'>
  874. Search status, 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='Delete a Chunk in a Document'
  930. name='#delete_segment'
  931. />
  932. <Row>
  933. <Col>
  934. ### Path
  935. <Properties>
  936. <Property name='dataset_id' type='string' key='dataset_id'>
  937. Knowledge ID
  938. </Property>
  939. <Property name='document_id' type='string' key='document_id'>
  940. Document ID
  941. </Property>
  942. <Property name='segment_id' type='string' key='segment_id'>
  943. Document Segment 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}/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}/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='Update a Chunk in a Document'
  974. name='#update_segment'
  975. />
  976. <Row>
  977. <Col>
  978. ### POST
  979. <Properties>
  980. <Property name='dataset_id' type='string' key='dataset_id'>
  981. Knowledge ID
  982. </Property>
  983. <Property name='document_id' type='string' key='document_id'>
  984. Document ID
  985. </Property>
  986. <Property name='segment_id' type='string' key='segment_id'>
  987. Document Segment ID
  988. </Property>
  989. </Properties>
  990. ### Request Body
  991. <Properties>
  992. <Property name='segment' type='object' key='segment'>
  993. - <code>content</code> (text) Text content / question content, required
  994. - <code>answer</code> (text) Answer content, passed if the knowledge is in Q&A mode (optional)
  995. - <code>keywords</code> (list) Keyword (optional)
  996. - <code>enabled</code> (bool) False / true (optional)
  997. - <code>regenerate_child_chunks</code> (bool) Whether to regenerate child chunks (optional)
  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 'Content-Type: application/json' \
  1011. --data-raw '{
  1012. "segment": {
  1013. "content": "1",
  1014. "answer": "1",
  1015. "keywords": ["a"],
  1016. "enabled": false
  1017. }
  1018. }'
  1019. ```
  1020. </CodeGroup>
  1021. <CodeGroup title="Response">
  1022. ```json {{ title: 'Response' }}
  1023. {
  1024. "data": [{
  1025. "id": "",
  1026. "position": 1,
  1027. "document_id": "",
  1028. "content": "1",
  1029. "answer": "1",
  1030. "word_count": 25,
  1031. "tokens": 0,
  1032. "keywords": [
  1033. "a"
  1034. ],
  1035. "index_node_id": "",
  1036. "index_node_hash": "",
  1037. "hit_count": 0,
  1038. "enabled": true,
  1039. "disabled_at": null,
  1040. "disabled_by": null,
  1041. "status": "completed",
  1042. "created_by": "",
  1043. "created_at": 1695312007,
  1044. "indexing_at": 1695312007,
  1045. "completed_at": 1695312007,
  1046. "error": null,
  1047. "stopped_at": null
  1048. }],
  1049. "doc_form": "text_model"
  1050. }
  1051. ```
  1052. </CodeGroup>
  1053. </Col>
  1054. </Row>
  1055. <hr className='ml-0 mr-0' />
  1056. <Heading
  1057. url='/datasets/{dataset_id}/documents/{document_id}/upload-file'
  1058. method='GET'
  1059. title='Get Upload File'
  1060. name='#get_upload_file'
  1061. />
  1062. <Row>
  1063. <Col>
  1064. ### Path
  1065. <Properties>
  1066. <Property name='dataset_id' type='string' key='dataset_id'>
  1067. Knowledge ID
  1068. </Property>
  1069. <Property name='document_id' type='string' key='document_id'>
  1070. Document ID
  1071. </Property>
  1072. </Properties>
  1073. </Col>
  1074. <Col sticky>
  1075. <CodeGroup
  1076. title="Request"
  1077. tag="GET"
  1078. label="/datasets/{dataset_id}/documents/{document_id}/upload-file"
  1079. 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'`}
  1080. >
  1081. ```bash {{ title: 'cURL' }}
  1082. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/upload-file' \
  1083. --header 'Authorization: Bearer {api_key}' \
  1084. --header 'Content-Type: application/json'
  1085. ```
  1086. </CodeGroup>
  1087. <CodeGroup title="Response">
  1088. ```json {{ title: 'Response' }}
  1089. {
  1090. "id": "file_id",
  1091. "name": "file_name",
  1092. "size": 1024,
  1093. "extension": "txt",
  1094. "url": "preview_url",
  1095. "download_url": "download_url",
  1096. "mime_type": "text/plain",
  1097. "created_by": "user_id",
  1098. "created_at": 1728734540,
  1099. }
  1100. ```
  1101. </CodeGroup>
  1102. </Col>
  1103. </Row>
  1104. <hr className='ml-0 mr-0' />
  1105. <Heading
  1106. url='/datasets/{dataset_id}/retrieve'
  1107. method='POST'
  1108. title='Retrieve Chunks from a Knowledge Base'
  1109. name='#dataset_retrieval'
  1110. />
  1111. <Row>
  1112. <Col>
  1113. ### Path
  1114. <Properties>
  1115. <Property name='dataset_id' type='string' key='dataset_id'>
  1116. Knowledge ID
  1117. </Property>
  1118. </Properties>
  1119. ### Request Body
  1120. <Properties>
  1121. <Property name='query' type='string' key='query'>
  1122. Query keyword
  1123. </Property>
  1124. <Property name='retrieval_model' type='object' key='retrieval_model'>
  1125. Retrieval model (optional, if not filled, it will be recalled according to the default method)
  1126. - <code>search_method</code> (text) Search method: One of the following four keywords is required
  1127. - <code>keyword_search</code> Keyword search
  1128. - <code>semantic_search</code> Semantic search
  1129. - <code>full_text_search</code> Full-text search
  1130. - <code>hybrid_search</code> Hybrid search
  1131. - <code>reranking_enable</code> (bool) Whether to enable reranking, required if the search mode is semantic_search or hybrid_search (optional)
  1132. - <code>reranking_mode</code> (object) Rerank model configuration, required if reranking is enabled
  1133. - <code>reranking_provider_name</code> (string) Rerank model provider
  1134. - <code>reranking_model_name</code> (string) Rerank model name
  1135. - <code>weights</code> (double) Semantic search weight setting in hybrid search mode
  1136. - <code>top_k</code> (integer) Number of results to return (optional)
  1137. - <code>score_threshold_enabled</code> (bool) Whether to enable score threshold
  1138. - <code>score_threshold</code> (double) Score threshold
  1139. </Property>
  1140. <Property name='external_retrieval_model' type='object' key='external_retrieval_model'>
  1141. Unused field
  1142. </Property>
  1143. </Properties>
  1144. </Col>
  1145. <Col sticky>
  1146. <CodeGroup
  1147. title="Request"
  1148. tag="POST"
  1149. label="/datasets/{dataset_id}/retrieve"
  1150. 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 '{
  1151. "query": "test",
  1152. "retrieval_model": {
  1153. "search_method": "keyword_search",
  1154. "reranking_enable": false,
  1155. "reranking_mode": null,
  1156. "reranking_model": {
  1157. "reranking_provider_name": "",
  1158. "reranking_model_name": ""
  1159. },
  1160. "weights": null,
  1161. "top_k": 1,
  1162. "score_threshold_enabled": false,
  1163. "score_threshold": null
  1164. }
  1165. }'`}
  1166. >
  1167. ```bash {{ title: 'cURL' }}
  1168. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/retrieve' \
  1169. --header 'Authorization: Bearer {api_key}' \
  1170. --header 'Content-Type: application/json' \
  1171. --data-raw '{
  1172. "query": "test",
  1173. "retrieval_model": {
  1174. "search_method": "keyword_search",
  1175. "reranking_enable": false,
  1176. "reranking_mode": null,
  1177. "reranking_model": {
  1178. "reranking_provider_name": "",
  1179. "reranking_model_name": ""
  1180. },
  1181. "weights": null,
  1182. "top_k": 2,
  1183. "score_threshold_enabled": false,
  1184. "score_threshold": null
  1185. }
  1186. }'
  1187. ```
  1188. </CodeGroup>
  1189. <CodeGroup title="Response">
  1190. ```json {{ title: 'Response' }}
  1191. {
  1192. "query": {
  1193. "content": "test"
  1194. },
  1195. "records": [
  1196. {
  1197. "segment": {
  1198. "id": "7fa6f24f-8679-48b3-bc9d-bdf28d73f218",
  1199. "position": 1,
  1200. "document_id": "a8c6c36f-9f5d-4d7a-8472-f5d7b75d71d2",
  1201. "content": "Operation guide",
  1202. "answer": null,
  1203. "word_count": 847,
  1204. "tokens": 280,
  1205. "keywords": [
  1206. "install",
  1207. "java",
  1208. "base",
  1209. "scripts",
  1210. "jdk",
  1211. "manual",
  1212. "internal",
  1213. "opens",
  1214. "add",
  1215. "vmoptions"
  1216. ],
  1217. "index_node_id": "39dd8443-d960-45a8-bb46-7275ad7fbc8e",
  1218. "index_node_hash": "0189157697b3c6a418ccf8264a09699f25858975578f3467c76d6bfc94df1d73",
  1219. "hit_count": 0,
  1220. "enabled": true,
  1221. "disabled_at": null,
  1222. "disabled_by": null,
  1223. "status": "completed",
  1224. "created_by": "dbcb1ab5-90c8-41a7-8b78-73b235eb6f6f",
  1225. "created_at": 1728734540,
  1226. "indexing_at": 1728734552,
  1227. "completed_at": 1728734584,
  1228. "error": null,
  1229. "stopped_at": null,
  1230. "document": {
  1231. "id": "a8c6c36f-9f5d-4d7a-8472-f5d7b75d71d2",
  1232. "data_source_type": "upload_file",
  1233. "name": "readme.txt",
  1234. "doc_type": null
  1235. }
  1236. },
  1237. "score": 3.730463140527718e-05,
  1238. "tsne_position": null
  1239. }
  1240. ]
  1241. }
  1242. ```
  1243. </CodeGroup>
  1244. </Col>
  1245. </Row>
  1246. <hr className='ml-0 mr-0' />
  1247. <Row>
  1248. <Col>
  1249. ### Error message
  1250. <Properties>
  1251. <Property name='code' type='string' key='code'>
  1252. Error code
  1253. </Property>
  1254. </Properties>
  1255. <Properties>
  1256. <Property name='status' type='number' key='status'>
  1257. Error status
  1258. </Property>
  1259. </Properties>
  1260. <Properties>
  1261. <Property name='message' type='string' key='message'>
  1262. Error message
  1263. </Property>
  1264. </Properties>
  1265. </Col>
  1266. <Col>
  1267. <CodeGroup title="Example">
  1268. ```json {{ title: 'Response' }}
  1269. {
  1270. "code": "no_file_uploaded",
  1271. "message": "Please upload your file.",
  1272. "status": 400
  1273. }
  1274. ```
  1275. </CodeGroup>
  1276. </Col>
  1277. </Row>
  1278. <table className="max-w-auto border-collapse border border-slate-400" style={{ maxWidth: 'none', width: 'auto' }}>
  1279. <thead style={{ background: '#f9fafc' }}>
  1280. <tr>
  1281. <th className="p-2 border border-slate-300">code</th>
  1282. <th className="p-2 border border-slate-300">status</th>
  1283. <th className="p-2 border border-slate-300">message</th>
  1284. </tr>
  1285. </thead>
  1286. <tbody>
  1287. <tr>
  1288. <td className="p-2 border border-slate-300">no_file_uploaded</td>
  1289. <td className="p-2 border border-slate-300">400</td>
  1290. <td className="p-2 border border-slate-300">Please upload your file.</td>
  1291. </tr>
  1292. <tr>
  1293. <td className="p-2 border border-slate-300">too_many_files</td>
  1294. <td className="p-2 border border-slate-300">400</td>
  1295. <td className="p-2 border border-slate-300">Only one file is allowed.</td>
  1296. </tr>
  1297. <tr>
  1298. <td className="p-2 border border-slate-300">file_too_large</td>
  1299. <td className="p-2 border border-slate-300">413</td>
  1300. <td className="p-2 border border-slate-300">File size exceeded.</td>
  1301. </tr>
  1302. <tr>
  1303. <td className="p-2 border border-slate-300">unsupported_file_type</td>
  1304. <td className="p-2 border border-slate-300">415</td>
  1305. <td className="p-2 border border-slate-300">File type not allowed.</td>
  1306. </tr>
  1307. <tr>
  1308. <td className="p-2 border border-slate-300">high_quality_dataset_only</td>
  1309. <td className="p-2 border border-slate-300">400</td>
  1310. <td className="p-2 border border-slate-300">Current operation only supports 'high-quality' datasets.</td>
  1311. </tr>
  1312. <tr>
  1313. <td className="p-2 border border-slate-300">dataset_not_initialized</td>
  1314. <td className="p-2 border border-slate-300">400</td>
  1315. <td className="p-2 border border-slate-300">The dataset is still being initialized or indexing. Please wait a moment.</td>
  1316. </tr>
  1317. <tr>
  1318. <td className="p-2 border border-slate-300">archived_document_immutable</td>
  1319. <td className="p-2 border border-slate-300">403</td>
  1320. <td className="p-2 border border-slate-300">The archived document is not editable.</td>
  1321. </tr>
  1322. <tr>
  1323. <td className="p-2 border border-slate-300">dataset_name_duplicate</td>
  1324. <td className="p-2 border border-slate-300">409</td>
  1325. <td className="p-2 border border-slate-300">The dataset name already exists. Please modify your dataset name.</td>
  1326. </tr>
  1327. <tr>
  1328. <td className="p-2 border border-slate-300">invalid_action</td>
  1329. <td className="p-2 border border-slate-300">400</td>
  1330. <td className="p-2 border border-slate-300">Invalid action.</td>
  1331. </tr>
  1332. <tr>
  1333. <td className="p-2 border border-slate-300">document_already_finished</td>
  1334. <td className="p-2 border border-slate-300">400</td>
  1335. <td className="p-2 border border-slate-300">The document has been processed. Please refresh the page or go to the document details.</td>
  1336. </tr>
  1337. <tr>
  1338. <td className="p-2 border border-slate-300">document_indexing</td>
  1339. <td className="p-2 border border-slate-300">400</td>
  1340. <td className="p-2 border border-slate-300">The document is being processed and cannot be edited.</td>
  1341. </tr>
  1342. <tr>
  1343. <td className="p-2 border border-slate-300">invalid_metadata</td>
  1344. <td className="p-2 border border-slate-300">400</td>
  1345. <td className="p-2 border border-slate-300">The metadata content is incorrect. Please check and verify.</td>
  1346. </tr>
  1347. </tbody>
  1348. </table>
  1349. <div className="pb-4" />