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 76KB

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