Documents.svelte 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  1. <script lang="ts">
  2. import { toast } from 'svelte-sonner';
  3. import { onMount, getContext, createEventDispatcher } from 'svelte';
  4. const dispatch = createEventDispatcher();
  5. import {
  6. getQuerySettings,
  7. updateQuerySettings,
  8. resetVectorDB,
  9. getEmbeddingConfig,
  10. updateEmbeddingConfig,
  11. getRerankingConfig,
  12. updateRerankingConfig,
  13. getRAGConfig,
  14. updateRAGConfig
  15. } from '$lib/apis/retrieval';
  16. import { reindexKnowledgeFiles } from '$lib/apis/knowledge';
  17. import { deleteAllFiles } from '$lib/apis/files';
  18. import ResetUploadDirConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
  19. import ResetVectorDBConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
  20. import ReindexKnowledgeFilesConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
  21. import SensitiveInput from '$lib/components/common/SensitiveInput.svelte';
  22. import Tooltip from '$lib/components/common/Tooltip.svelte';
  23. import Switch from '$lib/components/common/Switch.svelte';
  24. import Textarea from '$lib/components/common/Textarea.svelte';
  25. import Spinner from '$lib/components/common/Spinner.svelte';
  26. const i18n = getContext('i18n');
  27. let updateEmbeddingModelLoading = false;
  28. let updateRerankingModelLoading = false;
  29. let showResetConfirm = false;
  30. let showResetUploadDirConfirm = false;
  31. let showReindexConfirm = false;
  32. let embeddingEngine = '';
  33. let embeddingModel = '';
  34. let embeddingBatchSize = 1;
  35. let rerankingModel = '';
  36. let OpenAIUrl = '';
  37. let OpenAIKey = '';
  38. let OllamaUrl = '';
  39. let OllamaKey = '';
  40. let querySettings = {
  41. template: '',
  42. r: 0.0,
  43. k: 4,
  44. k_reranker: 4,
  45. hybrid: false
  46. };
  47. let RAGConfig = null;
  48. const embeddingModelUpdateHandler = async () => {
  49. if (embeddingEngine === '' && embeddingModel.split('/').length - 1 > 1) {
  50. toast.error(
  51. $i18n.t(
  52. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  53. )
  54. );
  55. return;
  56. }
  57. if (embeddingEngine === 'ollama' && embeddingModel === '') {
  58. toast.error(
  59. $i18n.t(
  60. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  61. )
  62. );
  63. return;
  64. }
  65. if (embeddingEngine === 'openai' && embeddingModel === '') {
  66. toast.error(
  67. $i18n.t(
  68. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  69. )
  70. );
  71. return;
  72. }
  73. if ((embeddingEngine === 'openai' && OpenAIKey === '') || OpenAIUrl === '') {
  74. toast.error($i18n.t('OpenAI URL/Key required.'));
  75. return;
  76. }
  77. console.log('Update embedding model attempt:', embeddingModel);
  78. updateEmbeddingModelLoading = true;
  79. const res = await updateEmbeddingConfig(localStorage.token, {
  80. embedding_engine: embeddingEngine,
  81. embedding_model: embeddingModel,
  82. embedding_batch_size: embeddingBatchSize,
  83. ollama_config: {
  84. key: OllamaKey,
  85. url: OllamaUrl
  86. },
  87. openai_config: {
  88. key: OpenAIKey,
  89. url: OpenAIUrl
  90. }
  91. }).catch(async (error) => {
  92. toast.error(`${error}`);
  93. await setEmbeddingConfig();
  94. return null;
  95. });
  96. updateEmbeddingModelLoading = false;
  97. if (res) {
  98. console.log('embeddingModelUpdateHandler:', res);
  99. if (res.status === true) {
  100. toast.success($i18n.t('Embedding model set to "{{embedding_model}}"', res), {
  101. duration: 1000 * 10
  102. });
  103. }
  104. }
  105. };
  106. const submitHandler = async () => {
  107. if (
  108. RAGConfig.CONTENT_EXTRACTION_ENGINE === 'external' &&
  109. RAGConfig.EXTERNAL_DOCUMENT_LOADER_URL === ''
  110. ) {
  111. toast.error($i18n.t('External Document Loader URL required.'));
  112. return;
  113. }
  114. if (RAGConfig.CONTENT_EXTRACTION_ENGINE === 'tika' && RAGConfig.TIKA_SERVER_URL === '') {
  115. toast.error($i18n.t('Tika Server URL required.'));
  116. return;
  117. }
  118. if (RAGConfig.CONTENT_EXTRACTION_ENGINE === 'docling' && RAGConfig.DOCLING_SERVER_URL === '') {
  119. toast.error($i18n.t('Docling Server URL required.'));
  120. return;
  121. }
  122. if (
  123. RAGConfig.CONTENT_EXTRACTION_ENGINE === 'docling' &&
  124. ((RAGConfig.DOCLING_OCR_ENGINE === '' && RAGConfig.DOCLING_OCR_LANG !== '') ||
  125. (RAGConfig.DOCLING_OCR_ENGINE !== '' && RAGConfig.DOCLING_OCR_LANG === ''))
  126. ) {
  127. toast.error(
  128. $i18n.t('Both Docling OCR Engine and Language(s) must be provided or both left empty.')
  129. );
  130. return;
  131. }
  132. if (
  133. RAGConfig.CONTENT_EXTRACTION_ENGINE === 'document_intelligence' &&
  134. (RAGConfig.DOCUMENT_INTELLIGENCE_ENDPOINT === '' ||
  135. RAGConfig.DOCUMENT_INTELLIGENCE_KEY === '')
  136. ) {
  137. toast.error($i18n.t('Document Intelligence endpoint and key required.'));
  138. return;
  139. }
  140. if (
  141. RAGConfig.CONTENT_EXTRACTION_ENGINE === 'mistral_ocr' &&
  142. RAGConfig.MISTRAL_OCR_API_KEY === ''
  143. ) {
  144. toast.error($i18n.t('Mistral OCR API Key required.'));
  145. return;
  146. }
  147. if (!RAGConfig.BYPASS_EMBEDDING_AND_RETRIEVAL) {
  148. await embeddingModelUpdateHandler();
  149. }
  150. const res = await updateRAGConfig(localStorage.token, RAGConfig);
  151. dispatch('save');
  152. };
  153. const setEmbeddingConfig = async () => {
  154. const embeddingConfig = await getEmbeddingConfig(localStorage.token);
  155. if (embeddingConfig) {
  156. embeddingEngine = embeddingConfig.embedding_engine;
  157. embeddingModel = embeddingConfig.embedding_model;
  158. embeddingBatchSize = embeddingConfig.embedding_batch_size ?? 1;
  159. OpenAIKey = embeddingConfig.openai_config.key;
  160. OpenAIUrl = embeddingConfig.openai_config.url;
  161. OllamaKey = embeddingConfig.ollama_config.key;
  162. OllamaUrl = embeddingConfig.ollama_config.url;
  163. }
  164. };
  165. onMount(async () => {
  166. await setEmbeddingConfig();
  167. RAGConfig = await getRAGConfig(localStorage.token);
  168. });
  169. </script>
  170. <ResetUploadDirConfirmDialog
  171. bind:show={showResetUploadDirConfirm}
  172. on:confirm={async () => {
  173. const res = await deleteAllFiles(localStorage.token).catch((error) => {
  174. toast.error(`${error}`);
  175. return null;
  176. });
  177. if (res) {
  178. toast.success($i18n.t('Success'));
  179. }
  180. }}
  181. />
  182. <ResetVectorDBConfirmDialog
  183. bind:show={showResetConfirm}
  184. on:confirm={() => {
  185. const res = resetVectorDB(localStorage.token).catch((error) => {
  186. toast.error(`${error}`);
  187. return null;
  188. });
  189. if (res) {
  190. toast.success($i18n.t('Success'));
  191. }
  192. }}
  193. />
  194. <ReindexKnowledgeFilesConfirmDialog
  195. bind:show={showReindexConfirm}
  196. on:confirm={async () => {
  197. const res = await reindexKnowledgeFiles(localStorage.token).catch((error) => {
  198. toast.error(`${error}`);
  199. return null;
  200. });
  201. if (res) {
  202. toast.success($i18n.t('Success'));
  203. }
  204. }}
  205. />
  206. <form
  207. class="flex flex-col h-full justify-between space-y-3 text-sm"
  208. on:submit|preventDefault={() => {
  209. submitHandler();
  210. }}
  211. >
  212. {#if RAGConfig}
  213. <div class=" space-y-2.5 overflow-y-scroll scrollbar-hidden h-full pr-1.5">
  214. <div class="">
  215. <div class="mb-3">
  216. <div class=" mb-2.5 text-base font-medium">{$i18n.t('General')}</div>
  217. <hr class=" border-gray-100 dark:border-gray-850 my-2" />
  218. <div class="mb-2.5 flex flex-col w-full justify-between">
  219. <div class="flex w-full justify-between mb-1">
  220. <div class="self-center text-xs font-medium">
  221. {$i18n.t('Content Extraction Engine')}
  222. </div>
  223. <div class="">
  224. <select
  225. class="dark:bg-gray-900 w-fit pr-8 rounded-sm px-2 text-xs bg-transparent outline-hidden text-right"
  226. bind:value={RAGConfig.CONTENT_EXTRACTION_ENGINE}
  227. >
  228. <option value="">{$i18n.t('Default')}</option>
  229. <option value="external">{$i18n.t('External')}</option>
  230. <option value="tika">{$i18n.t('Tika')}</option>
  231. <option value="docling">{$i18n.t('Docling')}</option>
  232. <option value="document_intelligence">{$i18n.t('Document Intelligence')}</option>
  233. <option value="mistral_ocr">{$i18n.t('Mistral OCR')}</option>
  234. </select>
  235. </div>
  236. </div>
  237. {#if RAGConfig.CONTENT_EXTRACTION_ENGINE === ''}
  238. <div class="flex w-full mt-1">
  239. <div class="flex-1 flex justify-between">
  240. <div class=" self-center text-xs font-medium">
  241. {$i18n.t('PDF Extract Images (OCR)')}
  242. </div>
  243. <div class="flex items-center relative">
  244. <Switch bind:state={RAGConfig.PDF_EXTRACT_IMAGES} />
  245. </div>
  246. </div>
  247. </div>
  248. {:else if RAGConfig.CONTENT_EXTRACTION_ENGINE === 'external'}
  249. <div class="my-0.5 flex gap-2 pr-2">
  250. <input
  251. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  252. placeholder={$i18n.t('Enter External Document Loader URL')}
  253. bind:value={RAGConfig.EXTERNAL_DOCUMENT_LOADER_URL}
  254. />
  255. <SensitiveInput
  256. placeholder={$i18n.t('Enter External Document Loader API Key')}
  257. required={false}
  258. bind:value={RAGConfig.EXTERNAL_DOCUMENT_LOADER_API_KEY}
  259. />
  260. </div>
  261. {:else if RAGConfig.CONTENT_EXTRACTION_ENGINE === 'tika'}
  262. <div class="flex w-full mt-1">
  263. <div class="flex-1 mr-2">
  264. <input
  265. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  266. placeholder={$i18n.t('Enter Tika Server URL')}
  267. bind:value={RAGConfig.TIKA_SERVER_URL}
  268. />
  269. </div>
  270. </div>
  271. {:else if RAGConfig.CONTENT_EXTRACTION_ENGINE === 'docling'}
  272. <div class="flex w-full mt-1">
  273. <input
  274. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  275. placeholder={$i18n.t('Enter Docling Server URL')}
  276. bind:value={RAGConfig.DOCLING_SERVER_URL}
  277. />
  278. </div>
  279. <div class="flex w-full mt-2">
  280. <input
  281. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  282. placeholder={$i18n.t('Enter Docling OCR Engine')}
  283. bind:value={RAGConfig.DOCLING_OCR_ENGINE}
  284. />
  285. <input
  286. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  287. placeholder={$i18n.t('Enter Docling OCR Language(s)')}
  288. bind:value={RAGConfig.DOCLING_OCR_LANG}
  289. />
  290. </div>
  291. <div class="flex w-full mt-2">
  292. <div class="flex-1 flex justify-between">
  293. <div class=" self-center text-xs font-medium">
  294. {$i18n.t('Describe Pictures in Documents')}
  295. </div>
  296. <div class="flex items-center relative">
  297. <Switch bind:state={RAGConfig.DOCLING_DO_PICTURE_DESCRIPTION} />
  298. </div>
  299. </div>
  300. </div>
  301. {:else if RAGConfig.CONTENT_EXTRACTION_ENGINE === 'document_intelligence'}
  302. <div class="my-0.5 flex gap-2 pr-2">
  303. <input
  304. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  305. placeholder={$i18n.t('Enter Document Intelligence Endpoint')}
  306. bind:value={RAGConfig.DOCUMENT_INTELLIGENCE_ENDPOINT}
  307. />
  308. <SensitiveInput
  309. placeholder={$i18n.t('Enter Document Intelligence Key')}
  310. bind:value={RAGConfig.DOCUMENT_INTELLIGENCE_KEY}
  311. />
  312. </div>
  313. {:else if RAGConfig.CONTENT_EXTRACTION_ENGINE === 'mistral_ocr'}
  314. <div class="my-0.5 flex gap-2 pr-2">
  315. <SensitiveInput
  316. placeholder={$i18n.t('Enter Mistral API Key')}
  317. bind:value={RAGConfig.MISTRAL_OCR_API_KEY}
  318. />
  319. </div>
  320. {/if}
  321. </div>
  322. <div class=" mb-2.5 flex w-full justify-between">
  323. <div class=" self-center text-xs font-medium">
  324. <Tooltip content={$i18n.t('Full Context Mode')} placement="top-start">
  325. {$i18n.t('Bypass Embedding and Retrieval')}
  326. </Tooltip>
  327. </div>
  328. <div class="flex items-center relative">
  329. <Tooltip
  330. content={RAGConfig.BYPASS_EMBEDDING_AND_RETRIEVAL
  331. ? $i18n.t(
  332. 'Inject the entire content as context for comprehensive processing, this is recommended for complex queries.'
  333. )
  334. : $i18n.t(
  335. 'Default to segmented retrieval for focused and relevant content extraction, this is recommended for most cases.'
  336. )}
  337. >
  338. <Switch bind:state={RAGConfig.BYPASS_EMBEDDING_AND_RETRIEVAL} />
  339. </Tooltip>
  340. </div>
  341. </div>
  342. {#if !RAGConfig.BYPASS_EMBEDDING_AND_RETRIEVAL}
  343. <div class=" mb-2.5 flex w-full justify-between">
  344. <div class=" self-center text-xs font-medium">{$i18n.t('Text Splitter')}</div>
  345. <div class="flex items-center relative">
  346. <select
  347. class="dark:bg-gray-900 w-fit pr-8 rounded-sm px-2 text-xs bg-transparent outline-hidden text-right"
  348. bind:value={RAGConfig.TEXT_SPLITTER}
  349. >
  350. <option value="">{$i18n.t('Default')} ({$i18n.t('Character')})</option>
  351. <option value="token">{$i18n.t('Token')} ({$i18n.t('Tiktoken')})</option>
  352. </select>
  353. </div>
  354. </div>
  355. <div class=" mb-2.5 flex w-full justify-between">
  356. <div class=" flex gap-1.5 w-full">
  357. <div class=" w-full justify-between">
  358. <div class="self-center text-xs font-medium min-w-fit mb-1">
  359. {$i18n.t('Chunk Size')}
  360. </div>
  361. <div class="self-center">
  362. <input
  363. class=" w-full rounded-lg py-1.5 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-hidden"
  364. type="number"
  365. placeholder={$i18n.t('Enter Chunk Size')}
  366. bind:value={RAGConfig.CHUNK_SIZE}
  367. autocomplete="off"
  368. min="0"
  369. />
  370. </div>
  371. </div>
  372. <div class="w-full">
  373. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  374. {$i18n.t('Chunk Overlap')}
  375. </div>
  376. <div class="self-center">
  377. <input
  378. class="w-full rounded-lg py-1.5 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-hidden"
  379. type="number"
  380. placeholder={$i18n.t('Enter Chunk Overlap')}
  381. bind:value={RAGConfig.CHUNK_OVERLAP}
  382. autocomplete="off"
  383. min="0"
  384. />
  385. </div>
  386. </div>
  387. </div>
  388. </div>
  389. {/if}
  390. </div>
  391. {#if !RAGConfig.BYPASS_EMBEDDING_AND_RETRIEVAL}
  392. <div class="mb-3">
  393. <div class=" mb-2.5 text-base font-medium">{$i18n.t('Embedding')}</div>
  394. <hr class=" border-gray-100 dark:border-gray-850 my-2" />
  395. <div class=" mb-2.5 flex flex-col w-full justify-between">
  396. <div class="flex w-full justify-between">
  397. <div class=" self-center text-xs font-medium">
  398. {$i18n.t('Embedding Model Engine')}
  399. </div>
  400. <div class="flex items-center relative">
  401. <select
  402. class="dark:bg-gray-900 w-fit pr-8 rounded-sm px-2 p-1 text-xs bg-transparent outline-hidden text-right"
  403. bind:value={embeddingEngine}
  404. placeholder="Select an embedding model engine"
  405. on:change={(e) => {
  406. if (e.target.value === 'ollama') {
  407. embeddingModel = '';
  408. } else if (e.target.value === 'openai') {
  409. embeddingModel = 'text-embedding-3-small';
  410. } else if (e.target.value === '') {
  411. embeddingModel = 'sentence-transformers/all-MiniLM-L6-v2';
  412. }
  413. }}
  414. >
  415. <option value="">{$i18n.t('Default (SentenceTransformers)')}</option>
  416. <option value="ollama">{$i18n.t('Ollama')}</option>
  417. <option value="openai">{$i18n.t('OpenAI')}</option>
  418. </select>
  419. </div>
  420. </div>
  421. {#if embeddingEngine === 'openai'}
  422. <div class="my-0.5 flex gap-2 pr-2">
  423. <input
  424. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  425. placeholder={$i18n.t('API Base URL')}
  426. bind:value={OpenAIUrl}
  427. required
  428. />
  429. <SensitiveInput placeholder={$i18n.t('API Key')} bind:value={OpenAIKey} />
  430. </div>
  431. {:else if embeddingEngine === 'ollama'}
  432. <div class="my-0.5 flex gap-2 pr-2">
  433. <input
  434. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  435. placeholder={$i18n.t('API Base URL')}
  436. bind:value={OllamaUrl}
  437. required
  438. />
  439. <SensitiveInput
  440. placeholder={$i18n.t('API Key')}
  441. bind:value={OllamaKey}
  442. required={false}
  443. />
  444. </div>
  445. {/if}
  446. </div>
  447. <div class=" mb-2.5 flex flex-col w-full">
  448. <div class=" mb-1 text-xs font-medium">{$i18n.t('Embedding Model')}</div>
  449. <div class="">
  450. {#if embeddingEngine === 'ollama'}
  451. <div class="flex w-full">
  452. <div class="flex-1 mr-2">
  453. <input
  454. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  455. bind:value={embeddingModel}
  456. placeholder={$i18n.t('Set embedding model')}
  457. required
  458. />
  459. </div>
  460. </div>
  461. {:else}
  462. <div class="flex w-full">
  463. <div class="flex-1 mr-2">
  464. <input
  465. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  466. placeholder={$i18n.t('Set embedding model (e.g. {{model}})', {
  467. model: embeddingModel.slice(-40)
  468. })}
  469. bind:value={embeddingModel}
  470. />
  471. </div>
  472. {#if embeddingEngine === ''}
  473. <button
  474. class="px-2.5 bg-transparent text-gray-800 dark:bg-transparent dark:text-gray-100 rounded-lg transition"
  475. on:click={() => {
  476. embeddingModelUpdateHandler();
  477. }}
  478. disabled={updateEmbeddingModelLoading}
  479. >
  480. {#if updateEmbeddingModelLoading}
  481. <div class="self-center">
  482. <svg
  483. class=" w-4 h-4"
  484. viewBox="0 0 24 24"
  485. fill="currentColor"
  486. xmlns="http://www.w3.org/2000/svg"
  487. >
  488. <style>
  489. .spinner_ajPY {
  490. transform-origin: center;
  491. animation: spinner_AtaB 0.75s infinite linear;
  492. }
  493. @keyframes spinner_AtaB {
  494. 100% {
  495. transform: rotate(360deg);
  496. }
  497. }
  498. </style>
  499. <path
  500. d="M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"
  501. opacity=".25"
  502. />
  503. <path
  504. d="M10.14,1.16a11,11,0,0,0-9,8.92A1.59,1.59,0,0,0,2.46,12,1.52,1.52,0,0,0,4.11,10.7a8,8,0,0,1,6.66-6.61A1.42,1.42,0,0,0,12,2.69h0A1.57,1.57,0,0,0,10.14,1.16Z"
  505. class="spinner_ajPY"
  506. />
  507. </svg>
  508. </div>
  509. {:else}
  510. <svg
  511. xmlns="http://www.w3.org/2000/svg"
  512. viewBox="0 0 16 16"
  513. fill="currentColor"
  514. class="w-4 h-4"
  515. >
  516. <path
  517. d="M8.75 2.75a.75.75 0 0 0-1.5 0v5.69L5.03 6.22a.75.75 0 0 0-1.06 1.06l3.5 3.5a.75.75 0 0 0 1.06 0l3.5-3.5a.75.75 0 0 0-1.06-1.06L8.75 8.44V2.75Z"
  518. />
  519. <path
  520. d="M3.5 9.75a.75.75 0 0 0-1.5 0v1.5A2.75 2.75 0 0 0 4.75 14h6.5A2.75 2.75 0 0 0 14 11.25v-1.5a.75.75 0 0 0-1.5 0v1.5c0 .69-.56 1.25-1.25 1.25h-6.5c-.69 0-1.25-.56-1.25-1.25v-1.5Z"
  521. />
  522. </svg>
  523. {/if}
  524. </button>
  525. {/if}
  526. </div>
  527. {/if}
  528. </div>
  529. <div class="mt-1 mb-1 text-xs text-gray-400 dark:text-gray-500">
  530. {$i18n.t(
  531. 'Warning: If you update or change your embedding model, you will need to re-import all documents.'
  532. )}
  533. </div>
  534. </div>
  535. {#if embeddingEngine === 'ollama' || embeddingEngine === 'openai'}
  536. <div class=" mb-2.5 flex w-full justify-between">
  537. <div class=" self-center text-xs font-medium">
  538. {$i18n.t('Embedding Batch Size')}
  539. </div>
  540. <div class="">
  541. <input
  542. bind:value={embeddingBatchSize}
  543. type="number"
  544. class=" bg-transparent text-center w-14 outline-none"
  545. min="-2"
  546. max="16000"
  547. step="1"
  548. />
  549. </div>
  550. </div>
  551. {/if}
  552. </div>
  553. <div class="mb-3">
  554. <div class=" mb-2.5 text-base font-medium">{$i18n.t('Retrieval')}</div>
  555. <hr class=" border-gray-100 dark:border-gray-850 my-2" />
  556. <div class=" mb-2.5 flex w-full justify-between">
  557. <div class=" self-center text-xs font-medium">{$i18n.t('Full Context Mode')}</div>
  558. <div class="flex items-center relative">
  559. <Tooltip
  560. content={RAGConfig.RAG_FULL_CONTEXT
  561. ? $i18n.t(
  562. 'Inject the entire content as context for comprehensive processing, this is recommended for complex queries.'
  563. )
  564. : $i18n.t(
  565. 'Default to segmented retrieval for focused and relevant content extraction, this is recommended for most cases.'
  566. )}
  567. >
  568. <Switch bind:state={RAGConfig.RAG_FULL_CONTEXT} />
  569. </Tooltip>
  570. </div>
  571. </div>
  572. {#if !RAGConfig.RAG_FULL_CONTEXT}
  573. <div class=" mb-2.5 flex w-full justify-between">
  574. <div class=" self-center text-xs font-medium">{$i18n.t('Hybrid Search')}</div>
  575. <div class="flex items-center relative">
  576. <Switch
  577. bind:state={RAGConfig.ENABLE_RAG_HYBRID_SEARCH}
  578. on:change={() => {
  579. submitHandler();
  580. }}
  581. />
  582. </div>
  583. </div>
  584. {#if RAGConfig.ENABLE_RAG_HYBRID_SEARCH === true}
  585. <div class=" mb-2.5 flex flex-col w-full justify-between">
  586. <div class="flex w-full justify-between">
  587. <div class=" self-center text-xs font-medium">
  588. {$i18n.t('Reranking Engine')}
  589. </div>
  590. <div class="flex items-center relative">
  591. <select
  592. class="dark:bg-gray-900 w-fit pr-8 rounded-sm px-2 p-1 text-xs bg-transparent outline-hidden text-right"
  593. bind:value={RAGConfig.RAG_RERANKING_ENGINE}
  594. placeholder="Select a reranking model engine"
  595. on:change={(e) => {
  596. if (e.target.value === 'external') {
  597. RAGConfig.RAG_RERANKING_MODEL = '';
  598. } else if (e.target.value === '') {
  599. RAGConfig.RAG_RERANKING_MODEL = 'BAAI/bge-reranker-v2-m3';
  600. }
  601. }}
  602. >
  603. <option value="">{$i18n.t('Default (SentenceTransformers)')}</option>
  604. <option value="external">{$i18n.t('External')}</option>
  605. </select>
  606. </div>
  607. </div>
  608. {#if RAGConfig.RAG_RERANKING_ENGINE === 'external'}
  609. <div class="my-0.5 flex gap-2 pr-2">
  610. <input
  611. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  612. placeholder={$i18n.t('API Base URL')}
  613. bind:value={RAGConfig.RAG_EXTERNAL_RERANKER_URL}
  614. required
  615. />
  616. <SensitiveInput
  617. placeholder={$i18n.t('API Key')}
  618. bind:value={RAGConfig.RAG_EXTERNAL_RERANKER_API_KEY}
  619. required={false}
  620. />
  621. </div>
  622. {/if}
  623. </div>
  624. <div class=" mb-2.5 flex flex-col w-full">
  625. <div class=" mb-1 text-xs font-medium">{$i18n.t('Reranking Model')}</div>
  626. <div class="">
  627. <div class="flex w-full">
  628. <div class="flex-1 mr-2">
  629. <input
  630. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  631. placeholder={$i18n.t('Set reranking model (e.g. {{model}})', {
  632. model: 'BAAI/bge-reranker-v2-m3'
  633. })}
  634. bind:value={RAGConfig.RAG_RERANKING_MODEL}
  635. />
  636. </div>
  637. </div>
  638. </div>
  639. </div>
  640. {/if}
  641. <div class=" mb-2.5 flex w-full justify-between">
  642. <div class=" self-center text-xs font-medium">{$i18n.t('Top K')}</div>
  643. <div class="flex items-center relative">
  644. <input
  645. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  646. type="number"
  647. placeholder={$i18n.t('Enter Top K')}
  648. bind:value={RAGConfig.TOP_K}
  649. autocomplete="off"
  650. min="0"
  651. />
  652. </div>
  653. </div>
  654. {#if RAGConfig.ENABLE_RAG_HYBRID_SEARCH === true}
  655. <div class="mb-2.5 flex w-full justify-between">
  656. <div class="self-center text-xs font-medium">{$i18n.t('Top K Reranker')}</div>
  657. <div class="flex items-center relative">
  658. <input
  659. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  660. type="number"
  661. placeholder={$i18n.t('Enter Top K Reranker')}
  662. bind:value={RAGConfig.TOP_K_RERANKER}
  663. autocomplete="off"
  664. min="0"
  665. />
  666. </div>
  667. </div>
  668. {/if}
  669. {#if RAGConfig.ENABLE_RAG_HYBRID_SEARCH === true}
  670. <div class=" mb-2.5 flex flex-col w-full justify-between">
  671. <div class=" flex w-full justify-between">
  672. <div class=" self-center text-xs font-medium">
  673. {$i18n.t('Relevance Threshold')}
  674. </div>
  675. <div class="flex items-center relative">
  676. <input
  677. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  678. type="number"
  679. step="0.01"
  680. placeholder={$i18n.t('Enter Score')}
  681. bind:value={RAGConfig.RELEVANCE_THRESHOLD}
  682. autocomplete="off"
  683. min="0.0"
  684. title={$i18n.t(
  685. 'The score should be a value between 0.0 (0%) and 1.0 (100%).'
  686. )}
  687. />
  688. </div>
  689. </div>
  690. <div class="mt-1 text-xs text-gray-400 dark:text-gray-500">
  691. {$i18n.t(
  692. 'Note: If you set a minimum score, the search will only return documents with a score greater than or equal to the minimum score.'
  693. )}
  694. </div>
  695. </div>
  696. {/if}
  697. {/if}
  698. <div class=" mb-2.5 flex flex-col w-full justify-between">
  699. <div class=" mb-1 text-xs font-medium">{$i18n.t('RAG Template')}</div>
  700. <div class="flex w-full items-center relative">
  701. <Tooltip
  702. content={$i18n.t(
  703. 'Leave empty to use the default prompt, or enter a custom prompt'
  704. )}
  705. placement="top-start"
  706. className="w-full"
  707. >
  708. <Textarea
  709. bind:value={RAGConfig.RAG_TEMPLATE}
  710. placeholder={$i18n.t(
  711. 'Leave empty to use the default prompt, or enter a custom prompt'
  712. )}
  713. />
  714. </Tooltip>
  715. </div>
  716. </div>
  717. </div>
  718. {/if}
  719. <div class="mb-3">
  720. <div class=" mb-2.5 text-base font-medium">{$i18n.t('Files')}</div>
  721. <hr class=" border-gray-100 dark:border-gray-850 my-2" />
  722. <div class=" mb-2.5 flex w-full justify-between">
  723. <div class=" self-center text-xs font-medium">{$i18n.t('Max Upload Size')}</div>
  724. <div class="flex items-center relative">
  725. <Tooltip
  726. content={$i18n.t(
  727. 'The maximum file size in MB. If the file size exceeds this limit, the file will not be uploaded.'
  728. )}
  729. placement="top-start"
  730. >
  731. <input
  732. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  733. type="number"
  734. placeholder={$i18n.t('Leave empty for unlimited')}
  735. bind:value={RAGConfig.FILE_MAX_SIZE}
  736. autocomplete="off"
  737. min="0"
  738. />
  739. </Tooltip>
  740. </div>
  741. </div>
  742. <div class=" mb-2.5 flex w-full justify-between">
  743. <div class=" self-center text-xs font-medium">{$i18n.t('Max Upload Count')}</div>
  744. <div class="flex items-center relative">
  745. <Tooltip
  746. content={$i18n.t(
  747. 'The maximum number of files that can be used at once in chat. If the number of files exceeds this limit, the files will not be uploaded.'
  748. )}
  749. placement="top-start"
  750. >
  751. <input
  752. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  753. type="number"
  754. placeholder={$i18n.t('Leave empty for unlimited')}
  755. bind:value={RAGConfig.FILE_MAX_COUNT}
  756. autocomplete="off"
  757. min="0"
  758. />
  759. </Tooltip>
  760. </div>
  761. </div>
  762. </div>
  763. <div class="mb-3">
  764. <div class=" mb-2.5 text-base font-medium">{$i18n.t('Integration')}</div>
  765. <hr class=" border-gray-100 dark:border-gray-850 my-2" />
  766. <div class=" mb-2.5 flex w-full justify-between">
  767. <div class=" self-center text-xs font-medium">{$i18n.t('Google Drive')}</div>
  768. <div class="flex items-center relative">
  769. <Switch bind:state={RAGConfig.ENABLE_GOOGLE_DRIVE_INTEGRATION} />
  770. </div>
  771. </div>
  772. <div class=" mb-2.5 flex w-full justify-between">
  773. <div class=" self-center text-xs font-medium">{$i18n.t('OneDrive')}</div>
  774. <div class="flex items-center relative">
  775. <Switch bind:state={RAGConfig.ENABLE_ONEDRIVE_INTEGRATION} />
  776. </div>
  777. </div>
  778. </div>
  779. <div class="mb-3">
  780. <div class=" mb-2.5 text-base font-medium">{$i18n.t('Danger Zone')}</div>
  781. <hr class=" border-gray-100 dark:border-gray-850 my-2" />
  782. <div class=" mb-2.5 flex w-full justify-between">
  783. <div class=" self-center text-xs font-medium">{$i18n.t('Reset Upload Directory')}</div>
  784. <div class="flex items-center relative">
  785. <button
  786. class="text-xs"
  787. on:click={() => {
  788. showResetUploadDirConfirm = true;
  789. }}
  790. >
  791. {$i18n.t('Reset')}
  792. </button>
  793. </div>
  794. </div>
  795. <div class=" mb-2.5 flex w-full justify-between">
  796. <div class=" self-center text-xs font-medium">
  797. {$i18n.t('Reset Vector Storage/Knowledge')}
  798. </div>
  799. <div class="flex items-center relative">
  800. <button
  801. class="text-xs"
  802. on:click={() => {
  803. showResetConfirm = true;
  804. }}
  805. >
  806. {$i18n.t('Reset')}
  807. </button>
  808. </div>
  809. </div>
  810. <div class=" mb-2.5 flex w-full justify-between">
  811. <div class=" self-center text-xs font-medium">
  812. {$i18n.t('Reindex Knowledge Base Vectors')}
  813. </div>
  814. <div class="flex items-center relative">
  815. <button
  816. class="text-xs"
  817. on:click={() => {
  818. showReindexConfirm = true;
  819. }}
  820. >
  821. {$i18n.t('Reindex')}
  822. </button>
  823. </div>
  824. </div>
  825. </div>
  826. </div>
  827. </div>
  828. <div class="flex justify-end pt-3 text-sm font-medium">
  829. <button
  830. class="px-3.5 py-1.5 text-sm font-medium bg-black hover:bg-gray-900 text-white dark:bg-white dark:text-black dark:hover:bg-gray-100 transition rounded-full"
  831. type="submit"
  832. >
  833. {$i18n.t('Save')}
  834. </button>
  835. </div>
  836. {:else}
  837. <div class="flex items-center justify-center h-full">
  838. <Spinner />
  839. </div>
  840. {/if}
  841. </form>