You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

template.en.mdx 77KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284
  1. {/**
  2. * @typedef Props
  3. * @property {string} apiBaseUrl
  4. */}
  5. import { CodeGroup } from '@/app/components/develop/code.tsx'
  6. import { Row, Col, Properties, Property, Heading, SubProperty, PropertyInstruction, Paragraph } from '@/app/components/develop/md.tsx'
  7. # Knowledge API
  8. <div>
  9. ### Authentication
  10. Service API of Dify authenticates using an `API-Key`.
  11. 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.
  12. All API requests should include your `API-Key` in the **`Authorization`** HTTP Header, as shown below:
  13. <CodeGroup title="Code">
  14. ```javascript
  15. Authorization: Bearer {API_KEY}
  16. ```
  17. </CodeGroup>
  18. </div>
  19. <hr className='ml-0 mr-0' />
  20. <Heading
  21. url='/datasets/{dataset_id}/document/create-by-text'
  22. method='POST'
  23. title='Create a Document from Text'
  24. name='#create-by-text'
  25. />
  26. <Row>
  27. <Col>
  28. This API is based on an existing knowledge and creates a new document through text based on this knowledge.
  29. ### Params
  30. <Properties>
  31. <Property name='dataset_id' type='string' key='dataset_id'>
  32. Knowledge ID
  33. </Property>
  34. </Properties>
  35. ### Request Body
  36. <Properties>
  37. <Property name='name' type='string' key='name'>
  38. Document name
  39. </Property>
  40. <Property name='text' type='string' key='text'>
  41. Document content
  42. </Property>
  43. <Property name='indexing_technique' type='string' key='indexing_technique'>
  44. Index mode
  45. - <code>high_quality</code> High quality: embedding using embedding model, built as vector database index
  46. - <code>economy</code> Economy: Build using inverted index of keyword table index
  47. </Property>
  48. <Property name='doc_form' type='string' key='doc_form'>
  49. Format of indexed content
  50. - <code>text_model</code> Text documents are directly embedded; `economy` mode defaults to using this form
  51. - <code>hierarchical_model</code> Parent-child mode
  52. - <code>qa_model</code> Q&A Mode: Generates Q&A pairs for segmented documents and then embeds the questions
  53. </Property>
  54. <Property name='doc_language' type='string' key='doc_language'>
  55. In Q&A mode, specify the language of the document, for example: <code>English</code>, <code>Chinese</code>
  56. </Property>
  57. <Property name='process_rule' type='object' key='process_rule'>
  58. Processing rules
  59. - <code>mode</code> (string) Cleaning, segmentation mode, automatic / custom
  60. - <code>rules</code> (object) Custom rules (in automatic mode, this field is empty)
  61. - <code>pre_processing_rules</code> (array[object]) Preprocessing rules
  62. - <code>id</code> (string) Unique identifier for the preprocessing rule
  63. - enumerate
  64. - <code>remove_extra_spaces</code> Replace consecutive spaces, newlines, tabs
  65. - <code>remove_urls_emails</code> Delete URL, email address
  66. - <code>enabled</code> (bool) Whether to select this rule or not. If no document ID is passed in, it represents the default value.
  67. - <code>segmentation</code> (object) Segmentation rules
  68. - <code>separator</code> Custom segment identifier, currently only allows one delimiter to be set. Default is \n
  69. - <code>max_tokens</code> Maximum length (token) defaults to 1000
  70. - <code>parent_mode</code> Retrieval mode of parent chunks: <code>full-doc</code> full text retrieval / <code>paragraph</code> paragraph retrieval
  71. - <code>subchunk_segmentation</code> (object) Child chunk rules
  72. - <code>separator</code> Segmentation identifier. Currently, only one delimiter is allowed. The default is <code>***</code>
  73. - <code>max_tokens</code> The maximum length (tokens) must be validated to be shorter than the length of the parent chunk
  74. - <code>chunk_overlap</code> Define the overlap between adjacent chunks (optional)
  75. </Property>
  76. <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>
  77. <Property name='retrieval_model' type='object' key='retrieval_model'>
  78. Retrieval model
  79. - <code>search_method</code> (string) Search method
  80. - <code>hybrid_search</code> Hybrid search
  81. - <code>semantic_search</code> Semantic search
  82. - <code>full_text_search</code> Full-text search
  83. - <code>reranking_enable</code> (bool) Whether to enable reranking
  84. - <code>reranking_mode</code> (object) Rerank model configuration
  85. - <code>reranking_provider_name</code> (string) Rerank model provider
  86. - <code>reranking_model_name</code> (string) Rerank model name
  87. - <code>top_k</code> (int) Number of results to return
  88. - <code>score_threshold_enabled</code> (bool) Whether to enable score threshold
  89. - <code>score_threshold</code> (float) Score threshold
  90. </Property>
  91. <Property name='embedding_model' type='string' key='embedding_model'>
  92. Embedding model name
  93. </Property>
  94. <Property name='embedding_model_provider' type='string' key='embedding_model_provider'>
  95. Embedding model provider
  96. </Property>
  97. </Properties>
  98. </Col>
  99. <Col sticky>
  100. <CodeGroup
  101. title="Request"
  102. tag="POST"
  103. label="/datasets/{dataset_id}/document/create-by-text"
  104. 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"}}'`}
  105. >
  106. ```bash {{ title: 'cURL' }}
  107. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/document/create-by-text' \
  108. --header 'Authorization: Bearer {api_key}' \
  109. --header 'Content-Type: application/json' \
  110. --data-raw '{
  111. "name": "text",
  112. "text": "text",
  113. "indexing_technique": "high_quality",
  114. "process_rule": {
  115. "mode": "automatic"
  116. }
  117. }'
  118. ```
  119. </CodeGroup>
  120. <CodeGroup title="Response">
  121. ```json {{ title: 'Response' }}
  122. {
  123. "document": {
  124. "id": "",
  125. "position": 1,
  126. "data_source_type": "upload_file",
  127. "data_source_info": {
  128. "upload_file_id": ""
  129. },
  130. "dataset_process_rule_id": "",
  131. "name": "text.txt",
  132. "created_from": "api",
  133. "created_by": "",
  134. "created_at": 1695690280,
  135. "tokens": 0,
  136. "indexing_status": "waiting",
  137. "error": null,
  138. "enabled": true,
  139. "disabled_at": null,
  140. "disabled_by": null,
  141. "archived": false,
  142. "display_status": "queuing",
  143. "word_count": 0,
  144. "hit_count": 0,
  145. "doc_form": "text_model"
  146. },
  147. "batch": ""
  148. }
  149. ```
  150. </CodeGroup>
  151. </Col>
  152. </Row>
  153. <hr className='ml-0 mr-0' />
  154. <Heading
  155. url='/datasets/{dataset_id}/document/create-by-file'
  156. method='POST'
  157. title='Create a Document from a File'
  158. name='#create-by-file'
  159. />
  160. <Row>
  161. <Col>
  162. This API is based on an existing knowledge and creates a new document through a file based on this knowledge.
  163. ### Params
  164. <Properties>
  165. <Property name='dataset_id' type='string' key='dataset_id'>
  166. Knowledge ID
  167. </Property>
  168. </Properties>
  169. ### Request Body
  170. <Properties>
  171. <Property name='data' type='multipart/form-data json string' key='data'>
  172. - <code>original_document_id</code> Source document ID (optional)
  173. - Used to re-upload the document or modify the document cleaning and segmentation configuration. The missing information is copied from the source document
  174. - The source document cannot be an archived document
  175. - 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
  176. - When original_document_id is not passed in, the new operation is performed on behalf of the document, and process_rule is required
  177. - <code>indexing_technique</code> Index mode
  178. - <code>high_quality</code> High quality: embedding using embedding model, built as vector database index
  179. - <code>economy</code> Economy: Build using inverted index of keyword table index
  180. - <code>doc_form</code> Format of indexed content
  181. - <code>text_model</code> Text documents are directly embedded; `economy` mode defaults to using this form
  182. - <code>hierarchical_model</code> Parent-child mode
  183. - <code>qa_model</code> Q&A Mode: Generates Q&A pairs for segmented documents and then embeds the questions
  184. - <code>doc_language</code> In Q&A mode, specify the language of the document, for example: <code>English</code>, <code>Chinese</code>
  185. - <code>process_rule</code> Processing rules
  186. - <code>mode</code> (string) Cleaning, segmentation mode, automatic / custom
  187. - <code>rules</code> (object) Custom rules (in automatic mode, this field is empty)
  188. - <code>pre_processing_rules</code> (array[object]) Preprocessing rules
  189. - <code>id</code> (string) Unique identifier for the preprocessing rule
  190. - enumerate
  191. - <code>remove_extra_spaces</code> Replace consecutive spaces, newlines, tabs
  192. - <code>remove_urls_emails</code> Delete URL, email address
  193. - <code>enabled</code> (bool) Whether to select this rule or not. If no document ID is passed in, it represents the default value.
  194. - <code>segmentation</code> (object) Segmentation rules
  195. - <code>separator</code> Custom segment identifier, currently only allows one delimiter to be set. Default is \n
  196. - <code>max_tokens</code> Maximum length (token) defaults to 1000
  197. - <code>parent_mode</code> Retrieval mode of parent chunks: <code>full-doc</code> full text retrieval / <code>paragraph</code> paragraph retrieval
  198. - <code>subchunk_segmentation</code> (object) Child chunk rules
  199. - <code>separator</code> Segmentation identifier. Currently, only one delimiter is allowed. The default is <code>***</code>
  200. - <code>max_tokens</code> The maximum length (tokens) must be validated to be shorter than the length of the parent chunk
  201. - <code>chunk_overlap</code> Define the overlap between adjacent chunks (optional)
  202. </Property>
  203. <Property name='file' type='multipart/form-data' key='file'>
  204. Files that need to be uploaded.
  205. </Property>
  206. <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>
  207. <Property name='retrieval_model' type='object' key='retrieval_model'>
  208. Retrieval model
  209. - <code>search_method</code> (string) Search method
  210. - <code>hybrid_search</code> Hybrid search
  211. - <code>semantic_search</code> Semantic search
  212. - <code>full_text_search</code> Full-text search
  213. - <code>reranking_enable</code> (bool) Whether to enable reranking
  214. - <code>reranking_mode</code> (object) Rerank model configuration
  215. - <code>reranking_provider_name</code> (string) Rerank model provider
  216. - <code>reranking_model_name</code> (string) Rerank model name
  217. - <code>top_k</code> (int) Number of results to return
  218. - <code>score_threshold_enabled</code> (bool) Whether to enable score threshold
  219. - <code>score_threshold</code> (float) Score threshold
  220. </Property>
  221. <Property name='embedding_model' type='string' key='embedding_model'>
  222. Embedding model name
  223. </Property>
  224. <Property name='embedding_model_provider' type='string' key='embedding_model_provider'>
  225. Embedding model provider
  226. </Property>
  227. </Properties>
  228. </Col>
  229. <Col sticky>
  230. <CodeGroup
  231. title="Request"
  232. tag="POST"
  233. label="/datasets/{dataset_id}/document/create-by-file"
  234. 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"'`}
  235. >
  236. ```bash {{ title: 'cURL' }}
  237. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/document/create-by-file' \
  238. --header 'Authorization: Bearer {api_key}' \
  239. --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' \
  240. --form 'file=@"/path/to/file"'
  241. ```
  242. </CodeGroup>
  243. <CodeGroup title="Response">
  244. ```json {{ title: 'Response' }}
  245. {
  246. "document": {
  247. "id": "",
  248. "position": 1,
  249. "data_source_type": "upload_file",
  250. "data_source_info": {
  251. "upload_file_id": ""
  252. },
  253. "dataset_process_rule_id": "",
  254. "name": "Dify.txt",
  255. "created_from": "api",
  256. "created_by": "",
  257. "created_at": 1695308667,
  258. "tokens": 0,
  259. "indexing_status": "waiting",
  260. "error": null,
  261. "enabled": true,
  262. "disabled_at": null,
  263. "disabled_by": null,
  264. "archived": false,
  265. "display_status": "queuing",
  266. "word_count": 0,
  267. "hit_count": 0,
  268. "doc_form": "text_model"
  269. },
  270. "batch": ""
  271. }
  272. ```
  273. </CodeGroup>
  274. </Col>
  275. </Row>
  276. <hr className='ml-0 mr-0' />
  277. <Heading
  278. url='/datasets'
  279. method='POST'
  280. title='Create an Empty Knowledge Base'
  281. name='#create_empty_dataset'
  282. />
  283. <Row>
  284. <Col>
  285. ### Request Body
  286. <Properties>
  287. <Property name='name' type='string' key='name'>
  288. Knowledge name
  289. </Property>
  290. <Property name='description' type='string' key='description'>
  291. Knowledge description (optional)
  292. </Property>
  293. <Property name='indexing_technique' type='string' key='indexing_technique'>
  294. Index technique (optional)
  295. - <code>high_quality</code> High quality
  296. - <code>economy</code> Economy
  297. </Property>
  298. <Property name='permission' type='string' key='permission'>
  299. Permission
  300. - <code>only_me</code> Only me
  301. - <code>all_team_members</code> All team members
  302. - <code>partial_members</code> Partial members
  303. </Property>
  304. <Property name='provider' type='string' key='provider'>
  305. Provider (optional, default: vendor)
  306. - <code>vendor</code> Vendor
  307. - <code>external</code> External knowledge
  308. </Property>
  309. <Property name='external_knowledge_api_id' type='str' key='external_knowledge_api_id'>
  310. External knowledge API ID (optional)
  311. </Property>
  312. <Property name='external_knowledge_id' type='str' key='external_knowledge_id'>
  313. External knowledge ID (optional)
  314. </Property>
  315. </Properties>
  316. </Col>
  317. <Col sticky>
  318. <CodeGroup
  319. title="Request"
  320. tag="POST"
  321. label="/datasets"
  322. 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"}'`}
  323. >
  324. ```bash {{ title: 'cURL' }}
  325. curl --location --request POST '${apiBaseUrl}/v1/datasets' \
  326. --header 'Authorization: Bearer {api_key}' \
  327. --header 'Content-Type: application/json' \
  328. --data-raw '{
  329. "name": "name",
  330. "permission": "only_me"
  331. }'
  332. ```
  333. </CodeGroup>
  334. <CodeGroup title="Response">
  335. ```json {{ title: 'Response' }}
  336. {
  337. "id": "",
  338. "name": "name",
  339. "description": null,
  340. "provider": "vendor",
  341. "permission": "only_me",
  342. "data_source_type": null,
  343. "indexing_technique": null,
  344. "app_count": 0,
  345. "document_count": 0,
  346. "word_count": 0,
  347. "created_by": "",
  348. "created_at": 1695636173,
  349. "updated_by": "",
  350. "updated_at": 1695636173,
  351. "embedding_model": null,
  352. "embedding_model_provider": null,
  353. "embedding_available": null
  354. }
  355. ```
  356. </CodeGroup>
  357. </Col>
  358. </Row>
  359. <hr className='ml-0 mr-0' />
  360. <Heading
  361. url='/datasets'
  362. method='GET'
  363. title='Get Knowledge Base List'
  364. name='#dataset_list'
  365. />
  366. <Row>
  367. <Col>
  368. ### Query
  369. <Properties>
  370. <Property name='keyword' type='string' key='keyword'>
  371. Search keyword, optional
  372. </Property>
  373. <Property name='tag_ids' type='array[string]' key='tag_ids'>
  374. Tag ID list, optional
  375. </Property>
  376. <Property name='page' type='string' key='page'>
  377. Page number, optional, default 1
  378. </Property>
  379. <Property name='limit' type='string' key='limit'>
  380. Number of items returned, optional, default 20, range 1-100
  381. </Property>
  382. <Property name='include_all' type='boolean' key='include_all'>
  383. Whether to include all datasets (only effective for owners), optional, defaults to false
  384. </Property>
  385. </Properties>
  386. </Col>
  387. <Col sticky>
  388. <CodeGroup
  389. title="Request"
  390. tag="GET"
  391. label="/datasets"
  392. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets?page=1&limit=20' \\\n--header 'Authorization: Bearer {api_key}'`}
  393. >
  394. ```bash {{ title: 'cURL' }}
  395. curl --location --request GET '${props.apiBaseUrl}/datasets?page=1&limit=20' \
  396. --header 'Authorization: Bearer {api_key}'
  397. ```
  398. </CodeGroup>
  399. <CodeGroup title="Response">
  400. ```json {{ title: 'Response' }}
  401. {
  402. "data": [
  403. {
  404. "id": "",
  405. "name": "name",
  406. "description": "desc",
  407. "permission": "only_me",
  408. "data_source_type": "upload_file",
  409. "indexing_technique": "",
  410. "app_count": 2,
  411. "document_count": 10,
  412. "word_count": 1200,
  413. "created_by": "",
  414. "created_at": "",
  415. "updated_by": "",
  416. "updated_at": ""
  417. },
  418. ...
  419. ],
  420. "has_more": true,
  421. "limit": 20,
  422. "total": 50,
  423. "page": 1
  424. }
  425. ```
  426. </CodeGroup>
  427. </Col>
  428. </Row>
  429. <hr className='ml-0 mr-0' />
  430. <Heading
  431. url='/datasets/{dataset_id}'
  432. method='GET'
  433. title='Get knowledge base details by knowledge base ID'
  434. name='#view_dataset'
  435. />
  436. <Row>
  437. <Col>
  438. ### Query
  439. <Properties>
  440. <Property name='dataset_id' type='string' key='dataset_id'>
  441. Knowledge Base ID
  442. </Property>
  443. </Properties>
  444. </Col>
  445. <Col sticky>
  446. <CodeGroup
  447. title="Request"
  448. tag="GET"
  449. label="/datasets/{dataset_id}"
  450. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  451. >
  452. ```bash {{ title: 'cURL' }}
  453. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}' \
  454. --header 'Authorization: Bearer {api_key}'
  455. ```
  456. </CodeGroup>
  457. <CodeGroup title="Response">
  458. ```json {{ title: 'Response' }}
  459. {
  460. "id": "eaedb485-95ac-4ffd-ab1e-18da6d676a2f",
  461. "name": "Test Knowledge Base",
  462. "description": "",
  463. "provider": "vendor",
  464. "permission": "only_me",
  465. "data_source_type": null,
  466. "indexing_technique": null,
  467. "app_count": 0,
  468. "document_count": 0,
  469. "word_count": 0,
  470. "created_by": "e99a1635-f725-4951-a99a-1daaaa76cfc6",
  471. "created_at": 1735620612,
  472. "updated_by": "e99a1635-f725-4951-a99a-1daaaa76cfc6",
  473. "updated_at": 1735620612,
  474. "embedding_model": null,
  475. "embedding_model_provider": null,
  476. "embedding_available": true,
  477. "retrieval_model_dict": {
  478. "search_method": "semantic_search",
  479. "reranking_enable": false,
  480. "reranking_mode": null,
  481. "reranking_model": {
  482. "reranking_provider_name": "",
  483. "reranking_model_name": ""
  484. },
  485. "weights": null,
  486. "top_k": 2,
  487. "score_threshold_enabled": false,
  488. "score_threshold": null
  489. },
  490. "tags": [],
  491. "doc_form": null,
  492. "external_knowledge_info": {
  493. "external_knowledge_id": null,
  494. "external_knowledge_api_id": null,
  495. "external_knowledge_api_name": null,
  496. "external_knowledge_api_endpoint": null
  497. },
  498. "external_retrieval_model": {
  499. "top_k": 2,
  500. "score_threshold": 0.0,
  501. "score_threshold_enabled": null
  502. }
  503. }
  504. ```
  505. </CodeGroup>
  506. </Col>
  507. </Row>
  508. <hr className='ml-0 mr-0' />
  509. <Heading
  510. url='/datasets/{dataset_id}'
  511. method='POST'
  512. title='Update knowledge base'
  513. name='#update_dataset'
  514. />
  515. <Row>
  516. <Col>
  517. ### Query
  518. <Properties>
  519. <Property name='dataset_id' type='string' key='dataset_id'>
  520. Knowledge Base ID
  521. </Property>
  522. <Property name='indexing_technique' type='string' key='indexing_technique'>
  523. Index technique (optional)
  524. - <code>high_quality</code> High quality
  525. - <code>economy</code> Economy
  526. </Property>
  527. <Property name='permission' type='string' key='permission'>
  528. Permission
  529. - <code>only_me</code> Only me
  530. - <code>all_team_members</code> All team members
  531. - <code>partial_members</code> Partial members
  532. </Property>
  533. <Property name='embedding_model_provider' type='string' key='embedding_model_provider'>
  534. Specified embedding model provider, must be set up in the system first, corresponding to the provider field(Optional)
  535. </Property>
  536. <Property name='embedding_model' type='string' key='embedding_model'>
  537. Specified embedding model, corresponding to the model field(Optional)
  538. </Property>
  539. <Property name='retrieval_model' type='string' key='retrieval_model'>
  540. Specified retrieval model, corresponding to the model field(Optional)
  541. </Property>
  542. <Property name='partial_member_list' type='array' key='partial_member_list'>
  543. Partial member list(Optional)
  544. </Property>
  545. </Properties>
  546. </Col>
  547. <Col sticky>
  548. <CodeGroup
  549. title="Request"
  550. tag="POST"
  551. label="/datasets/{dataset_id}"
  552. targetCode={`curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{"name": "Test Knowledge Base", "indexing_technique": "high_quality", "permission": "only_me", "embedding_model_provider": "zhipuai", "embedding_model": "embedding-3", "retrieval_model": "", "partial_member_list": []}' `}
  553. >
  554. ```bash {{ title: 'cURL' }}
  555. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}' \
  556. --header 'Authorization: Bearer {api_key}' \
  557. --header 'Content-Type: application/json' \
  558. --data-raw '{"name": "Test Knowledge Base", "indexing_technique": "high_quality", "permission": "only_me",\
  559. "embedding_model_provider": "zhipuai", "embedding_model": "embedding-3", "retrieval_model": "", "partial_member_list": []}'
  560. ```
  561. </CodeGroup>
  562. <CodeGroup title="Response">
  563. ```json {{ title: 'Response' }}
  564. {
  565. "id": "eaedb485-95ac-4ffd-ab1e-18da6d676a2f",
  566. "name": "Test Knowledge Base",
  567. "description": "",
  568. "provider": "vendor",
  569. "permission": "only_me",
  570. "data_source_type": null,
  571. "indexing_technique": "high_quality",
  572. "app_count": 0,
  573. "document_count": 0,
  574. "word_count": 0,
  575. "created_by": "e99a1635-f725-4951-a99a-1daaaa76cfc6",
  576. "created_at": 1735620612,
  577. "updated_by": "e99a1635-f725-4951-a99a-1daaaa76cfc6",
  578. "updated_at": 1735622679,
  579. "embedding_model": "embedding-3",
  580. "embedding_model_provider": "zhipuai",
  581. "embedding_available": null,
  582. "retrieval_model_dict": {
  583. "search_method": "semantic_search",
  584. "reranking_enable": false,
  585. "reranking_mode": null,
  586. "reranking_model": {
  587. "reranking_provider_name": "",
  588. "reranking_model_name": ""
  589. },
  590. "weights": null,
  591. "top_k": 2,
  592. "score_threshold_enabled": false,
  593. "score_threshold": null
  594. },
  595. "tags": [],
  596. "doc_form": null,
  597. "external_knowledge_info": {
  598. "external_knowledge_id": null,
  599. "external_knowledge_api_id": null,
  600. "external_knowledge_api_name": null,
  601. "external_knowledge_api_endpoint": null
  602. },
  603. "external_retrieval_model": {
  604. "top_k": 2,
  605. "score_threshold": 0.0,
  606. "score_threshold_enabled": null
  607. },
  608. "partial_member_list": []
  609. }
  610. ```
  611. </CodeGroup>
  612. </Col>
  613. </Row>
  614. <hr className='ml-0 mr-0' />
  615. <Heading
  616. url='/datasets/{dataset_id}'
  617. method='DELETE'
  618. title='Delete a Knowledge Base'
  619. name='#delete_dataset'
  620. />
  621. <Row>
  622. <Col>
  623. ### Params
  624. <Properties>
  625. <Property name='dataset_id' type='string' key='dataset_id'>
  626. Knowledge ID
  627. </Property>
  628. </Properties>
  629. </Col>
  630. <Col sticky>
  631. <CodeGroup
  632. title="Request"
  633. tag="DELETE"
  634. label="/datasets/{dataset_id}"
  635. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  636. >
  637. ```bash {{ title: 'cURL' }}
  638. curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}' \
  639. --header 'Authorization: Bearer {api_key}'
  640. ```
  641. </CodeGroup>
  642. <CodeGroup title="Response">
  643. ```text {{ title: 'Response' }}
  644. 204 No Content
  645. ```
  646. </CodeGroup>
  647. </Col>
  648. </Row>
  649. <hr className='ml-0 mr-0' />
  650. <Heading
  651. url='/datasets/{dataset_id}/documents/{document_id}/update-by-text'
  652. method='POST'
  653. title='Update a Document with Text'
  654. name='#update-by-text'
  655. />
  656. <Row>
  657. <Col>
  658. This API is based on an existing knowledge and updates the document through text based on this knowledge.
  659. ### Params
  660. <Properties>
  661. <Property name='dataset_id' type='string' key='dataset_id'>
  662. Knowledge ID
  663. </Property>
  664. <Property name='document_id' type='string' key='document_id'>
  665. Document ID
  666. </Property>
  667. </Properties>
  668. ### Request Body
  669. <Properties>
  670. <Property name='name' type='string' key='name'>
  671. Document name (optional)
  672. </Property>
  673. <Property name='text' type='string' key='text'>
  674. Document content (optional)
  675. </Property>
  676. <Property name='process_rule' type='object' key='process_rule'>
  677. Processing rules
  678. - <code>mode</code> (string) Cleaning, segmentation mode, automatic / custom
  679. - <code>rules</code> (object) Custom rules (in automatic mode, this field is empty)
  680. - <code>pre_processing_rules</code> (array[object]) Preprocessing rules
  681. - <code>id</code> (string) Unique identifier for the preprocessing rule
  682. - enumerate
  683. - <code>remove_extra_spaces</code> Replace consecutive spaces, newlines, tabs
  684. - <code>remove_urls_emails</code> Delete URL, email address
  685. - <code>enabled</code> (bool) Whether to select this rule or not. If no document ID is passed in, it represents the default value.
  686. - <code>segmentation</code> (object) Segmentation rules
  687. - <code>separator</code> Custom segment identifier, currently only allows one delimiter to be set. Default is \n
  688. - <code>max_tokens</code> Maximum length (token) defaults to 1000
  689. - <code>parent_mode</code> Retrieval mode of parent chunks: <code>full-doc</code> full text retrieval / <code>paragraph</code> paragraph retrieval
  690. - <code>subchunk_segmentation</code> (object) Child chunk rules
  691. - <code>separator</code> Segmentation identifier. Currently, only one delimiter is allowed. The default is <code>***</code>
  692. - <code>max_tokens</code> The maximum length (tokens) must be validated to be shorter than the length of the parent chunk
  693. - <code>chunk_overlap</code> Define the overlap between adjacent chunks (optional)
  694. </Property>
  695. </Properties>
  696. </Col>
  697. <Col sticky>
  698. <CodeGroup
  699. title="Request"
  700. tag="POST"
  701. label="/datasets/{dataset_id}/documents/{document_id}/update-by-text"
  702. 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"}'`}
  703. >
  704. ```bash {{ title: 'cURL' }}
  705. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/update-by-text' \
  706. --header 'Authorization: Bearer {api_key}' \
  707. --header 'Content-Type: application/json' \
  708. --data-raw '{
  709. "name": "name",
  710. "text": "text"
  711. }'
  712. ```
  713. </CodeGroup>
  714. <CodeGroup title="Response">
  715. ```json {{ title: 'Response' }}
  716. {
  717. "document": {
  718. "id": "",
  719. "position": 1,
  720. "data_source_type": "upload_file",
  721. "data_source_info": {
  722. "upload_file_id": ""
  723. },
  724. "dataset_process_rule_id": "",
  725. "name": "name.txt",
  726. "created_from": "api",
  727. "created_by": "",
  728. "created_at": 1695308667,
  729. "tokens": 0,
  730. "indexing_status": "waiting",
  731. "error": null,
  732. "enabled": true,
  733. "disabled_at": null,
  734. "disabled_by": null,
  735. "archived": false,
  736. "display_status": "queuing",
  737. "word_count": 0,
  738. "hit_count": 0,
  739. "doc_form": "text_model"
  740. },
  741. "batch": ""
  742. }
  743. ```
  744. </CodeGroup>
  745. </Col>
  746. </Row>
  747. <hr className='ml-0 mr-0' />
  748. <Heading
  749. url='/datasets/{dataset_id}/documents/{document_id}/update-by-file'
  750. method='POST'
  751. title='Update a Document with a File'
  752. name='#update-by-file'
  753. />
  754. <Row>
  755. <Col>
  756. This API is based on an existing knowledge, and updates documents through files based on this knowledge
  757. ### Params
  758. <Properties>
  759. <Property name='dataset_id' type='string' key='dataset_id'>
  760. Knowledge ID
  761. </Property>
  762. <Property name='document_id' type='string' key='document_id'>
  763. Document ID
  764. </Property>
  765. </Properties>
  766. ### Request Body
  767. <Properties>
  768. <Property name='name' type='string' key='name'>
  769. Document name (optional)
  770. </Property>
  771. <Property name='file' type='multipart/form-data' key='file'>
  772. Files to be uploaded
  773. </Property>
  774. <Property name='process_rule' type='object' key='process_rule'>
  775. Processing rules
  776. - <code>mode</code> (string) Cleaning, segmentation mode, automatic / custom
  777. - <code>rules</code> (object) Custom rules (in automatic mode, this field is empty)
  778. - <code>pre_processing_rules</code> (array[object]) Preprocessing rules
  779. - <code>id</code> (string) Unique identifier for the preprocessing rule
  780. - enumerate
  781. - <code>remove_extra_spaces</code> Replace consecutive spaces, newlines, tabs
  782. - <code>remove_urls_emails</code> Delete URL, email address
  783. - <code>enabled</code> (bool) Whether to select this rule or not. If no document ID is passed in, it represents the default value.
  784. - <code>segmentation</code> (object) Segmentation rules
  785. - <code>separator</code> Custom segment identifier, currently only allows one delimiter to be set. Default is \n
  786. - <code>max_tokens</code> Maximum length (token) defaults to 1000
  787. - <code>parent_mode</code> Retrieval mode of parent chunks: <code>full-doc</code> full text retrieval / <code>paragraph</code> paragraph retrieval
  788. - <code>subchunk_segmentation</code> (object) Child chunk rules
  789. - <code>separator</code> Segmentation identifier. Currently, only one delimiter is allowed. The default is <code>***</code>
  790. - <code>max_tokens</code> The maximum length (tokens) must be validated to be shorter than the length of the parent chunk
  791. - <code>chunk_overlap</code> Define the overlap between adjacent chunks (optional)
  792. </Property>
  793. </Properties>
  794. </Col>
  795. <Col sticky>
  796. <CodeGroup
  797. title="Request"
  798. tag="POST"
  799. label="/datasets/{dataset_id}/documents/{document_id}/update-by-file"
  800. 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"'`}
  801. >
  802. ```bash {{ title: 'cURL' }}
  803. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/update-by-file' \
  804. --header 'Authorization: Bearer {api_key}' \
  805. --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' \
  806. --form 'file=@"/path/to/file"'
  807. ```
  808. </CodeGroup>
  809. <CodeGroup title="Response">
  810. ```json {{ title: 'Response' }}
  811. {
  812. "document": {
  813. "id": "",
  814. "position": 1,
  815. "data_source_type": "upload_file",
  816. "data_source_info": {
  817. "upload_file_id": ""
  818. },
  819. "dataset_process_rule_id": "",
  820. "name": "Dify.txt",
  821. "created_from": "api",
  822. "created_by": "",
  823. "created_at": 1695308667,
  824. "tokens": 0,
  825. "indexing_status": "waiting",
  826. "error": null,
  827. "enabled": true,
  828. "disabled_at": null,
  829. "disabled_by": null,
  830. "archived": false,
  831. "display_status": "queuing",
  832. "word_count": 0,
  833. "hit_count": 0,
  834. "doc_form": "text_model"
  835. },
  836. "batch": "20230921150427533684"
  837. }
  838. ```
  839. </CodeGroup>
  840. </Col>
  841. </Row>
  842. <hr className='ml-0 mr-0' />
  843. <Heading
  844. url='/datasets/{dataset_id}/documents/{batch}/indexing-status'
  845. method='GET'
  846. title='Get Document Embedding Status (Progress)'
  847. name='#indexing_status'
  848. />
  849. <Row>
  850. <Col>
  851. ### Params
  852. <Properties>
  853. <Property name='dataset_id' type='string' key='dataset_id'>
  854. Knowledge ID
  855. </Property>
  856. <Property name='batch' type='string' key='batch'>
  857. Batch number of uploaded documents
  858. </Property>
  859. </Properties>
  860. </Col>
  861. <Col sticky>
  862. <CodeGroup
  863. title="Request"
  864. tag="GET"
  865. label="/datasets/{dataset_id}/documents/{batch}/indexing-status"
  866. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{batch}/indexing-status' \\\n--header 'Authorization: Bearer {api_key}'`}
  867. >
  868. ```bash {{ title: 'cURL' }}
  869. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{batch}/indexing-status' \
  870. --header 'Authorization: Bearer {api_key}' \
  871. ```
  872. </CodeGroup>
  873. <CodeGroup title="Response">
  874. ```json {{ title: 'Response' }}
  875. {
  876. "data":[{
  877. "id": "",
  878. "indexing_status": "indexing",
  879. "processing_started_at": 1681623462.0,
  880. "parsing_completed_at": 1681623462.0,
  881. "cleaning_completed_at": 1681623462.0,
  882. "splitting_completed_at": 1681623462.0,
  883. "completed_at": null,
  884. "paused_at": null,
  885. "error": null,
  886. "stopped_at": null,
  887. "completed_segments": 24,
  888. "total_segments": 100
  889. }]
  890. }
  891. ```
  892. </CodeGroup>
  893. </Col>
  894. </Row>
  895. <hr className='ml-0 mr-0' />
  896. <Heading
  897. url='/datasets/{dataset_id}/documents/{document_id}'
  898. method='DELETE'
  899. title='Delete a Document'
  900. name='#delete_document'
  901. />
  902. <Row>
  903. <Col>
  904. ### Params
  905. <Properties>
  906. <Property name='dataset_id' type='string' key='dataset_id'>
  907. Knowledge ID
  908. </Property>
  909. <Property name='document_id' type='string' key='document_id'>
  910. Document ID
  911. </Property>
  912. </Properties>
  913. </Col>
  914. <Col sticky>
  915. <CodeGroup
  916. title="Request"
  917. tag="DELETE"
  918. label="/datasets/{dataset_id}/documents/{document_id}"
  919. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  920. >
  921. ```bash {{ title: 'cURL' }}
  922. curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}' \
  923. --header 'Authorization: Bearer {api_key}' \
  924. ```
  925. </CodeGroup>
  926. <CodeGroup title="Response">
  927. ```json {{ title: 'Response' }}
  928. {
  929. "result": "success"
  930. }
  931. ```
  932. </CodeGroup>
  933. </Col>
  934. </Row>
  935. <hr className='ml-0 mr-0' />
  936. <Heading
  937. url='/datasets/{dataset_id}/documents'
  938. method='GET'
  939. title='Get the Document List of a Knowledge Base'
  940. name='#dataset_document_list'
  941. />
  942. <Row>
  943. <Col>
  944. ### Params
  945. <Properties>
  946. <Property name='dataset_id' type='string' key='dataset_id'>
  947. Knowledge ID
  948. </Property>
  949. </Properties>
  950. ### Query
  951. <Properties>
  952. <Property name='keyword' type='string' key='keyword'>
  953. Search keywords, currently only search document names (optional)
  954. </Property>
  955. <Property name='page' type='string' key='page'>
  956. Page number (optional)
  957. </Property>
  958. <Property name='limit' type='string' key='limit'>
  959. Number of items returned, default 20, range 1-100 (optional)
  960. </Property>
  961. </Properties>
  962. </Col>
  963. <Col sticky>
  964. <CodeGroup
  965. title="Request"
  966. tag="GET"
  967. label="/datasets/{dataset_id}/documents"
  968. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents' \\\n--header 'Authorization: Bearer {api_key}'`}
  969. >
  970. ```bash {{ title: 'cURL' }}
  971. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents' \
  972. --header 'Authorization: Bearer {api_key}' \
  973. ```
  974. </CodeGroup>
  975. <CodeGroup title="Response">
  976. ```json {{ title: 'Response' }}
  977. {
  978. "data": [
  979. {
  980. "id": "",
  981. "position": 1,
  982. "data_source_type": "file_upload",
  983. "data_source_info": null,
  984. "dataset_process_rule_id": null,
  985. "name": "dify",
  986. "created_from": "",
  987. "created_by": "",
  988. "created_at": 1681623639,
  989. "tokens": 0,
  990. "indexing_status": "waiting",
  991. "error": null,
  992. "enabled": true,
  993. "disabled_at": null,
  994. "disabled_by": null,
  995. "archived": false
  996. },
  997. ],
  998. "has_more": false,
  999. "limit": 20,
  1000. "total": 9,
  1001. "page": 1
  1002. }
  1003. ```
  1004. </CodeGroup>
  1005. </Col>
  1006. </Row>
  1007. <hr className='ml-0 mr-0' />
  1008. <Heading
  1009. url='/datasets/{dataset_id}/documents/{document_id}/segments'
  1010. method='POST'
  1011. title='Add Chunks to a Document'
  1012. name='#create_new_segment'
  1013. />
  1014. <Row>
  1015. <Col>
  1016. ### Params
  1017. <Properties>
  1018. <Property name='dataset_id' type='string' key='dataset_id'>
  1019. Knowledge ID
  1020. </Property>
  1021. <Property name='document_id' type='string' key='document_id'>
  1022. Document ID
  1023. </Property>
  1024. </Properties>
  1025. ### Request Body
  1026. <Properties>
  1027. <Property name='segments' type='object list' key='segments'>
  1028. - <code>content</code> (text) Text content / question content, required
  1029. - <code>answer</code> (text) Answer content, if the mode of the knowledge is Q&A mode, pass the value (optional)
  1030. - <code>keywords</code> (list) Keywords (optional)
  1031. </Property>
  1032. </Properties>
  1033. </Col>
  1034. <Col sticky>
  1035. <CodeGroup
  1036. title="Request"
  1037. tag="POST"
  1038. label="/datasets/{dataset_id}/documents/{document_id}/segments"
  1039. 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"]}]}'`}
  1040. >
  1041. ```bash {{ title: 'cURL' }}
  1042. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments' \
  1043. --header 'Authorization: Bearer {api_key}' \
  1044. --header 'Content-Type: application/json' \
  1045. --data-raw '{
  1046. "segments": [
  1047. {
  1048. "content": "1",
  1049. "answer": "1",
  1050. "keywords": ["a"]
  1051. }
  1052. ]
  1053. }'
  1054. ```
  1055. </CodeGroup>
  1056. <CodeGroup title="Response">
  1057. ```json {{ title: 'Response' }}
  1058. {
  1059. "data": [{
  1060. "id": "",
  1061. "position": 1,
  1062. "document_id": "",
  1063. "content": "1",
  1064. "answer": "1",
  1065. "word_count": 25,
  1066. "tokens": 0,
  1067. "keywords": [
  1068. "a"
  1069. ],
  1070. "index_node_id": "",
  1071. "index_node_hash": "",
  1072. "hit_count": 0,
  1073. "enabled": true,
  1074. "disabled_at": null,
  1075. "disabled_by": null,
  1076. "status": "completed",
  1077. "created_by": "",
  1078. "created_at": 1695312007,
  1079. "indexing_at": 1695312007,
  1080. "completed_at": 1695312007,
  1081. "error": null,
  1082. "stopped_at": null
  1083. }],
  1084. "doc_form": "text_model"
  1085. }
  1086. ```
  1087. </CodeGroup>
  1088. </Col>
  1089. </Row>
  1090. <hr className='ml-0 mr-0' />
  1091. <Heading
  1092. url='/datasets/{dataset_id}/documents/{document_id}/segments'
  1093. method='GET'
  1094. title='Get Chunks from a Document'
  1095. name='#get_segment'
  1096. />
  1097. <Row>
  1098. <Col>
  1099. ### Path
  1100. <Properties>
  1101. <Property name='dataset_id' type='string' key='dataset_id'>
  1102. Knowledge ID
  1103. </Property>
  1104. <Property name='document_id' type='string' key='document_id'>
  1105. Document ID
  1106. </Property>
  1107. </Properties>
  1108. ### Query
  1109. <Properties>
  1110. <Property name='keyword' type='string' key='keyword'>
  1111. Keyword (optional)
  1112. </Property>
  1113. <Property name='status' type='string' key='status'>
  1114. Search status, completed
  1115. </Property>
  1116. <Property name='page' type='string' key='page'>
  1117. Page number (optional)
  1118. </Property>
  1119. <Property name='limit' type='string' key='limit'>
  1120. Number of items returned, default 20, range 1-100 (optional)
  1121. </Property>
  1122. </Properties>
  1123. </Col>
  1124. <Col sticky>
  1125. <CodeGroup
  1126. title="Request"
  1127. tag="GET"
  1128. label="/datasets/{dataset_id}/documents/{document_id}/segments"
  1129. 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'`}
  1130. >
  1131. ```bash {{ title: 'cURL' }}
  1132. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments' \
  1133. --header 'Authorization: Bearer {api_key}' \
  1134. --header 'Content-Type: application/json'
  1135. ```
  1136. </CodeGroup>
  1137. <CodeGroup title="Response">
  1138. ```json {{ title: 'Response' }}
  1139. {
  1140. "data": [{
  1141. "id": "",
  1142. "position": 1,
  1143. "document_id": "",
  1144. "content": "1",
  1145. "answer": "1",
  1146. "word_count": 25,
  1147. "tokens": 0,
  1148. "keywords": [
  1149. "a"
  1150. ],
  1151. "index_node_id": "",
  1152. "index_node_hash": "",
  1153. "hit_count": 0,
  1154. "enabled": true,
  1155. "disabled_at": null,
  1156. "disabled_by": null,
  1157. "status": "completed",
  1158. "created_by": "",
  1159. "created_at": 1695312007,
  1160. "indexing_at": 1695312007,
  1161. "completed_at": 1695312007,
  1162. "error": null,
  1163. "stopped_at": null
  1164. }],
  1165. "doc_form": "text_model",
  1166. "has_more": false,
  1167. "limit": 20,
  1168. "total": 9,
  1169. "page": 1
  1170. }
  1171. ```
  1172. </CodeGroup>
  1173. </Col>
  1174. </Row>
  1175. <hr className='ml-0 mr-0' />
  1176. <Heading
  1177. url='/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}'
  1178. method='DELETE'
  1179. title='Delete a Chunk in a Document'
  1180. name='#delete_segment'
  1181. />
  1182. <Row>
  1183. <Col>
  1184. ### Path
  1185. <Properties>
  1186. <Property name='dataset_id' type='string' key='dataset_id'>
  1187. Knowledge ID
  1188. </Property>
  1189. <Property name='document_id' type='string' key='document_id'>
  1190. Document ID
  1191. </Property>
  1192. <Property name='segment_id' type='string' key='segment_id'>
  1193. Document Segment ID
  1194. </Property>
  1195. </Properties>
  1196. </Col>
  1197. <Col sticky>
  1198. <CodeGroup
  1199. title="Request"
  1200. tag="DELETE"
  1201. label="/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}"
  1202. 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'`}
  1203. >
  1204. ```bash {{ title: 'cURL' }}
  1205. curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/segments/{segment_id}' \
  1206. --header 'Authorization: Bearer {api_key}' \
  1207. --header 'Content-Type: application/json'
  1208. ```
  1209. </CodeGroup>
  1210. <CodeGroup title="Response">
  1211. ```json {{ title: 'Response' }}
  1212. {
  1213. "result": "success"
  1214. }
  1215. ```
  1216. </CodeGroup>
  1217. </Col>
  1218. </Row>
  1219. <hr className='ml-0 mr-0' />
  1220. <Heading
  1221. url='/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}'
  1222. method='POST'
  1223. title='Update a Chunk in a Document'
  1224. name='#update_segment'
  1225. />
  1226. <Row>
  1227. <Col>
  1228. ### POST
  1229. <Properties>
  1230. <Property name='dataset_id' type='string' key='dataset_id'>
  1231. Knowledge ID
  1232. </Property>
  1233. <Property name='document_id' type='string' key='document_id'>
  1234. Document ID
  1235. </Property>
  1236. <Property name='segment_id' type='string' key='segment_id'>
  1237. Document Segment ID
  1238. </Property>
  1239. </Properties>
  1240. ### Request Body
  1241. <Properties>
  1242. <Property name='segment' type='object' key='segment'>
  1243. - <code>content</code> (text) Text content / question content, required
  1244. - <code>answer</code> (text) Answer content, passed if the knowledge is in Q&A mode (optional)
  1245. - <code>keywords</code> (list) Keyword (optional)
  1246. - <code>enabled</code> (bool) False / true (optional)
  1247. - <code>regenerate_child_chunks</code> (bool) Whether to regenerate child chunks (optional)
  1248. </Property>
  1249. </Properties>
  1250. </Col>
  1251. <Col sticky>
  1252. <CodeGroup
  1253. title="Request"
  1254. tag="POST"
  1255. label="/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}"
  1256. 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}}'`}
  1257. >
  1258. ```bash {{ title: 'cURL' }}
  1259. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}' \
  1260. --header 'Content-Type: application/json' \
  1261. --data-raw '{
  1262. "segment": {
  1263. "content": "1",
  1264. "answer": "1",
  1265. "keywords": ["a"],
  1266. "enabled": false
  1267. }
  1268. }'
  1269. ```
  1270. </CodeGroup>
  1271. <CodeGroup title="Response">
  1272. ```json {{ title: 'Response' }}
  1273. {
  1274. "data": {
  1275. "id": "",
  1276. "position": 1,
  1277. "document_id": "",
  1278. "content": "1",
  1279. "answer": "1",
  1280. "word_count": 25,
  1281. "tokens": 0,
  1282. "keywords": [
  1283. "a"
  1284. ],
  1285. "index_node_id": "",
  1286. "index_node_hash": "",
  1287. "hit_count": 0,
  1288. "enabled": true,
  1289. "disabled_at": null,
  1290. "disabled_by": null,
  1291. "status": "completed",
  1292. "created_by": "",
  1293. "created_at": 1695312007,
  1294. "indexing_at": 1695312007,
  1295. "completed_at": 1695312007,
  1296. "error": null,
  1297. "stopped_at": null
  1298. },
  1299. "doc_form": "text_model"
  1300. }
  1301. ```
  1302. </CodeGroup>
  1303. </Col>
  1304. </Row>
  1305. <hr className='ml-0 mr-0' />
  1306. <Heading
  1307. url='/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks'
  1308. method='POST'
  1309. title='Create Child Chunk'
  1310. name='#create_child_chunk'
  1311. />
  1312. <Row>
  1313. <Col>
  1314. ### Params
  1315. <Properties>
  1316. <Property name='dataset_id' type='string' key='dataset_id'>
  1317. Knowledge ID
  1318. </Property>
  1319. <Property name='document_id' type='string' key='document_id'>
  1320. Document ID
  1321. </Property>
  1322. <Property name='segment_id' type='string' key='segment_id'>
  1323. Segment ID
  1324. </Property>
  1325. </Properties>
  1326. ### Request Body
  1327. <Properties>
  1328. <Property name='content' type='string' key='content'>
  1329. Child chunk content
  1330. </Property>
  1331. </Properties>
  1332. </Col>
  1333. <Col sticky>
  1334. <CodeGroup
  1335. title="Request"
  1336. tag="POST"
  1337. label="/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks"
  1338. targetCode={`curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{"content": "Child chunk content"}'`}
  1339. >
  1340. ```bash {{ title: 'cURL' }}
  1341. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks' \
  1342. --header 'Authorization: Bearer {api_key}' \
  1343. --header 'Content-Type: application/json' \
  1344. --data-raw '{
  1345. "content": "Child chunk content"
  1346. }'
  1347. ```
  1348. </CodeGroup>
  1349. <CodeGroup title="Response">
  1350. ```json {{ title: 'Response' }}
  1351. {
  1352. "data": {
  1353. "id": "",
  1354. "segment_id": "",
  1355. "content": "Child chunk content",
  1356. "word_count": 25,
  1357. "tokens": 0,
  1358. "index_node_id": "",
  1359. "index_node_hash": "",
  1360. "status": "completed",
  1361. "created_by": "",
  1362. "created_at": 1695312007,
  1363. "indexing_at": 1695312007,
  1364. "completed_at": 1695312007,
  1365. "error": null,
  1366. "stopped_at": null
  1367. }
  1368. }
  1369. ```
  1370. </CodeGroup>
  1371. </Col>
  1372. </Row>
  1373. <hr className='ml-0 mr-0' />
  1374. <Heading
  1375. url='/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks'
  1376. method='GET'
  1377. title='Get Child Chunks'
  1378. name='#get_child_chunks'
  1379. />
  1380. <Row>
  1381. <Col>
  1382. ### Params
  1383. <Properties>
  1384. <Property name='dataset_id' type='string' key='dataset_id'>
  1385. Knowledge ID
  1386. </Property>
  1387. <Property name='document_id' type='string' key='document_id'>
  1388. Document ID
  1389. </Property>
  1390. <Property name='segment_id' type='string' key='segment_id'>
  1391. Segment ID
  1392. </Property>
  1393. </Properties>
  1394. ### Query
  1395. <Properties>
  1396. <Property name='keyword' type='string' key='keyword'>
  1397. Search keyword (optional)
  1398. </Property>
  1399. <Property name='page' type='integer' key='page'>
  1400. Page number (optional, default: 1)
  1401. </Property>
  1402. <Property name='limit' type='integer' key='limit'>
  1403. Items per page (optional, default: 20, max: 100)
  1404. </Property>
  1405. </Properties>
  1406. </Col>
  1407. <Col sticky>
  1408. <CodeGroup
  1409. title="Request"
  1410. tag="GET"
  1411. label="/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks"
  1412. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks?page=1&limit=20' \\\n--header 'Authorization: Bearer {api_key}'`}
  1413. >
  1414. ```bash {{ title: 'cURL' }}
  1415. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks?page=1&limit=20' \
  1416. --header 'Authorization: Bearer {api_key}'
  1417. ```
  1418. </CodeGroup>
  1419. <CodeGroup title="Response">
  1420. ```json {{ title: 'Response' }}
  1421. {
  1422. "data": [{
  1423. "id": "",
  1424. "segment_id": "",
  1425. "content": "Child chunk content",
  1426. "word_count": 25,
  1427. "tokens": 0,
  1428. "index_node_id": "",
  1429. "index_node_hash": "",
  1430. "status": "completed",
  1431. "created_by": "",
  1432. "created_at": 1695312007,
  1433. "indexing_at": 1695312007,
  1434. "completed_at": 1695312007,
  1435. "error": null,
  1436. "stopped_at": null
  1437. }],
  1438. "total": 1,
  1439. "total_pages": 1,
  1440. "page": 1,
  1441. "limit": 20
  1442. }
  1443. ```
  1444. </CodeGroup>
  1445. </Col>
  1446. </Row>
  1447. <hr className='ml-0 mr-0' />
  1448. <Heading
  1449. url='/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks/{child_chunk_id}'
  1450. method='DELETE'
  1451. title='Delete Child Chunk'
  1452. name='#delete_child_chunk'
  1453. />
  1454. <Row>
  1455. <Col>
  1456. ### Params
  1457. <Properties>
  1458. <Property name='dataset_id' type='string' key='dataset_id'>
  1459. Knowledge ID
  1460. </Property>
  1461. <Property name='document_id' type='string' key='document_id'>
  1462. Document ID
  1463. </Property>
  1464. <Property name='segment_id' type='string' key='segment_id'>
  1465. Segment ID
  1466. </Property>
  1467. <Property name='child_chunk_id' type='string' key='child_chunk_id'>
  1468. Child Chunk ID
  1469. </Property>
  1470. </Properties>
  1471. </Col>
  1472. <Col sticky>
  1473. <CodeGroup
  1474. title="Request"
  1475. tag="DELETE"
  1476. label="/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks/{child_chunk_id}"
  1477. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/segments/{segment_id}/child_chunks/{child_chunk_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  1478. >
  1479. ```bash {{ title: 'cURL' }}
  1480. curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/segments/{segment_id}/child_chunks/{child_chunk_id}' \
  1481. --header 'Authorization: Bearer {api_key}'
  1482. ```
  1483. </CodeGroup>
  1484. <CodeGroup title="Response">
  1485. ```json {{ title: 'Response' }}
  1486. {
  1487. "result": "success"
  1488. }
  1489. ```
  1490. </CodeGroup>
  1491. </Col>
  1492. </Row>
  1493. <hr className='ml-0 mr-0' />
  1494. <Heading
  1495. url='/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks/{child_chunk_id}'
  1496. method='PATCH'
  1497. title='Update Child Chunk'
  1498. name='#update_child_chunk'
  1499. />
  1500. <Row>
  1501. <Col>
  1502. ### Params
  1503. <Properties>
  1504. <Property name='dataset_id' type='string' key='dataset_id'>
  1505. Knowledge ID
  1506. </Property>
  1507. <Property name='document_id' type='string' key='document_id'>
  1508. Document ID
  1509. </Property>
  1510. <Property name='segment_id' type='string' key='segment_id'>
  1511. Segment ID
  1512. </Property>
  1513. <Property name='child_chunk_id' type='string' key='child_chunk_id'>
  1514. Child Chunk ID
  1515. </Property>
  1516. </Properties>
  1517. ### Request Body
  1518. <Properties>
  1519. <Property name='content' type='string' key='content'>
  1520. Child chunk content
  1521. </Property>
  1522. </Properties>
  1523. </Col>
  1524. <Col sticky>
  1525. <CodeGroup
  1526. title="Request"
  1527. tag="PATCH"
  1528. label="/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks/{child_chunk_id}"
  1529. targetCode={`curl --location --request PATCH '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks/{child_chunk_id}' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{"content": "Updated child chunk content"}'`}
  1530. >
  1531. ```bash {{ title: 'cURL' }}
  1532. curl --location --request PATCH '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks/{child_chunk_id}' \
  1533. --header 'Authorization: Bearer {api_key}' \
  1534. --header 'Content-Type: application/json' \
  1535. --data-raw '{
  1536. "content": "Updated child chunk content"
  1537. }'
  1538. ```
  1539. </CodeGroup>
  1540. <CodeGroup title="Response">
  1541. ```json {{ title: 'Response' }}
  1542. {
  1543. "data": {
  1544. "id": "",
  1545. "segment_id": "",
  1546. "content": "Updated child chunk content",
  1547. "word_count": 25,
  1548. "tokens": 0,
  1549. "index_node_id": "",
  1550. "index_node_hash": "",
  1551. "status": "completed",
  1552. "created_by": "",
  1553. "created_at": 1695312007,
  1554. "indexing_at": 1695312007,
  1555. "completed_at": 1695312007,
  1556. "error": null,
  1557. "stopped_at": null
  1558. }
  1559. }
  1560. ```
  1561. </CodeGroup>
  1562. </Col>
  1563. </Row>
  1564. <hr className='ml-0 mr-0' />
  1565. <Heading
  1566. url='/datasets/{dataset_id}/documents/{document_id}/upload-file'
  1567. method='GET'
  1568. title='Get Upload File'
  1569. name='#get_upload_file'
  1570. />
  1571. <Row>
  1572. <Col>
  1573. ### Path
  1574. <Properties>
  1575. <Property name='dataset_id' type='string' key='dataset_id'>
  1576. Knowledge ID
  1577. </Property>
  1578. <Property name='document_id' type='string' key='document_id'>
  1579. Document ID
  1580. </Property>
  1581. </Properties>
  1582. </Col>
  1583. <Col sticky>
  1584. <CodeGroup
  1585. title="Request"
  1586. tag="GET"
  1587. label="/datasets/{dataset_id}/documents/{document_id}/upload-file"
  1588. 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'`}
  1589. >
  1590. ```bash {{ title: 'cURL' }}
  1591. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/upload-file' \
  1592. --header 'Authorization: Bearer {api_key}' \
  1593. --header 'Content-Type: application/json'
  1594. ```
  1595. </CodeGroup>
  1596. <CodeGroup title="Response">
  1597. ```json {{ title: 'Response' }}
  1598. {
  1599. "id": "file_id",
  1600. "name": "file_name",
  1601. "size": 1024,
  1602. "extension": "txt",
  1603. "url": "preview_url",
  1604. "download_url": "download_url",
  1605. "mime_type": "text/plain",
  1606. "created_by": "user_id",
  1607. "created_at": 1728734540,
  1608. }
  1609. ```
  1610. </CodeGroup>
  1611. </Col>
  1612. </Row>
  1613. <hr className='ml-0 mr-0' />
  1614. <Heading
  1615. url='/datasets/{dataset_id}/retrieve'
  1616. method='POST'
  1617. title='Retrieve Chunks from a Knowledge Base'
  1618. name='#dataset_retrieval'
  1619. />
  1620. <Row>
  1621. <Col>
  1622. ### Path
  1623. <Properties>
  1624. <Property name='dataset_id' type='string' key='dataset_id'>
  1625. Knowledge ID
  1626. </Property>
  1627. </Properties>
  1628. ### Request Body
  1629. <Properties>
  1630. <Property name='query' type='string' key='query'>
  1631. Query keyword
  1632. </Property>
  1633. <Property name='retrieval_model' type='object' key='retrieval_model'>
  1634. Retrieval model (optional, if not filled, it will be recalled according to the default method)
  1635. - <code>search_method</code> (text) Search method: One of the following four keywords is required
  1636. - <code>keyword_search</code> Keyword search
  1637. - <code>semantic_search</code> Semantic search
  1638. - <code>full_text_search</code> Full-text search
  1639. - <code>hybrid_search</code> Hybrid search
  1640. - <code>reranking_enable</code> (bool) Whether to enable reranking, required if the search mode is semantic_search or hybrid_search (optional)
  1641. - <code>reranking_mode</code> (object) Rerank model configuration, required if reranking is enabled
  1642. - <code>reranking_provider_name</code> (string) Rerank model provider
  1643. - <code>reranking_model_name</code> (string) Rerank model name
  1644. - <code>weights</code> (float) Semantic search weight setting in hybrid search mode
  1645. - <code>top_k</code> (integer) Number of results to return (optional)
  1646. - <code>score_threshold_enabled</code> (bool) Whether to enable score threshold
  1647. - <code>score_threshold</code> (float) Score threshold
  1648. </Property>
  1649. <Property name='external_retrieval_model' type='object' key='external_retrieval_model'>
  1650. Unused field
  1651. </Property>
  1652. </Properties>
  1653. </Col>
  1654. <Col sticky>
  1655. <CodeGroup
  1656. title="Request"
  1657. tag="POST"
  1658. label="/datasets/{dataset_id}/retrieve"
  1659. 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 '{
  1660. "query": "test",
  1661. "retrieval_model": {
  1662. "search_method": "keyword_search",
  1663. "reranking_enable": false,
  1664. "reranking_mode": null,
  1665. "reranking_model": {
  1666. "reranking_provider_name": "",
  1667. "reranking_model_name": ""
  1668. },
  1669. "weights": null,
  1670. "top_k": 1,
  1671. "score_threshold_enabled": false,
  1672. "score_threshold": null
  1673. }
  1674. }'`}
  1675. >
  1676. ```bash {{ title: 'cURL' }}
  1677. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/retrieve' \
  1678. --header 'Authorization: Bearer {api_key}' \
  1679. --header 'Content-Type: application/json' \
  1680. --data-raw '{
  1681. "query": "test",
  1682. "retrieval_model": {
  1683. "search_method": "keyword_search",
  1684. "reranking_enable": false,
  1685. "reranking_mode": null,
  1686. "reranking_model": {
  1687. "reranking_provider_name": "",
  1688. "reranking_model_name": ""
  1689. },
  1690. "weights": null,
  1691. "top_k": 2,
  1692. "score_threshold_enabled": false,
  1693. "score_threshold": null
  1694. }
  1695. }'
  1696. ```
  1697. </CodeGroup>
  1698. <CodeGroup title="Response">
  1699. ```json {{ title: 'Response' }}
  1700. {
  1701. "query": {
  1702. "content": "test"
  1703. },
  1704. "records": [
  1705. {
  1706. "segment": {
  1707. "id": "7fa6f24f-8679-48b3-bc9d-bdf28d73f218",
  1708. "position": 1,
  1709. "document_id": "a8c6c36f-9f5d-4d7a-8472-f5d7b75d71d2",
  1710. "content": "Operation guide",
  1711. "answer": null,
  1712. "word_count": 847,
  1713. "tokens": 280,
  1714. "keywords": [
  1715. "install",
  1716. "java",
  1717. "base",
  1718. "scripts",
  1719. "jdk",
  1720. "manual",
  1721. "internal",
  1722. "opens",
  1723. "add",
  1724. "vmoptions"
  1725. ],
  1726. "index_node_id": "39dd8443-d960-45a8-bb46-7275ad7fbc8e",
  1727. "index_node_hash": "0189157697b3c6a418ccf8264a09699f25858975578f3467c76d6bfc94df1d73",
  1728. "hit_count": 0,
  1729. "enabled": true,
  1730. "disabled_at": null,
  1731. "disabled_by": null,
  1732. "status": "completed",
  1733. "created_by": "dbcb1ab5-90c8-41a7-8b78-73b235eb6f6f",
  1734. "created_at": 1728734540,
  1735. "indexing_at": 1728734552,
  1736. "completed_at": 1728734584,
  1737. "error": null,
  1738. "stopped_at": null,
  1739. "document": {
  1740. "id": "a8c6c36f-9f5d-4d7a-8472-f5d7b75d71d2",
  1741. "data_source_type": "upload_file",
  1742. "name": "readme.txt",
  1743. }
  1744. },
  1745. "score": 3.730463140527718e-05,
  1746. "tsne_position": null
  1747. }
  1748. ]
  1749. }
  1750. ```
  1751. </CodeGroup>
  1752. </Col>
  1753. </Row>
  1754. <hr className='ml-0 mr-0' />
  1755. <Heading
  1756. url='/datasets/{dataset_id}/metadata'
  1757. method='POST'
  1758. title='Create a Knowledge Metadata'
  1759. name='#create_metadata'
  1760. />
  1761. <Row>
  1762. <Col>
  1763. ### Params
  1764. <Properties>
  1765. <Property name='dataset_id' type='string' key='dataset_id'>
  1766. Knowledge ID
  1767. </Property>
  1768. </Properties>
  1769. ### Request Body
  1770. <Properties>
  1771. <Property name='segment' type='object' key='segment'>
  1772. - <code>type</code> (string) Metadata type, required
  1773. - <code>name</code> (string) Metadata name, required
  1774. </Property>
  1775. </Properties>
  1776. </Col>
  1777. <Col sticky>
  1778. <CodeGroup
  1779. title="Request"
  1780. tag="POST"
  1781. label="/datasets/{dataset_id}/metadata"
  1782. 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"}'`}
  1783. >
  1784. ```bash {{ title: 'cURL' }}
  1785. ```
  1786. </CodeGroup>
  1787. <CodeGroup title="Response">
  1788. ```json {{ title: 'Response' }}
  1789. {
  1790. "id": "abc",
  1791. "type": "string",
  1792. "name": "test",
  1793. }
  1794. ```
  1795. </CodeGroup>
  1796. </Col>
  1797. </Row>
  1798. <hr className='ml-0 mr-0' />
  1799. <Heading
  1800. url='/datasets/{dataset_id}/metadata/{metadata_id}'
  1801. method='PATCH'
  1802. title='Update a Knowledge Metadata'
  1803. name='#update_metadata'
  1804. />
  1805. <Row>
  1806. <Col>
  1807. ### Params
  1808. <Properties>
  1809. <Property name='dataset_id' type='string' key='dataset_id'>
  1810. Knowledge ID
  1811. </Property>
  1812. <Property name='metadata_id' type='string' key='metadata_id'>
  1813. Metadata ID
  1814. </Property>
  1815. </Properties>
  1816. ### Request Body
  1817. <Properties>
  1818. <Property name='segment' type='object' key='segment'>
  1819. - <code>name</code> (string) Metadata name, required
  1820. </Property>
  1821. </Properties>
  1822. </Col>
  1823. <Col sticky>
  1824. <CodeGroup
  1825. title="Request"
  1826. tag="PATCH"
  1827. label="/datasets/{dataset_id}/metadata/{metadata_id}"
  1828. targetCode={`curl --location --request PATCH '${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"}'`}
  1829. >
  1830. ```bash {{ title: 'cURL' }}
  1831. ```
  1832. </CodeGroup>
  1833. <CodeGroup title="Response">
  1834. ```json {{ title: 'Response' }}
  1835. {
  1836. "id": "abc",
  1837. "type": "string",
  1838. "name": "test",
  1839. }
  1840. ```
  1841. </CodeGroup>
  1842. </Col>
  1843. </Row>
  1844. <hr className='ml-0 mr-0' />
  1845. <Heading
  1846. url='/datasets/{dataset_id}/metadata/{metadata_id}'
  1847. method='DELETE'
  1848. title='Delete a Knowledge Metadata'
  1849. name='#delete_metadata'
  1850. />
  1851. <Row>
  1852. <Col>
  1853. ### Params
  1854. <Properties>
  1855. <Property name='dataset_id' type='string' key='dataset_id'>
  1856. Knowledge ID
  1857. </Property>
  1858. <Property name='metadata_id' type='string' key='metadata_id'>
  1859. Metadata ID
  1860. </Property>
  1861. </Properties>
  1862. </Col>
  1863. <Col sticky>
  1864. <CodeGroup
  1865. title="Request"
  1866. tag="DELETE"
  1867. label="/datasets/{dataset_id}/metadata/{metadata_id}"
  1868. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/metadata/{metadata_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  1869. >
  1870. ```bash {{ title: 'cURL' }}
  1871. ```
  1872. </CodeGroup>
  1873. </Col>
  1874. </Row>
  1875. <hr className='ml-0 mr-0' />
  1876. <Heading
  1877. url='/datasets/{dataset_id}/metadata/built-in/{action}'
  1878. method='POST'
  1879. title='Disable Or Enable Built-in Metadata'
  1880. name='#toggle_metadata'
  1881. />
  1882. <Row>
  1883. <Col>
  1884. ### Params
  1885. <Properties>
  1886. <Property name='dataset_id' type='string' key='dataset_id'>
  1887. Knowledge ID
  1888. </Property>
  1889. <Property name='action' type='string' key='action'>
  1890. disable/enable
  1891. </Property>
  1892. </Properties>
  1893. </Col>
  1894. <Col sticky>
  1895. <CodeGroup
  1896. title="Request"
  1897. tag="POST"
  1898. label="/datasets/{dataset_id}/metadata/built-in/{action}"
  1899. targetCode={`curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/metadata/built-in/{action}' \\\n--header 'Authorization: Bearer {api_key}'`}
  1900. >
  1901. ```bash {{ title: 'cURL' }}
  1902. ```
  1903. </CodeGroup>
  1904. </Col>
  1905. </Row>
  1906. <hr className='ml-0 mr-0' />
  1907. <Heading
  1908. url='/datasets/{dataset_id}/documents/metadata'
  1909. method='POST'
  1910. title='Update Documents Metadata'
  1911. name='#update_documents_metadata'
  1912. />
  1913. <Row>
  1914. <Col>
  1915. ### Params
  1916. <Properties>
  1917. <Property name='dataset_id' type='string' key='dataset_id'>
  1918. Knowledge ID
  1919. </Property>
  1920. </Properties>
  1921. ### Request Body
  1922. <Properties>
  1923. <Property name='operation_data' type='object list' key='segments'>
  1924. - <code>document_id</code> (string) Document ID
  1925. - <code>metadata_list</code> (list) Metadata list
  1926. - <code>id</code> (string) Metadata ID
  1927. - <code>value</code> (string) Metadata value
  1928. - <code>name</code> (string) Metadata name
  1929. </Property>
  1930. </Properties>
  1931. </Col>
  1932. <Col sticky>
  1933. <CodeGroup
  1934. title="Request"
  1935. tag="POST"
  1936. label="/datasets/{dataset_id}/documents/metadata"
  1937. 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"}]}]}'`}
  1938. >
  1939. ```bash {{ title: 'cURL' }}
  1940. ```
  1941. </CodeGroup>
  1942. </Col>
  1943. </Row>
  1944. <hr className='ml-0 mr-0' />
  1945. <Heading
  1946. url='/datasets/{dataset_id}/metadata'
  1947. method='GET'
  1948. title='Get Knowledge Metadata List'
  1949. name='#dataset_metadata_list'
  1950. />
  1951. <Row>
  1952. <Col>
  1953. ### Params
  1954. <Properties>
  1955. <Property name='dataset_id' type='string' key='dataset_id'>
  1956. Knowledge ID
  1957. </Property>
  1958. </Properties>
  1959. </Col>
  1960. <Col sticky>
  1961. <CodeGroup
  1962. title="Request"
  1963. tag="GET"
  1964. label="/datasets/{dataset_id}/metadata"
  1965. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/metadata' \\\n--header 'Authorization: Bearer {api_key}'`}
  1966. >
  1967. ```bash {{ title: 'cURL' }}
  1968. ```
  1969. </CodeGroup>
  1970. <CodeGroup title="Response">
  1971. ```json {{ title: 'Response' }}
  1972. {
  1973. "doc_metadata": [
  1974. {
  1975. "id": "",
  1976. "name": "name",
  1977. "type": "string",
  1978. "use_count": 0,
  1979. },
  1980. ...
  1981. ],
  1982. "built_in_field_enabled": true
  1983. }
  1984. ```
  1985. </CodeGroup>
  1986. </Col>
  1987. </Row>
  1988. <hr className='ml-0 mr-0' />
  1989. <Heading
  1990. url='/workspaces/current/models/model-types/text-embedding'
  1991. method='GET'
  1992. title='Get available embedding models'
  1993. name='#model_type_list'
  1994. />
  1995. <Row>
  1996. <Col>
  1997. ### Query
  1998. <Properties>
  1999. </Properties>
  2000. </Col>
  2001. <Col sticky>
  2002. <CodeGroup
  2003. title="Request"
  2004. tag="GET"
  2005. label="/datasets/{dataset_id}"
  2006. targetCode={`curl --location --location --request GET '${props.apiBaseUrl}/workspaces/current/models/model-types/text-embedding' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' `}
  2007. >
  2008. ```bash {{ title: 'cURL' }}
  2009. curl --location --request GET '${props.apiBaseUrl}/workspaces/current/models/model-types/text-embedding' \
  2010. --header 'Authorization: Bearer {api_key}' \
  2011. --header 'Content-Type: application/json' \
  2012. ```
  2013. </CodeGroup>
  2014. <CodeGroup title="Response">
  2015. ```json {{ title: 'Response' }}
  2016. {
  2017. "data": [
  2018. {
  2019. "provider": "zhipuai",
  2020. "label": {
  2021. "zh_Hans": "智谱 AI",
  2022. "en_US": "ZHIPU AI"
  2023. },
  2024. "icon_small": {
  2025. "zh_Hans": "http://127.0.0.1:5001/console/api/workspaces/current/model-providers/zhipuai/icon_small/zh_Hans",
  2026. "en_US": "http://127.0.0.1:5001/console/api/workspaces/current/model-providers/zhipuai/icon_small/en_US"
  2027. },
  2028. "icon_large": {
  2029. "zh_Hans": "http://127.0.0.1:5001/console/api/workspaces/current/model-providers/zhipuai/icon_large/zh_Hans",
  2030. "en_US": "http://127.0.0.1:5001/console/api/workspaces/current/model-providers/zhipuai/icon_large/en_US"
  2031. },
  2032. "status": "active",
  2033. "models": [
  2034. {
  2035. "model": "embedding-3",
  2036. "label": {
  2037. "zh_Hans": "embedding-3",
  2038. "en_US": "embedding-3"
  2039. },
  2040. "model_type": "text-embedding",
  2041. "features": null,
  2042. "fetch_from": "predefined-model",
  2043. "model_properties": {
  2044. "context_size": 8192
  2045. },
  2046. "deprecated": false,
  2047. "status": "active",
  2048. "load_balancing_enabled": false
  2049. },
  2050. {
  2051. "model": "embedding-2",
  2052. "label": {
  2053. "zh_Hans": "embedding-2",
  2054. "en_US": "embedding-2"
  2055. },
  2056. "model_type": "text-embedding",
  2057. "features": null,
  2058. "fetch_from": "predefined-model",
  2059. "model_properties": {
  2060. "context_size": 8192
  2061. },
  2062. "deprecated": false,
  2063. "status": "active",
  2064. "load_balancing_enabled": false
  2065. },
  2066. {
  2067. "model": "text_embedding",
  2068. "label": {
  2069. "zh_Hans": "text_embedding",
  2070. "en_US": "text_embedding"
  2071. },
  2072. "model_type": "text-embedding",
  2073. "features": null,
  2074. "fetch_from": "predefined-model",
  2075. "model_properties": {
  2076. "context_size": 512
  2077. },
  2078. "deprecated": false,
  2079. "status": "active",
  2080. "load_balancing_enabled": false
  2081. }
  2082. ]
  2083. }
  2084. ]
  2085. }
  2086. ```
  2087. </CodeGroup>
  2088. </Col>
  2089. </Row>
  2090. <hr className='ml-0 mr-0' />
  2091. <Row>
  2092. <Col>
  2093. ### Error message
  2094. <Properties>
  2095. <Property name='code' type='string' key='code'>
  2096. Error code
  2097. </Property>
  2098. </Properties>
  2099. <Properties>
  2100. <Property name='status' type='number' key='status'>
  2101. Error status
  2102. </Property>
  2103. </Properties>
  2104. <Properties>
  2105. <Property name='message' type='string' key='message'>
  2106. Error message
  2107. </Property>
  2108. </Properties>
  2109. </Col>
  2110. <Col>
  2111. <CodeGroup title="Example">
  2112. ```json {{ title: 'Response' }}
  2113. {
  2114. "code": "no_file_uploaded",
  2115. "message": "Please upload your file.",
  2116. "status": 400
  2117. }
  2118. ```
  2119. </CodeGroup>
  2120. </Col>
  2121. </Row>
  2122. <table className="max-w-auto border-collapse border border-slate-400" style={{ maxWidth: 'none', width: 'auto' }}>
  2123. <thead style={{ background: '#f9fafc' }}>
  2124. <tr>
  2125. <th className="p-2 border border-slate-300">code</th>
  2126. <th className="p-2 border border-slate-300">status</th>
  2127. <th className="p-2 border border-slate-300">message</th>
  2128. </tr>
  2129. </thead>
  2130. <tbody>
  2131. <tr>
  2132. <td className="p-2 border border-slate-300">no_file_uploaded</td>
  2133. <td className="p-2 border border-slate-300">400</td>
  2134. <td className="p-2 border border-slate-300">Please upload your file.</td>
  2135. </tr>
  2136. <tr>
  2137. <td className="p-2 border border-slate-300">too_many_files</td>
  2138. <td className="p-2 border border-slate-300">400</td>
  2139. <td className="p-2 border border-slate-300">Only one file is allowed.</td>
  2140. </tr>
  2141. <tr>
  2142. <td className="p-2 border border-slate-300">file_too_large</td>
  2143. <td className="p-2 border border-slate-300">413</td>
  2144. <td className="p-2 border border-slate-300">File size exceeded.</td>
  2145. </tr>
  2146. <tr>
  2147. <td className="p-2 border border-slate-300">unsupported_file_type</td>
  2148. <td className="p-2 border border-slate-300">415</td>
  2149. <td className="p-2 border border-slate-300">File type not allowed.</td>
  2150. </tr>
  2151. <tr>
  2152. <td className="p-2 border border-slate-300">high_quality_dataset_only</td>
  2153. <td className="p-2 border border-slate-300">400</td>
  2154. <td className="p-2 border border-slate-300">Current operation only supports 'high-quality' datasets.</td>
  2155. </tr>
  2156. <tr>
  2157. <td className="p-2 border border-slate-300">dataset_not_initialized</td>
  2158. <td className="p-2 border border-slate-300">400</td>
  2159. <td className="p-2 border border-slate-300">The dataset is still being initialized or indexing. Please wait a moment.</td>
  2160. </tr>
  2161. <tr>
  2162. <td className="p-2 border border-slate-300">archived_document_immutable</td>
  2163. <td className="p-2 border border-slate-300">403</td>
  2164. <td className="p-2 border border-slate-300">The archived document is not editable.</td>
  2165. </tr>
  2166. <tr>
  2167. <td className="p-2 border border-slate-300">dataset_name_duplicate</td>
  2168. <td className="p-2 border border-slate-300">409</td>
  2169. <td className="p-2 border border-slate-300">The dataset name already exists. Please modify your dataset name.</td>
  2170. </tr>
  2171. <tr>
  2172. <td className="p-2 border border-slate-300">invalid_action</td>
  2173. <td className="p-2 border border-slate-300">400</td>
  2174. <td className="p-2 border border-slate-300">Invalid action.</td>
  2175. </tr>
  2176. <tr>
  2177. <td className="p-2 border border-slate-300">document_already_finished</td>
  2178. <td className="p-2 border border-slate-300">400</td>
  2179. <td className="p-2 border border-slate-300">The document has been processed. Please refresh the page or go to the document details.</td>
  2180. </tr>
  2181. <tr>
  2182. <td className="p-2 border border-slate-300">document_indexing</td>
  2183. <td className="p-2 border border-slate-300">400</td>
  2184. <td className="p-2 border border-slate-300">The document is being processed and cannot be edited.</td>
  2185. </tr>
  2186. <tr>
  2187. <td className="p-2 border border-slate-300">invalid_metadata</td>
  2188. <td className="p-2 border border-slate-300">400</td>
  2189. <td className="p-2 border border-slate-300">The metadata content is incorrect. Please check and verify.</td>
  2190. </tr>
  2191. </tbody>
  2192. </table>
  2193. <div className="pb-4" />