template.en.mdx 61 KB

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