template.en.mdx 58 KB

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