template.zh.mdx 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656
  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. # 知识库 API
  4. <div>
  5. ### 鉴权
  6. Dify Service API 使用 `API-Key` 进行鉴权。
  7. 建议开发者把 `API-Key` 放在后端存储,而非分享或者放在客户端存储,以免 `API-Key` 泄露,导致财产损失。
  8. 所有 API 请求都应在 **`Authorization`** HTTP Header 中包含您的 `API-Key`,如下所示:
  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='通过文本创建文档'
  20. name='#create-by-text'
  21. />
  22. <Row>
  23. <Col>
  24. 此接口基于已存在知识库,在此知识库的基础上通过文本创建新的文档
  25. ### Path
  26. <Properties>
  27. <Property name='dataset_id' type='string' key='dataset_id'>
  28. 知识库 ID
  29. </Property>
  30. </Properties>
  31. ### Request Body
  32. <Properties>
  33. <Property name='name' type='string' key='name'>
  34. 文档名称
  35. </Property>
  36. <Property name='text' type='string' key='text'>
  37. 文档内容
  38. </Property>
  39. <Property name='doc_type' type='string' key='doc_type'>
  40. 文档类型(选填)
  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同步文档 Notion document
  50. - <code>synced_from_github</code> GitHub同步文档 GitHub document
  51. - <code>others</code> 其他文档类型 Other document types
  52. </Property>
  53. <Property name='doc_metadata' type='object' key='doc_metadata'>
  54. 文档元数据(如提供文档类型则必填)。字段因文档类型而异:
  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号码 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. 请查看 [api/services/dataset_service.py](https://github.com/langgenius/dify/blob/main/api/services/dataset_service.py#L475) 了解各文档类型所需字段的详细信息。
  72. 针对"其他"类型文档,接受任何有效的JSON对象
  73. </Property>
  74. <Property name='indexing_technique' type='string' key='indexing_technique'>
  75. 索引方式
  76. - <code>high_quality</code> 高质量:使用 embedding 模型进行嵌入,构建为向量数据库索引
  77. - <code>economy</code> 经济:使用 keyword table index 的倒排索引进行构建
  78. </Property>
  79. <Property name='doc_form' type='string' key='doc_form'>
  80. 索引内容的形式
  81. - <code>text_model</code> text 文档直接 embedding,经济模式默认为该模式
  82. - <code>hierarchical_model</code> parent-child 模式
  83. - <code>qa_model</code> Q&A 模式:为分片文档生成 Q&A 对,然后对问题进行 embedding
  84. </Property>
  85. <Property name='doc_language' type='string' key='doc_language'>
  86. 在 Q&A 模式下,指定文档的语言,例如:<code>English</code>、<code>Chinese</code>
  87. </Property>
  88. <Property name='process_rule' type='object' key='process_rule'>
  89. 处理规则
  90. - <code>mode</code> (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
  91. - <code>rules</code> (object) 自定义规则(自动模式下,该字段为空)
  92. - <code>pre_processing_rules</code> (array[object]) 预处理规则
  93. - <code>id</code> (string) 预处理规则的唯一标识符
  94. - 枚举:
  95. - <code>remove_extra_spaces</code> 替换连续空格、换行符、制表符
  96. - <code>remove_urls_emails</code> 删除 URL、电子邮件地址
  97. - <code>enabled</code> (bool) 是否选中该规则,不传入文档 ID 时代表默认值
  98. - <code>segmentation</code> (object) 分段规则
  99. - <code>separator</code> 自定义分段标识符,目前仅允许设置一个分隔符。默认为 <code>\n</code>
  100. - <code>max_tokens</code> 最大长度(token)默认为 1000
  101. - <code>parent_mode</code> 父分段的召回模式 <code>full-doc</code> 全文召回 / <code>paragraph</code> 段落召回
  102. - <code>subchunk_segmentation</code> (object) 子分段规则
  103. - <code>separator</code> 分段标识符,目前仅允许设置一个分隔符。默认为 <code>***</code>
  104. - <code>max_tokens</code> 最大长度 (token) 需要校验小于父级的长度
  105. - <code>chunk_overlap</code> 分段重叠指的是在对数据进行分段时,段与段之间存在一定的重叠部分(选填)
  106. </Property>
  107. <PropertyInstruction>当知识库未设置任何参数的时候,首次上传需要提供以下参数,未提供则使用默认选项:</PropertyInstruction>
  108. <Property name='retrieval_model' type='object' key='retrieval_model'>
  109. 检索模式
  110. - <code>search_method</code> (string) 检索方法
  111. - <code>hybrid_search</code> 混合检索
  112. - <code>semantic_search</code> 语义检索
  113. - <code>full_text_search</code> 全文检索
  114. - <code>reranking_enable</code> (bool) 是否开启rerank
  115. - <code>reranking_model</code> (object) Rerank 模型配置
  116. - <code>reranking_provider_name</code> (string) Rerank 模型的提供商
  117. - <code>reranking_model_name</code> (string) Rerank 模型的名称
  118. - <code>top_k</code> (int) 召回条数
  119. - <code>score_threshold_enabled</code> (bool)是否开启召回分数限制
  120. - <code>score_threshold</code> (float) 召回分数限制
  121. </Property>
  122. <Property name='embedding_model' type='string' key='embedding_model'>
  123. Embedding 模型名称
  124. </Property>
  125. <Property name='embedding_model_provider' type='string' key='embedding_model_provider'>
  126. Embedding 模型供应商
  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 --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='通过文件创建文档 '
  189. name='#create-by-file'
  190. />
  191. <Row>
  192. <Col>
  193. 此接口基于已存在知识库,在此知识库的基础上通过文件创建新的文档
  194. ### Path
  195. <Properties>
  196. <Property name='dataset_id' type='string' key='dataset_id'>
  197. 知识库 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> 源文档 ID(选填)
  204. - 用于重新上传文档或修改文档清洗、分段配置,缺失的信息从源文档复制
  205. - 源文档不可为归档的文档
  206. - 当传入 <code>original_document_id</code> 时,代表文档进行更新操作,<code>process_rule</code> 为可填项目,不填默认使用源文档的分段方式
  207. - 未传入 <code>original_document_id</code> 时,代表文档进行新增操作,<code>process_rule</code> 为必填
  208. - <code>indexing_technique</code> 索引方式
  209. - <code>high_quality</code> 高质量:使用 embedding 模型进行嵌入,构建为向量数据库索引
  210. - <code>economy</code> 经济:使用 keyword table index 的倒排索引进行构建
  211. - <code>doc_form</code> 索引内容的形式
  212. - <code>text_model</code> text 文档直接 embedding,经济模式默认为该模式
  213. - <code>hierarchical_model</code> parent-child 模式
  214. - <code>qa_model</code> Q&A 模式:为分片文档生成 Q&A 对,然后对问题进行 embedding
  215. - <code>doc_type</code> 文档类型(选填)Type of document (optional)
  216. - <code>book</code> 图书
  217. 文档记录一本书籍或出版物
  218. - <code>web_page</code> 网页
  219. 网页内容的文档记录
  220. - <code>paper</code> 学术论文/文章
  221. 学术论文或研究文章的记录
  222. - <code>social_media_post</code> 社交媒体帖子
  223. 社交媒体上的帖子内容
  224. - <code>wikipedia_entry</code> 维基百科条目
  225. 维基百科的词条内容
  226. - <code>personal_document</code> 个人文档
  227. 个人相关的文档记录
  228. - <code>business_document</code> 商业文档
  229. 商业相关的文档记录
  230. - <code>im_chat_log</code> 即时通讯记录
  231. 即时通讯的聊天记录
  232. - <code>synced_from_notion</code> Notion同步文档
  233. 从Notion同步的文档内容
  234. - <code>synced_from_github</code> GitHub同步文档
  235. 从GitHub同步的文档内容
  236. - <code>others</code> 其他文档类型
  237. 其他未列出的文档类型
  238. - <code>doc_metadata</code> 文档元数据(如提供文档类型则必填
  239. 字段因文档类型而异
  240. 针对图书类型 For <code>book</code>:
  241. - <code>title</code> 书名
  242. 书籍的标题
  243. - <code>language</code> 图书语言
  244. 书籍的语言
  245. - <code>author</code> 作者
  246. 书籍的作者
  247. - <code>publisher</code> 出版社
  248. 出版社的名称
  249. - <code>publication_date</code> 出版日期
  250. 书籍的出版日期
  251. - <code>isbn</code> ISBN号码
  252. 书籍的ISBN编号
  253. - <code>category</code> 图书分类
  254. 书籍的分类类别
  255. 针对网页类型 For <code>web_page</code>:
  256. - <code>title</code> 页面标题
  257. 网页的标题
  258. - <code>url</code> 页面网址
  259. 网页的URL地址
  260. - <code>language</code> 页面语言
  261. 网页的语言
  262. - <code>publish_date</code> 发布日期
  263. 网页的发布日期
  264. - <code>author/publisher</code> 作者/发布者
  265. 网页的作者或发布者
  266. - <code>topic/keywords</code> 主题/关键词
  267. 网页的主题或关键词
  268. - <code>description</code> 页面描述
  269. 网页的描述信息
  270. 请查看 [api/services/dataset_service.py](https://github.com/langgenius/dify/blob/main/api/services/dataset_service.py#L475) 了解各文档类型所需字段的详细信息。
  271. 针对"其他"类型文档,接受任何有效的JSON对象
  272. - <code>doc_language</code> 在 Q&A 模式下,指定文档的语言,例如:<code>English</code>、<code>Chinese</code>
  273. - <code>process_rule</code> 处理规则
  274. - <code>mode</code> (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
  275. - <code>rules</code> (object) 自定义规则(自动模式下,该字段为空)
  276. - <code>pre_processing_rules</code> (array[object]) 预处理规则
  277. - <code>id</code> (string) 预处理规则的唯一标识符
  278. - 枚举:
  279. - <code>remove_extra_spaces</code> 替换连续空格、换行符、制表符
  280. - <code>remove_urls_emails</code> 删除 URL、电子邮件地址
  281. - <code>enabled</code> (bool) 是否选中该规则,不传入文档 ID 时代表默认值
  282. - <code>segmentation</code> (object) 分段规则
  283. - <code>separator</code> 自定义分段标识符,目前仅允许设置一个分隔符。默认为 \n
  284. - <code>max_tokens</code> 最大长度(token)默认为 1000
  285. - <code>parent_mode</code> 父分段的召回模式 <code>full-doc</code> 全文召回 / <code>paragraph</code> 段落召回
  286. - <code>subchunk_segmentation</code> (object) 子分段规则
  287. - <code>separator</code> 分段标识符,目前仅允许设置一个分隔符。默认为 <code>***</code>
  288. - <code>max_tokens</code> 最大长度 (token) 需要校验小于父级的长度
  289. - <code>chunk_overlap</code> 分段重叠指的是在对数据进行分段时,段与段之间存在一定的重叠部分(选填)
  290. </Property>
  291. <Property name='file' type='multipart/form-data' key='file'>
  292. 需要上传的文件。
  293. </Property>
  294. <PropertyInstruction>当知识库未设置任何参数的时候,首次上传需要提供以下参数,未提供则使用默认选项:</PropertyInstruction>
  295. <Property name='retrieval_model' type='object' key='retrieval_model'>
  296. 检索模式
  297. - <code>search_method</code> (string) 检索方法
  298. - <code>hybrid_search</code> 混合检索
  299. - <code>semantic_search</code> 语义检索
  300. - <code>full_text_search</code> 全文检索
  301. - <code>reranking_enable</code> (bool) 是否开启rerank
  302. - <code>reranking_model</code> (object) Rerank 模型配置
  303. - <code>reranking_provider_name</code> (string) Rerank 模型的提供商
  304. - <code>reranking_model_name</code> (string) Rerank 模型的名称
  305. - <code>top_k</code> (int) 召回条数
  306. - <code>score_threshold_enabled</code> (bool)是否开启召回分数限制
  307. - <code>score_threshold</code> (float) 召回分数限制
  308. </Property>
  309. <Property name='embedding_model' type='string' key='embedding_model'>
  310. Embedding 模型名称
  311. </Property>
  312. <Property name='embedding_model_provider' type='string' key='embedding_model_provider'>
  313. Embedding 模型供应商
  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='创建空知识库'
  369. name='#create_empty_dataset'
  370. />
  371. <Row>
  372. <Col>
  373. ### Request Body
  374. <Properties>
  375. <Property name='name' type='string' key='name'>
  376. 知识库名称(必填)
  377. </Property>
  378. <Property name='description' type='string' key='description'>
  379. 知识库描述(选填)
  380. </Property>
  381. <Property name='indexing_technique' type='string' key='indexing_technique'>
  382. 索引模式(选填,建议填写)
  383. - <code>high_quality</code> 高质量
  384. - <code>economy</code> 经济
  385. </Property>
  386. <Property name='permission' type='string' key='permission'>
  387. 权限(选填,默认 only_me)
  388. - <code>only_me</code> 仅自己
  389. - <code>all_team_members</code> 所有团队成员
  390. - <code>partial_members</code> 部分团队成员
  391. </Property>
  392. <Property name='provider' type='string' key='provider'>
  393. Provider(选填,默认 vendor)
  394. - <code>vendor</code> 上传文件
  395. - <code>external</code> 外部知识库
  396. </Property>
  397. <Property name='external_knowledge_api_id' type='str' key='external_knowledge_api_id'>
  398. 外部知识库 API_ID(选填)
  399. </Property>
  400. <Property name='external_knowledge_id' type='str' key='external_knowledge_id'>
  401. 外部知识库 ID(选填)
  402. </Property>
  403. </Properties>
  404. </Col>
  405. <Col sticky>
  406. <CodeGroup
  407. title="Request"
  408. tag="POST"
  409. label="/datasets"
  410. 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"}'`}
  411. >
  412. ```bash {{ title: 'cURL' }}
  413. curl --location --request POST '${props.apiBaseUrl}/datasets' \
  414. --header 'Authorization: Bearer {api_key}' \
  415. --header 'Content-Type: application/json' \
  416. --data-raw '{
  417. "name": "name",
  418. "permission": "only_me"
  419. }'
  420. ```
  421. </CodeGroup>
  422. <CodeGroup title="Response">
  423. ```json {{ title: 'Response' }}
  424. {
  425. "id": "",
  426. "name": "name",
  427. "description": null,
  428. "provider": "vendor",
  429. "permission": "only_me",
  430. "data_source_type": null,
  431. "indexing_technique": null,
  432. "app_count": 0,
  433. "document_count": 0,
  434. "word_count": 0,
  435. "created_by": "",
  436. "created_at": 1695636173,
  437. "updated_by": "",
  438. "updated_at": 1695636173,
  439. "embedding_model": null,
  440. "embedding_model_provider": null,
  441. "embedding_available": null
  442. }
  443. ```
  444. </CodeGroup>
  445. </Col>
  446. </Row>
  447. <hr className='ml-0 mr-0' />
  448. <Heading
  449. url='/datasets'
  450. method='GET'
  451. title='知识库列表'
  452. name='#dataset_list'
  453. />
  454. <Row>
  455. <Col>
  456. ### Query
  457. <Properties>
  458. <Property name='page' type='string' key='page'>
  459. 页码
  460. </Property>
  461. <Property name='limit' type='string' key='limit'>
  462. 返回条数,默认 20,范围 1-100
  463. </Property>
  464. </Properties>
  465. </Col>
  466. <Col sticky>
  467. <CodeGroup
  468. title="Request"
  469. tag="GET"
  470. label="/datasets"
  471. targetCode={`curl --location --request GET '${props.apiBaseUrl}/datasets?page=1&limit=20' \\\n--header 'Authorization: Bearer {api_key}'`}
  472. >
  473. ```bash {{ title: 'cURL' }}
  474. curl --location --request GET '${props.apiBaseUrl}/datasets?page=1&limit=20' \
  475. --header 'Authorization: Bearer {api_key}'
  476. ```
  477. </CodeGroup>
  478. <CodeGroup title="Response">
  479. ```json {{ title: 'Response' }}
  480. {
  481. "data": [
  482. {
  483. "id": "",
  484. "name": "知识库名称",
  485. "description": "描述信息",
  486. "permission": "only_me",
  487. "data_source_type": "upload_file",
  488. "indexing_technique": "",
  489. "app_count": 2,
  490. "document_count": 10,
  491. "word_count": 1200,
  492. "created_by": "",
  493. "created_at": "",
  494. "updated_by": "",
  495. "updated_at": ""
  496. },
  497. ...
  498. ],
  499. "has_more": true,
  500. "limit": 20,
  501. "total": 50,
  502. "page": 1
  503. }
  504. ```
  505. </CodeGroup>
  506. </Col>
  507. </Row>
  508. <hr className='ml-0 mr-0' />
  509. <Heading
  510. url='/datasets/{dataset_id}'
  511. method='DELETE'
  512. title='删除知识库'
  513. name='#delete_dataset'
  514. />
  515. <Row>
  516. <Col>
  517. ### Path
  518. <Properties>
  519. <Property name='dataset_id' type='string' key='dataset_id'>
  520. 知识库 ID
  521. </Property>
  522. </Properties>
  523. </Col>
  524. <Col sticky>
  525. <CodeGroup
  526. title="Request"
  527. tag="DELETE"
  528. label="/datasets/{dataset_id}"
  529. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  530. >
  531. ```bash {{ title: 'cURL' }}
  532. curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}' \
  533. --header 'Authorization: Bearer {api_key}'
  534. ```
  535. </CodeGroup>
  536. <CodeGroup title="Response">
  537. ```text {{ title: 'Response' }}
  538. 204 No Content
  539. ```
  540. </CodeGroup>
  541. </Col>
  542. </Row>
  543. <hr className='ml-0 mr-0' />
  544. <Heading
  545. url='/datasets/{dataset_id}/documents/{document_id}/update-by-text'
  546. method='POST'
  547. title='通过文本更新文档'
  548. name='#update-by-text'
  549. />
  550. <Row>
  551. <Col>
  552. 此接口基于已存在知识库,在此知识库的基础上通过文本更新文档
  553. ### Path
  554. <Properties>
  555. <Property name='dataset_id' type='string' key='dataset_id'>
  556. 知识库 ID
  557. </Property>
  558. <Property name='document_id' type='string' key='document_id'>
  559. 文档 ID
  560. </Property>
  561. </Properties>
  562. ### Request Body
  563. <Properties>
  564. <Property name='name' type='string' key='name'>
  565. 文档名称(选填)
  566. </Property>
  567. <Property name='text' type='string' key='text'>
  568. 文档内容(选填)
  569. </Property>
  570. <Property name='doc_type' type='string' key='doc_type'>
  571. 文档类型(选填)
  572. - <code>book</code> 图书 Book
  573. - <code>web_page</code> 网页 Web page
  574. - <code>paper</code> 学术论文/文章 Academic paper/article
  575. - <code>social_media_post</code> 社交媒体帖子 Social media post
  576. - <code>wikipedia_entry</code> 维基百科条目 Wikipedia entry
  577. - <code>personal_document</code> 个人文档 Personal document
  578. - <code>business_document</code> 商业文档 Business document
  579. - <code>im_chat_log</code> 即时通讯记录 Chat log
  580. - <code>synced_from_notion</code> Notion同步文档 Notion document
  581. - <code>synced_from_github</code> GitHub同步文档 GitHub document
  582. - <code>others</code> 其他文档类型 Other document types
  583. </Property>
  584. <Property name='doc_metadata' type='object' key='doc_metadata'>
  585. 文档元数据(如提供文档类型则必填)。字段因文档类型而异:
  586. 针对图书 For <code>book</code>:
  587. - <code>title</code> 书名 Book title
  588. - <code>language</code> 图书语言 Book language
  589. - <code>author</code> 作者 Book author
  590. - <code>publisher</code> 出版社 Publisher name
  591. - <code>publication_date</code> 出版日期 Publication date
  592. - <code>isbn</code> ISBN号码 ISBN number
  593. - <code>category</code> 图书分类 Book category
  594. 针对网页 For <code>web_page</code>:
  595. - <code>title</code> 页面标题 Page title
  596. - <code>url</code> 页面网址 Page URL
  597. - <code>language</code> 页面语言 Page language
  598. - <code>publish_date</code> 发布日期 Publish date
  599. - <code>author/publisher</code> 作者/发布者 Author or publisher
  600. - <code>topic/keywords</code> 主题/关键词 Topic or keywords
  601. - <code>description</code> 页面描述 Page description
  602. 请查看 [api/services/dataset_service.py](https://github.com/langgenius/dify/blob/main/api/services/dataset_service.py#L475) 了解各文档类型所需字段的详细信息。
  603. 针对"其他"类型文档,接受任何有效的JSON对象
  604. </Property>
  605. <Property name='process_rule' type='object' key='process_rule'>
  606. 处理规则(选填)
  607. - <code>mode</code> (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
  608. - <code>rules</code> (object) 自定义规则(自动模式下,该字段为空)
  609. - <code>pre_processing_rules</code> (array[object]) 预处理规则
  610. - <code>id</code> (string) 预处理规则的唯一标识符
  611. - 枚举:
  612. - <code>remove_extra_spaces</code> 替换连续空格、换行符、制表符
  613. - <code>remove_urls_emails</code> 删除 URL、电子邮件地址
  614. - <code>enabled</code> (bool) 是否选中该规则,不传入文档 ID 时代表默认值
  615. - <code>segmentation</code> (object) 分段规则
  616. - <code>separator</code> 自定义分段标识符,目前仅允许设置一个分隔符。默认为 \n
  617. - <code>max_tokens</code> 最大长度(token)默认为 1000
  618. - <code>parent_mode</code> 父分段的召回模式 <code>full-doc</code> 全文召回 / <code>paragraph</code> 段落召回
  619. - <code>subchunk_segmentation</code> (object) 子分段规则
  620. - <code>separator</code> 分段标识符,目前仅允许设置一个分隔符。默认为 <code>***</code>
  621. - <code>max_tokens</code> 最大长度 (token) 需要校验小于父级的长度
  622. - <code>chunk_overlap</code> 分段重叠指的是在对数据进行分段时,段与段之间存在一定的重叠部分(选填)
  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='通过文件更新文档'
  681. name='#update-by-file'
  682. />
  683. <Row>
  684. <Col>
  685. 此接口基于已存在知识库,在此知识库的基础上通过文件更新文档的操作。
  686. ### Path
  687. <Properties>
  688. <Property name='dataset_id' type='string' key='dataset_id'>
  689. 知识库 ID
  690. </Property>
  691. <Property name='document_id' type='string' key='document_id'>
  692. 文档 ID
  693. </Property>
  694. </Properties>
  695. ### Request Body
  696. <Properties>
  697. <Property name='name' type='string' key='name'>
  698. 文档名称(选填)
  699. </Property>
  700. <Property name='file' type='multipart/form-data' key='file'>
  701. 需要上传的文件
  702. </Property>
  703. <Property name='process_rule' type='object' key='process_rule'>
  704. 处理规则(选填)
  705. - <code>mode</code> (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
  706. - <code>rules</code> (object) 自定义规则(自动模式下,该字段为空)
  707. - <code>pre_processing_rules</code> (array[object]) 预处理规则
  708. - <code>id</code> (string) 预处理规则的唯一标识符
  709. - 枚举:
  710. - <code>remove_extra_spaces</code> 替换连续空格、换行符、制表符
  711. - <code>remove_urls_emails</code> 删除 URL、电子邮件地址
  712. - <code>enabled</code> (bool) 是否选中该规则,不传入文档 ID 时代表默认值
  713. - <code>segmentation</code> (object) 分段规则
  714. - <code>separator</code> 自定义分段标识符,目前仅允许设置一个分隔符。默认为 \n
  715. - <code>max_tokens</code> 最大长度(token)默认为 1000
  716. - <code>parent_mode</code> 父分段的召回模式 <code>full-doc</code> 全文召回 / <code>paragraph</code> 段落召回
  717. - <code>subchunk_segmentation</code> (object) 子分段规则
  718. - <code>separator</code> 分段标识符,目前仅允许设置一个分隔符。默认为 <code>***</code>
  719. - <code>max_tokens</code> 最大长度 (token) 需要校验小于父级的长度
  720. - <code>chunk_overlap</code> 分段重叠指的是在对数据进行分段时,段与段之间存在一定的重叠部分(选填)
  721. - <code>doc_type</code> 文档类型(选填)Type of document (optional)
  722. - <code>book</code> 图书
  723. 文档记录一本书籍或出版物
  724. - <code>web_page</code> 网页
  725. 网页内容的文档记录
  726. - <code>paper</code> 学术论文/文章
  727. 学术论文或研究文章的记录
  728. - <code>social_media_post</code> 社交媒体帖子
  729. 社交媒体上的帖子内容
  730. - <code>wikipedia_entry</code> 维基百科条目
  731. 维基百科的词条内容
  732. - <code>personal_document</code> 个人文档
  733. 个人相关的文档记录
  734. - <code>business_document</code> 商业文档
  735. 商业相关的文档记录
  736. - <code>im_chat_log</code> 即时通讯记录
  737. 即时通讯的聊天记录
  738. - <code>synced_from_notion</code> Notion同步文档
  739. 从Notion同步的文档内容
  740. - <code>synced_from_github</code> GitHub同步文档
  741. 从GitHub同步的文档内容
  742. - <code>others</code> 其他文档类型
  743. 其他未列出的文档类型
  744. - <code>doc_metadata</code> 文档元数据(如提供文档类型则必填
  745. 字段因文档类型而异
  746. 针对图书类型 For <code>book</code>:
  747. - <code>title</code> 书名
  748. 书籍的标题
  749. - <code>language</code> 图书语言
  750. 书籍的语言
  751. - <code>author</code> 作者
  752. 书籍的作者
  753. - <code>publisher</code> 出版社
  754. 出版社的名称
  755. - <code>publication_date</code> 出版日期
  756. 书籍的出版日期
  757. - <code>isbn</code> ISBN号码
  758. 书籍的ISBN编号
  759. - <code>category</code> 图书分类
  760. 书籍的分类类别
  761. 针对网页类型 For <code>web_page</code>:
  762. - <code>title</code> 页面标题
  763. 网页的标题
  764. - <code>url</code> 页面网址
  765. 网页的URL地址
  766. - <code>language</code> 页面语言
  767. 网页的语言
  768. - <code>publish_date</code> 发布日期
  769. 网页的发布日期
  770. - <code>author/publisher</code> 作者/发布者
  771. 网页的作者或发布者
  772. - <code>topic/keywords</code> 主题/关键词
  773. 网页的主题或关键词
  774. - <code>description</code> 页面描述
  775. 网页的描述信息
  776. 请查看 [api/services/dataset_service.py](https://github.com/langgenius/dify/blob/main/api/services/dataset_service.py#L475) 了解各文档类型所需字段的详细信息。
  777. 针对"其他"类型文档,接受任何有效的JSON对象
  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='获取文档嵌入状态(进度)'
  833. name='#indexing_status'
  834. />
  835. <Row>
  836. <Col>
  837. ### Path
  838. <Properties>
  839. <Property name='dataset_id' type='string' key='dataset_id'>
  840. 知识库 ID
  841. </Property>
  842. <Property name='batch' type='string' key='batch'>
  843. 上传文档的批次号
  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='删除文档'
  886. name='#delete_document'
  887. />
  888. <Row>
  889. <Col>
  890. ### Path
  891. <Properties>
  892. <Property name='dataset_id' type='string' key='dataset_id'>
  893. 知识库 ID
  894. </Property>
  895. <Property name='document_id' type='string' key='document_id'>
  896. 文档 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='知识库文档列表'
  926. name='#dataset_document_list'
  927. />
  928. <Row>
  929. <Col>
  930. ### Path
  931. <Properties>
  932. <Property name='dataset_id' type='string' key='dataset_id'>
  933. 知识库 ID
  934. </Property>
  935. </Properties>
  936. ### Query
  937. <Properties>
  938. <Property name='keyword' type='string' key='keyword'>
  939. 搜索关键词,可选,目前仅搜索文档名称
  940. </Property>
  941. <Property name='page' type='string' key='page'>
  942. 页码,可选
  943. </Property>
  944. <Property name='limit' type='string' key='limit'>
  945. 返回条数,可选,默认 20,范围 1-100
  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='新增分段'
  998. name='#create_new_segment'
  999. />
  1000. <Row>
  1001. <Col>
  1002. ### Path
  1003. <Properties>
  1004. <Property name='dataset_id' type='string' key='dataset_id'>
  1005. 知识库 ID
  1006. </Property>
  1007. <Property name='document_id' type='string' key='document_id'>
  1008. 文档 ID
  1009. </Property>
  1010. </Properties>
  1011. ### Request Body
  1012. <Properties>
  1013. <Property name='segments' type='object list' key='segments'>
  1014. - <code>content</code> (text) 文本内容/问题内容,必填
  1015. - <code>answer</code> (text) 答案内容,非必填,如果知识库的模式为 Q&A 模式则传值
  1016. - <code>keywords</code> (list) 关键字,非必填
  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='查询文档分段'
  1081. name='#get_segment'
  1082. />
  1083. <Row>
  1084. <Col>
  1085. ### Path
  1086. <Properties>
  1087. <Property name='dataset_id' type='string' key='dataset_id'>
  1088. 知识库 ID
  1089. </Property>
  1090. <Property name='document_id' type='string' key='document_id'>
  1091. 文档 ID
  1092. </Property>
  1093. </Properties>
  1094. ### Query
  1095. <Properties>
  1096. <Property name='keyword' type='string' key='keyword'>
  1097. 搜索关键词,可选
  1098. </Property>
  1099. <Property name='status' type='string' key='status'>
  1100. 搜索状态,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='删除文档分段'
  1156. name='#delete_segment'
  1157. />
  1158. <Row>
  1159. <Col>
  1160. ### Path
  1161. <Properties>
  1162. <Property name='dataset_id' type='string' key='dataset_id'>
  1163. 知识库 ID
  1164. </Property>
  1165. <Property name='document_id' type='string' key='document_id'>
  1166. 文档 ID
  1167. </Property>
  1168. <Property name='segment_id' type='string' key='segment_id'>
  1169. 文档分段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}/documents/{document_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}/documents/{document_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='更新文档分段'
  1200. name='#update_segment'
  1201. />
  1202. <Row>
  1203. <Col>
  1204. ### POST
  1205. <Properties>
  1206. <Property name='dataset_id' type='string' key='dataset_id'>
  1207. 知识库 ID
  1208. </Property>
  1209. <Property name='document_id' type='string' key='document_id'>
  1210. 文档 ID
  1211. </Property>
  1212. <Property name='segment_id' type='string' key='segment_id'>
  1213. 文档分段ID
  1214. </Property>
  1215. </Properties>
  1216. ### Request Body
  1217. <Properties>
  1218. <Property name='segment' type='object' key='segment'>
  1219. - <code>content</code> (text) 文本内容/问题内容,必填
  1220. - <code>answer</code> (text) 答案内容,非必填,如果知识库的模式为 Q&A 模式则传值
  1221. - <code>keywords</code> (list) 关键字,非必填
  1222. - <code>enabled</code> (bool) false/true,非必填
  1223. - <code>regenerate_child_chunks</code> (bool) 是否重新生成子分段,非必填
  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 'Authorization: Bearer {api_key}' \
  1237. --header 'Content-Type: application/json' \
  1238. --data-raw '{
  1239. "segment": {
  1240. "content": "1",
  1241. "answer": "1",
  1242. "keywords": ["a"],
  1243. "enabled": false
  1244. }
  1245. }'
  1246. ```
  1247. </CodeGroup>
  1248. <CodeGroup title="Response">
  1249. ```json {{ title: 'Response' }}
  1250. {
  1251. "data": {
  1252. "id": "",
  1253. "position": 1,
  1254. "document_id": "",
  1255. "content": "1",
  1256. "answer": "1",
  1257. "word_count": 25,
  1258. "tokens": 0,
  1259. "keywords": [
  1260. "a"
  1261. ],
  1262. "index_node_id": "",
  1263. "index_node_hash": "",
  1264. "hit_count": 0,
  1265. "enabled": true,
  1266. "disabled_at": null,
  1267. "disabled_by": null,
  1268. "status": "completed",
  1269. "created_by": "",
  1270. "created_at": 1695312007,
  1271. "indexing_at": 1695312007,
  1272. "completed_at": 1695312007,
  1273. "error": null,
  1274. "stopped_at": null
  1275. },
  1276. "doc_form": "text_model"
  1277. }
  1278. ```
  1279. </CodeGroup>
  1280. </Col>
  1281. </Row>
  1282. <hr className='ml-0 mr-0' />
  1283. <Heading
  1284. url='/datasets/{dataset_id}/documents/{document_id}/upload-file'
  1285. method='GET'
  1286. title='获取上传文件'
  1287. name='#get_upload_file'
  1288. />
  1289. <Row>
  1290. <Col>
  1291. ### Path
  1292. <Properties>
  1293. <Property name='dataset_id' type='string' key='dataset_id'>
  1294. 知识库 ID
  1295. </Property>
  1296. <Property name='document_id' type='string' key='document_id'>
  1297. 文档 ID
  1298. </Property>
  1299. </Properties>
  1300. </Col>
  1301. <Col sticky>
  1302. <CodeGroup
  1303. title="Request"
  1304. tag="GET"
  1305. label="/datasets/{dataset_id}/documents/{document_id}/upload-file"
  1306. 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'`}
  1307. >
  1308. ```bash {{ title: 'cURL' }}
  1309. curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/upload-file' \
  1310. --header 'Authorization: Bearer {api_key}' \
  1311. --header 'Content-Type: application/json'
  1312. ```
  1313. </CodeGroup>
  1314. <CodeGroup title="Response">
  1315. ```json {{ title: 'Response' }}
  1316. {
  1317. "id": "file_id",
  1318. "name": "file_name",
  1319. "size": 1024,
  1320. "extension": "txt",
  1321. "url": "preview_url",
  1322. "download_url": "download_url",
  1323. "mime_type": "text/plain",
  1324. "created_by": "user_id",
  1325. "created_at": 1728734540,
  1326. }
  1327. ```
  1328. </CodeGroup>
  1329. </Col>
  1330. </Row>
  1331. <hr className='ml-0 mr-0' />
  1332. <Heading
  1333. url='/datasets/{dataset_id}/retrieve'
  1334. method='POST'
  1335. title='检索知识库'
  1336. name='#dataset_retrieval'
  1337. />
  1338. <Row>
  1339. <Col>
  1340. ### Path
  1341. <Properties>
  1342. <Property name='dataset_id' type='string' key='dataset_id'>
  1343. 知识库 ID
  1344. </Property>
  1345. </Properties>
  1346. ### Request Body
  1347. <Properties>
  1348. <Property name='query' type='string' key='query'>
  1349. 检索关键词
  1350. </Property>
  1351. <Property name='retrieval_model' type='object' key='retrieval_model'>
  1352. 检索参数(选填,如不填,按照默认方式召回)
  1353. - <code>search_method</code> (text) 检索方法:以下三个关键字之一,必填
  1354. - <code>keyword_search</code> 关键字检索
  1355. - <code>semantic_search</code> 语义检索
  1356. - <code>full_text_search</code> 全文检索
  1357. - <code>hybrid_search</code> 混合检索
  1358. - <code>reranking_enable</code> (bool) 是否启用 Reranking,非必填,如果检索模式为 semantic_search 模式或者 hybrid_search 则传值
  1359. - <code>reranking_mode</code> (object) Rerank 模型配置,非必填,如果启用了 reranking 则传值
  1360. - <code>reranking_provider_name</code> (string) Rerank 模型提供商
  1361. - <code>reranking_model_name</code> (string) Rerank 模型名称
  1362. - <code>weights</code> (float) 混合检索模式下语意检索的权重设置
  1363. - <code>top_k</code> (integer) 返回结果数量,非必填
  1364. - <code>score_threshold_enabled</code> (bool) 是否开启 score 阈值
  1365. - <code>score_threshold</code> (float) Score 阈值
  1366. </Property>
  1367. <Property name='external_retrieval_model' type='object' key='external_retrieval_model'>
  1368. 未启用字段
  1369. </Property>
  1370. </Properties>
  1371. </Col>
  1372. <Col sticky>
  1373. <CodeGroup
  1374. title="Request"
  1375. tag="POST"
  1376. label="/datasets/{dataset_id}/retrieve"
  1377. 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 '{
  1378. "query": "test",
  1379. "retrieval_model": {
  1380. "search_method": "keyword_search",
  1381. "reranking_enable": false,
  1382. "reranking_mode": null,
  1383. "reranking_model": {
  1384. "reranking_provider_name": "",
  1385. "reranking_model_name": ""
  1386. },
  1387. "weights": null,
  1388. "top_k": 1,
  1389. "score_threshold_enabled": false,
  1390. "score_threshold": null
  1391. }
  1392. }'`}
  1393. >
  1394. ```bash {{ title: 'cURL' }}
  1395. curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/retrieve' \
  1396. --header 'Authorization: Bearer {api_key}' \
  1397. --header 'Content-Type: application/json' \
  1398. --data-raw '{
  1399. "query": "test",
  1400. "retrieval_model": {
  1401. "search_method": "keyword_search",
  1402. "reranking_enable": false,
  1403. "reranking_mode": null,
  1404. "reranking_model": {
  1405. "reranking_provider_name": "",
  1406. "reranking_model_name": ""
  1407. },
  1408. "weights": null,
  1409. "top_k": 2,
  1410. "score_threshold_enabled": false,
  1411. "score_threshold": null
  1412. }
  1413. }'
  1414. ```
  1415. </CodeGroup>
  1416. <CodeGroup title="Response">
  1417. ```json {{ title: 'Response' }}
  1418. {
  1419. "query": {
  1420. "content": "test"
  1421. },
  1422. "records": [
  1423. {
  1424. "segment": {
  1425. "id": "7fa6f24f-8679-48b3-bc9d-bdf28d73f218",
  1426. "position": 1,
  1427. "document_id": "a8c6c36f-9f5d-4d7a-8472-f5d7b75d71d2",
  1428. "content": "Operation guide",
  1429. "answer": null,
  1430. "word_count": 847,
  1431. "tokens": 280,
  1432. "keywords": [
  1433. "install",
  1434. "java",
  1435. "base",
  1436. "scripts",
  1437. "jdk",
  1438. "manual",
  1439. "internal",
  1440. "opens",
  1441. "add",
  1442. "vmoptions"
  1443. ],
  1444. "index_node_id": "39dd8443-d960-45a8-bb46-7275ad7fbc8e",
  1445. "index_node_hash": "0189157697b3c6a418ccf8264a09699f25858975578f3467c76d6bfc94df1d73",
  1446. "hit_count": 0,
  1447. "enabled": true,
  1448. "disabled_at": null,
  1449. "disabled_by": null,
  1450. "status": "completed",
  1451. "created_by": "dbcb1ab5-90c8-41a7-8b78-73b235eb6f6f",
  1452. "created_at": 1728734540,
  1453. "indexing_at": 1728734552,
  1454. "completed_at": 1728734584,
  1455. "error": null,
  1456. "stopped_at": null,
  1457. "document": {
  1458. "id": "a8c6c36f-9f5d-4d7a-8472-f5d7b75d71d2",
  1459. "data_source_type": "upload_file",
  1460. "name": "readme.txt",
  1461. "doc_type": null
  1462. }
  1463. },
  1464. "score": 3.730463140527718e-05,
  1465. "tsne_position": null
  1466. }
  1467. ]
  1468. }
  1469. ```
  1470. </CodeGroup>
  1471. </Col>
  1472. </Row>
  1473. <hr className='ml-0 mr-0' />
  1474. <Row>
  1475. <Col>
  1476. ### 错误信息
  1477. <Properties>
  1478. <Property name='code' type='string' key='code'>
  1479. 返回的错误代码
  1480. </Property>
  1481. </Properties>
  1482. <Properties>
  1483. <Property name='status' type='number' key='status'>
  1484. 返回的错误状态
  1485. </Property>
  1486. </Properties>
  1487. <Properties>
  1488. <Property name='message' type='string' key='message'>
  1489. 返回的错误信息
  1490. </Property>
  1491. </Properties>
  1492. </Col>
  1493. <Col>
  1494. <CodeGroup title="Example">
  1495. ```json {{ title: 'Response' }}
  1496. {
  1497. "code": "no_file_uploaded",
  1498. "message": "Please upload your file.",
  1499. "status": 400
  1500. }
  1501. ```
  1502. </CodeGroup>
  1503. </Col>
  1504. </Row>
  1505. <table className="max-w-auto border-collapse border border-slate-400" style={{ maxWidth: 'none', width: 'auto' }}>
  1506. <thead style={{ background: '#f9fafc' }}>
  1507. <tr>
  1508. <th className="p-2 border border-slate-300">code</th>
  1509. <th className="p-2 border border-slate-300">status</th>
  1510. <th className="p-2 border border-slate-300">message</th>
  1511. </tr>
  1512. </thead>
  1513. <tbody>
  1514. <tr>
  1515. <td className="p-2 border border-slate-300">no_file_uploaded</td>
  1516. <td className="p-2 border border-slate-300">400</td>
  1517. <td className="p-2 border border-slate-300">Please upload your file.</td>
  1518. </tr>
  1519. <tr>
  1520. <td className="p-2 border border-slate-300">too_many_files</td>
  1521. <td className="p-2 border border-slate-300">400</td>
  1522. <td className="p-2 border border-slate-300">Only one file is allowed.</td>
  1523. </tr>
  1524. <tr>
  1525. <td className="p-2 border border-slate-300">file_too_large</td>
  1526. <td className="p-2 border border-slate-300">413</td>
  1527. <td className="p-2 border border-slate-300">File size exceeded.</td>
  1528. </tr>
  1529. <tr>
  1530. <td className="p-2 border border-slate-300">unsupported_file_type</td>
  1531. <td className="p-2 border border-slate-300">415</td>
  1532. <td className="p-2 border border-slate-300">File type not allowed.</td>
  1533. </tr>
  1534. <tr>
  1535. <td className="p-2 border border-slate-300">high_quality_dataset_only</td>
  1536. <td className="p-2 border border-slate-300">400</td>
  1537. <td className="p-2 border border-slate-300">Current operation only supports 'high-quality' datasets.</td>
  1538. </tr>
  1539. <tr>
  1540. <td className="p-2 border border-slate-300">dataset_not_initialized</td>
  1541. <td className="p-2 border border-slate-300">400</td>
  1542. <td className="p-2 border border-slate-300">The dataset is still being initialized or indexing. Please wait a moment.</td>
  1543. </tr>
  1544. <tr>
  1545. <td className="p-2 border border-slate-300">archived_document_immutable</td>
  1546. <td className="p-2 border border-slate-300">403</td>
  1547. <td className="p-2 border border-slate-300">The archived document is not editable.</td>
  1548. </tr>
  1549. <tr>
  1550. <td className="p-2 border border-slate-300">dataset_name_duplicate</td>
  1551. <td className="p-2 border border-slate-300">409</td>
  1552. <td className="p-2 border border-slate-300">The dataset name already exists. Please modify your dataset name.</td>
  1553. </tr>
  1554. <tr>
  1555. <td className="p-2 border border-slate-300">invalid_action</td>
  1556. <td className="p-2 border border-slate-300">400</td>
  1557. <td className="p-2 border border-slate-300">Invalid action.</td>
  1558. </tr>
  1559. <tr>
  1560. <td className="p-2 border border-slate-300">document_already_finished</td>
  1561. <td className="p-2 border border-slate-300">400</td>
  1562. <td className="p-2 border border-slate-300">The document has been processed. Please refresh the page or go to the document details.</td>
  1563. </tr>
  1564. <tr>
  1565. <td className="p-2 border border-slate-300">document_indexing</td>
  1566. <td className="p-2 border border-slate-300">400</td>
  1567. <td className="p-2 border border-slate-300">The document is being processed and cannot be edited.</td>
  1568. </tr>
  1569. <tr>
  1570. <td className="p-2 border border-slate-300">invalid_metadata</td>
  1571. <td className="p-2 border border-slate-300">400</td>
  1572. <td className="p-2 border border-slate-300">The metadata content is incorrect. Please check and verify.</td>
  1573. </tr>
  1574. </tbody>
  1575. </table>
  1576. <div className="pb-4" />