Documents.svelte 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290
  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 AzureOpenAIUrl = '';
  39. let AzureOpenAIKey = '';
  40. let AzureOpenAIVersion = '';
  41. let OllamaUrl = '';
  42. let OllamaKey = '';
  43. let querySettings = {
  44. template: '',
  45. r: 0.0,
  46. k: 4,
  47. k_reranker: 4,
  48. hybrid: false
  49. };
  50. let RAGConfig = null;
  51. const embeddingModelUpdateHandler = async () => {
  52. if (embeddingEngine === '' && embeddingModel.split('/').length - 1 > 1) {
  53. toast.error(
  54. $i18n.t(
  55. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  56. )
  57. );
  58. return;
  59. }
  60. if (embeddingEngine === 'ollama' && embeddingModel === '') {
  61. toast.error(
  62. $i18n.t(
  63. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  64. )
  65. );
  66. return;
  67. }
  68. if (embeddingEngine === 'openai' && embeddingModel === '') {
  69. toast.error(
  70. $i18n.t(
  71. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  72. )
  73. );
  74. return;
  75. }
  76. if (embeddingEngine === 'openai' && (OpenAIKey === '' || OpenAIUrl === '')) {
  77. toast.error($i18n.t('OpenAI URL/Key required.'));
  78. return;
  79. }
  80. if (
  81. embeddingEngine === 'azure_openai' &&
  82. (AzureOpenAIKey === '' || AzureOpenAIUrl === '' || AzureOpenAIVersion === '')
  83. ) {
  84. toast.error($i18n.t('OpenAI URL/Key required.'));
  85. return;
  86. }
  87. console.debug('Update embedding model attempt:', embeddingModel);
  88. updateEmbeddingModelLoading = true;
  89. const res = await updateEmbeddingConfig(localStorage.token, {
  90. embedding_engine: embeddingEngine,
  91. embedding_model: embeddingModel,
  92. embedding_batch_size: embeddingBatchSize,
  93. ollama_config: {
  94. key: OllamaKey,
  95. url: OllamaUrl
  96. },
  97. openai_config: {
  98. key: OpenAIKey,
  99. url: OpenAIUrl
  100. },
  101. azure_openai_config: {
  102. key: AzureOpenAIKey,
  103. url: AzureOpenAIUrl,
  104. version: AzureOpenAIVersion
  105. }
  106. }).catch(async (error) => {
  107. toast.error(`${error}`);
  108. await setEmbeddingConfig();
  109. return null;
  110. });
  111. updateEmbeddingModelLoading = false;
  112. if (res) {
  113. console.debug('embeddingModelUpdateHandler:', res);
  114. if (res.status === true) {
  115. toast.success($i18n.t('Embedding model set to "{{embedding_model}}"', res), {
  116. duration: 1000 * 10
  117. });
  118. }
  119. }
  120. };
  121. const submitHandler = async () => {
  122. if (
  123. RAGConfig.CONTENT_EXTRACTION_ENGINE === 'external' &&
  124. RAGConfig.EXTERNAL_DOCUMENT_LOADER_URL === ''
  125. ) {
  126. toast.error($i18n.t('External Document Loader URL required.'));
  127. return;
  128. }
  129. if (RAGConfig.CONTENT_EXTRACTION_ENGINE === 'tika' && RAGConfig.TIKA_SERVER_URL === '') {
  130. toast.error($i18n.t('Tika Server URL required.'));
  131. return;
  132. }
  133. if (RAGConfig.CONTENT_EXTRACTION_ENGINE === 'docling' && RAGConfig.DOCLING_SERVER_URL === '') {
  134. toast.error($i18n.t('Docling Server URL required.'));
  135. return;
  136. }
  137. if (
  138. RAGConfig.CONTENT_EXTRACTION_ENGINE === 'docling' &&
  139. ((RAGConfig.DOCLING_OCR_ENGINE === '' && RAGConfig.DOCLING_OCR_LANG !== '') ||
  140. (RAGConfig.DOCLING_OCR_ENGINE !== '' && RAGConfig.DOCLING_OCR_LANG === ''))
  141. ) {
  142. toast.error(
  143. $i18n.t('Both Docling OCR Engine and Language(s) must be provided or both left empty.')
  144. );
  145. return;
  146. }
  147. if (
  148. RAGConfig.CONTENT_EXTRACTION_ENGINE === 'datalab_marker' &&
  149. !RAGConfig.DATALAB_MARKER_API_KEY
  150. ) {
  151. toast.error($i18n.t('Datalab Marker API Key required.'));
  152. return;
  153. }
  154. if (
  155. RAGConfig.CONTENT_EXTRACTION_ENGINE === 'document_intelligence' &&
  156. (RAGConfig.DOCUMENT_INTELLIGENCE_ENDPOINT === '' ||
  157. RAGConfig.DOCUMENT_INTELLIGENCE_KEY === '')
  158. ) {
  159. toast.error($i18n.t('Document Intelligence endpoint and key required.'));
  160. return;
  161. }
  162. if (
  163. RAGConfig.CONTENT_EXTRACTION_ENGINE === 'mistral_ocr' &&
  164. RAGConfig.MISTRAL_OCR_API_KEY === ''
  165. ) {
  166. toast.error($i18n.t('Mistral OCR API Key required.'));
  167. return;
  168. }
  169. if (!RAGConfig.BYPASS_EMBEDDING_AND_RETRIEVAL) {
  170. await embeddingModelUpdateHandler();
  171. }
  172. RAGConfig.ALLOWED_FILE_EXTENSIONS = (RAGConfig?.ALLOWED_FILE_EXTENSIONS ?? '')
  173. .split(',')
  174. .map((ext) => ext.trim())
  175. .filter((ext) => ext !== '');
  176. RAGConfig.DATALAB_MARKER_LANGS = RAGConfig.DATALAB_MARKER_LANGS.split(',')
  177. .map((code) => code.trim())
  178. .filter((code) => code !== '')
  179. .join(', ');
  180. const res = await updateRAGConfig(localStorage.token, RAGConfig);
  181. dispatch('save');
  182. };
  183. const setEmbeddingConfig = async () => {
  184. const embeddingConfig = await getEmbeddingConfig(localStorage.token);
  185. if (embeddingConfig) {
  186. embeddingEngine = embeddingConfig.embedding_engine;
  187. embeddingModel = embeddingConfig.embedding_model;
  188. embeddingBatchSize = embeddingConfig.embedding_batch_size ?? 1;
  189. OpenAIKey = embeddingConfig.openai_config.key;
  190. OpenAIUrl = embeddingConfig.openai_config.url;
  191. OllamaKey = embeddingConfig.ollama_config.key;
  192. OllamaUrl = embeddingConfig.ollama_config.url;
  193. AzureOpenAIKey = embeddingConfig.azure_openai_config.key;
  194. AzureOpenAIUrl = embeddingConfig.azure_openai_config.url;
  195. AzureOpenAIVersion = embeddingConfig.azure_openai_config.version;
  196. }
  197. };
  198. onMount(async () => {
  199. await setEmbeddingConfig();
  200. const config = await getRAGConfig(localStorage.token);
  201. config.ALLOWED_FILE_EXTENSIONS = (config?.ALLOWED_FILE_EXTENSIONS ?? []).join(', ');
  202. RAGConfig = config;
  203. });
  204. </script>
  205. <ResetUploadDirConfirmDialog
  206. bind:show={showResetUploadDirConfirm}
  207. on:confirm={async () => {
  208. const res = await deleteAllFiles(localStorage.token).catch((error) => {
  209. toast.error(`${error}`);
  210. return null;
  211. });
  212. if (res) {
  213. toast.success($i18n.t('Success'));
  214. }
  215. }}
  216. />
  217. <ResetVectorDBConfirmDialog
  218. bind:show={showResetConfirm}
  219. on:confirm={() => {
  220. const res = resetVectorDB(localStorage.token).catch((error) => {
  221. toast.error(`${error}`);
  222. return null;
  223. });
  224. if (res) {
  225. toast.success($i18n.t('Success'));
  226. }
  227. }}
  228. />
  229. <ReindexKnowledgeFilesConfirmDialog
  230. bind:show={showReindexConfirm}
  231. on:confirm={async () => {
  232. const res = await reindexKnowledgeFiles(localStorage.token).catch((error) => {
  233. toast.error(`${error}`);
  234. return null;
  235. });
  236. if (res) {
  237. toast.success($i18n.t('Success'));
  238. }
  239. }}
  240. />
  241. <form
  242. class="flex flex-col h-full justify-between space-y-3 text-sm"
  243. on:submit|preventDefault={() => {
  244. submitHandler();
  245. }}
  246. >
  247. {#if RAGConfig}
  248. <div class=" space-y-2.5 overflow-y-scroll scrollbar-hidden h-full pr-1.5">
  249. <div class="">
  250. <div class="mb-3">
  251. <div class=" mb-2.5 text-base font-medium">{$i18n.t('General')}</div>
  252. <hr class=" border-gray-100 dark:border-gray-850 my-2" />
  253. <div class="mb-2.5 flex flex-col w-full justify-between">
  254. <div class="flex w-full justify-between mb-1">
  255. <div class="self-center text-xs font-medium">
  256. {$i18n.t('Content Extraction Engine')}
  257. </div>
  258. <div class="">
  259. <select
  260. class="dark:bg-gray-900 w-fit pr-8 rounded-sm px-2 text-xs bg-transparent outline-hidden text-right"
  261. bind:value={RAGConfig.CONTENT_EXTRACTION_ENGINE}
  262. >
  263. <option value="">{$i18n.t('Default')}</option>
  264. <option value="external">{$i18n.t('External')}</option>
  265. <option value="tika">{$i18n.t('Tika')}</option>
  266. <option value="docling">{$i18n.t('Docling')}</option>
  267. <option value="datalab_marker">{$i18n.t('Datalab Marker API')}</option>
  268. <option value="document_intelligence">{$i18n.t('Document Intelligence')}</option>
  269. <option value="mistral_ocr">{$i18n.t('Mistral OCR')}</option>
  270. </select>
  271. </div>
  272. </div>
  273. {#if RAGConfig.CONTENT_EXTRACTION_ENGINE === ''}
  274. <div class="flex w-full mt-1">
  275. <div class="flex-1 flex justify-between">
  276. <div class=" self-center text-xs font-medium">
  277. {$i18n.t('PDF Extract Images (OCR)')}
  278. </div>
  279. <div class="flex items-center relative">
  280. <Switch bind:state={RAGConfig.PDF_EXTRACT_IMAGES} />
  281. </div>
  282. </div>
  283. </div>
  284. {:else if RAGConfig.CONTENT_EXTRACTION_ENGINE === 'datalab_marker'}
  285. <div class="my-0.5 flex gap-2 pr-2">
  286. <SensitiveInput
  287. placeholder={$i18n.t('Enter Datalab Marker API Key')}
  288. required={false}
  289. bind:value={RAGConfig.DATALAB_MARKER_API_KEY}
  290. />
  291. </div>
  292. <div class="flex justify-between w-full mt-2">
  293. <div class="text-xs font-medium">
  294. {$i18n.t('Languages')}
  295. </div>
  296. <input
  297. class="text-sm bg-transparent outline-hidden"
  298. type="text"
  299. bind:value={RAGConfig.DATALAB_MARKER_LANGS}
  300. placeholder={$i18n.t('e.g.) en,fr,de')}
  301. />
  302. </div>
  303. <div class="flex justify-between w-full mt-2">
  304. <div class="self-center text-xs font-medium">
  305. <Tooltip
  306. content={$i18n.t(
  307. 'Significantly improves accuracy by using an LLM to enhance tables, forms, inline math, and layout detection. Will increase latency. Defaults to True.'
  308. )}
  309. placement="top-start"
  310. >
  311. {$i18n.t('Use LLM')}
  312. </Tooltip>
  313. </div>
  314. <div class="flex items-center">
  315. <Switch bind:state={RAGConfig.DATALAB_MARKER_USE_LLM} />
  316. </div>
  317. </div>
  318. <div class="flex justify-between w-full mt-2">
  319. <div class="self-center text-xs font-medium">
  320. <Tooltip
  321. content={$i18n.t('Skip the cache and re-run the inference. Defaults to False.')}
  322. placement="top-start"
  323. >
  324. {$i18n.t('Skip Cache')}
  325. </Tooltip>
  326. </div>
  327. <div class="flex items-center">
  328. <Switch bind:state={RAGConfig.DATALAB_MARKER_SKIP_CACHE} />
  329. </div>
  330. </div>
  331. <div class="flex justify-between w-full mt-2">
  332. <div class="self-center text-xs font-medium">
  333. <Tooltip
  334. content={$i18n.t(
  335. 'Force OCR on all pages of the PDF. This can lead to worse results if you have good text in your PDFs. Defaults to False.'
  336. )}
  337. placement="top-start"
  338. >
  339. {$i18n.t('Force OCR')}
  340. </Tooltip>
  341. </div>
  342. <div class="flex items-center">
  343. <Switch bind:state={RAGConfig.DATALAB_MARKER_FORCE_OCR} />
  344. </div>
  345. </div>
  346. <div class="flex justify-between w-full mt-2">
  347. <div class="self-center text-xs font-medium">
  348. <Tooltip
  349. content={$i18n.t(
  350. 'Whether to paginate the output. Each page will be separated by a horizontal rule and page number. Defaults to False.'
  351. )}
  352. placement="top-start"
  353. >
  354. {$i18n.t('Paginate')}
  355. </Tooltip>
  356. </div>
  357. <div class="flex items-center">
  358. <Switch bind:state={RAGConfig.DATALAB_MARKER_PAGINATE} />
  359. </div>
  360. </div>
  361. <div class="flex justify-between w-full mt-2">
  362. <div class="self-center text-xs font-medium">
  363. <Tooltip
  364. content={$i18n.t(
  365. 'Strip existing OCR text from the PDF and re-run OCR. Ignored if Force OCR is enabled. Defaults to False.'
  366. )}
  367. placement="top-start"
  368. >
  369. {$i18n.t('Strip Existing OCR')}
  370. </Tooltip>
  371. </div>
  372. <div class="flex items-center">
  373. <Switch bind:state={RAGConfig.DATALAB_MARKER_STRIP_EXISTING_OCR} />
  374. </div>
  375. </div>
  376. <div class="flex justify-between w-full mt-2">
  377. <div class="self-center text-xs font-medium">
  378. <Tooltip
  379. content={$i18n.t(
  380. 'Disable image extraction from the PDF. If Use LLM is enabled, images will be automatically captioned. Defaults to False.'
  381. )}
  382. placement="top-start"
  383. >
  384. {$i18n.t('Disable Image Extraction')}
  385. </Tooltip>
  386. </div>
  387. <div class="flex items-center">
  388. <Switch bind:state={RAGConfig.DATALAB_MARKER_DISABLE_IMAGE_EXTRACTION} />
  389. </div>
  390. </div>
  391. <div class="flex justify-between w-full mt-2">
  392. <div class="self-center text-xs font-medium">
  393. <Tooltip
  394. content={$i18n.t(
  395. "The output format for the text. Can be 'json', 'markdown', or 'html'. Defaults to 'markdown'."
  396. )}
  397. placement="top-start"
  398. >
  399. {$i18n.t('Output Format')}
  400. </Tooltip>
  401. </div>
  402. <div class="">
  403. <select
  404. class="dark:bg-gray-900 w-fit pr-8 rounded-sm px-2 text-xs bg-transparent outline-hidden text-right"
  405. bind:value={RAGConfig.DATALAB_MARKER_OUTPUT_FORMAT}
  406. >
  407. <option value="markdown">{$i18n.t('Markdown')}</option>
  408. <option value="json">{$i18n.t('JSON')}</option>
  409. <option value="html">{$i18n.t('HTML')}</option>
  410. </select>
  411. </div>
  412. </div>
  413. {:else if RAGConfig.CONTENT_EXTRACTION_ENGINE === 'external'}
  414. <div class="my-0.5 flex gap-2 pr-2">
  415. <input
  416. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  417. placeholder={$i18n.t('Enter External Document Loader URL')}
  418. bind:value={RAGConfig.EXTERNAL_DOCUMENT_LOADER_URL}
  419. />
  420. <SensitiveInput
  421. placeholder={$i18n.t('Enter External Document Loader API Key')}
  422. required={false}
  423. bind:value={RAGConfig.EXTERNAL_DOCUMENT_LOADER_API_KEY}
  424. />
  425. </div>
  426. {:else if RAGConfig.CONTENT_EXTRACTION_ENGINE === 'tika'}
  427. <div class="flex w-full mt-1">
  428. <div class="flex-1 mr-2">
  429. <input
  430. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  431. placeholder={$i18n.t('Enter Tika Server URL')}
  432. bind:value={RAGConfig.TIKA_SERVER_URL}
  433. />
  434. </div>
  435. </div>
  436. {:else if RAGConfig.CONTENT_EXTRACTION_ENGINE === 'docling'}
  437. <div class="flex w-full mt-1">
  438. <input
  439. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  440. placeholder={$i18n.t('Enter Docling Server URL')}
  441. bind:value={RAGConfig.DOCLING_SERVER_URL}
  442. />
  443. </div>
  444. <div class="flex w-full mt-2">
  445. <input
  446. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  447. placeholder={$i18n.t('Enter Docling OCR Engine')}
  448. bind:value={RAGConfig.DOCLING_OCR_ENGINE}
  449. />
  450. <input
  451. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  452. placeholder={$i18n.t('Enter Docling OCR Language(s)')}
  453. bind:value={RAGConfig.DOCLING_OCR_LANG}
  454. />
  455. </div>
  456. <div class="flex w-full mt-2">
  457. <div class="flex-1 flex justify-between">
  458. <div class=" self-center text-xs font-medium">
  459. {$i18n.t('Describe Pictures in Documents')}
  460. </div>
  461. <div class="flex items-center relative">
  462. <Switch bind:state={RAGConfig.DOCLING_DO_PICTURE_DESCRIPTION} />
  463. </div>
  464. </div>
  465. </div>
  466. {#if RAGConfig.DOCLING_DO_PICTURE_DESCRIPTION}
  467. <div class="flex w-full mt-2">
  468. <div class="flex-1 flex items-center gap-4">
  469. <label class="flex items-center gap-1 text-xs font-medium">
  470. <Tooltip
  471. content={$i18n.t('Use a model locally executed by Docling for picture description.')}
  472. placement="top-start"
  473. >
  474. <input
  475. type="radio"
  476. name="picture-description-mode"
  477. value="local"
  478. bind:group={RAGConfig.DOCLING_PICTURE_DESCRIPTION_MODE}
  479. checked={RAGConfig.DOCLING_PICTURE_DESCRIPTION_MODE === 'local'}
  480. />
  481. <span style="padding-left: 0.5em">{$i18n.t('Local Description')}</span>
  482. </Tooltip>
  483. </label>
  484. <label class="flex items-center gap-1 text-xs font-medium">
  485. <Tooltip
  486. content={$i18n.t('Use a remote API for picture description.')}
  487. placement="top-start"
  488. >
  489. <input
  490. type="radio"
  491. name="picture-description-mode"
  492. value="api"
  493. bind:group={RAGConfig.DOCLING_PICTURE_DESCRIPTION_MODE}
  494. checked={RAGConfig.DOCLING_PICTURE_DESCRIPTION_MODE === 'api'}
  495. />
  496. <span style="padding-left: 0.5em">{$i18n.t('Remote Description')}</span>
  497. </Tooltip>
  498. </label>
  499. </div>
  500. </div>
  501. {#if RAGConfig.DOCLING_PICTURE_DESCRIPTION_MODE === 'local'}
  502. <div class="flex flex-col gap-2 mt-2 ml-4">
  503. <div class="flex items-center gap-2">
  504. <div class="min-w-fit text-xs font-medium">
  505. <Tooltip
  506. content={$i18n.t('The HuggingFace repo ID for the local vision-language model.')}
  507. placement="top-start"
  508. >
  509. {$i18n.t('Repo ID')}
  510. </Tooltip>
  511. </div>
  512. <input
  513. 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"
  514. placeholder={$i18n.t('HuggingFaceTB/SmolVLM-256M-Instruct')}
  515. bind:value={RAGConfig.DOCLING_PICTURE_DESCRIPTION_LOCAL_REPO_ID}
  516. />
  517. </div>
  518. <div class="flex items-center gap-2">
  519. <div class="min-w-fit text-xs font-medium">
  520. <Tooltip
  521. content={$i18n.t('Maximum number of tokens for the generated description.')}
  522. placement="top-start"
  523. >
  524. {$i18n.t('Max Tokens')}
  525. </Tooltip>
  526. </div>
  527. <input
  528. 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"
  529. placeholder={$i18n.t('200')}
  530. bind:value={RAGConfig.DOCLING_PICTURE_DESCRIPTION_LOCAL_MAX_TOKENS}
  531. />
  532. </div>
  533. <div class="flex items-center gap-2">
  534. <div class="min-w-fit text-xs font-medium">
  535. <Tooltip
  536. content={$i18n.t('Prompt to use for describing the image.')}
  537. placement="top-start"
  538. >
  539. {$i18n.t('Prompt')}
  540. </Tooltip>
  541. </div>
  542. <input
  543. 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"
  544. placeholder={$i18n.t('Describe this image in a few sentences.')}
  545. bind:value={RAGConfig.DOCLING_PICTURE_DESCRIPTION_LOCAL_PROMPT}
  546. />
  547. </div>
  548. </div>
  549. {:else if RAGConfig.DOCLING_PICTURE_DESCRIPTION_MODE === 'api'}
  550. <div class="flex flex-col gap-2 mt-2 ml-4">
  551. <div class="flex items-center gap-2">
  552. <div class="min-w-fit text-xs font-medium">
  553. <Tooltip
  554. content={$i18n.t('The remote API endpoint for picture description.')}
  555. placement="top-start"
  556. >
  557. {$i18n.t('URL')}
  558. </Tooltip>
  559. </div>
  560. <input
  561. 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"
  562. placeholder={$i18n.t('Enter Remote API URL')}
  563. bind:value={RAGConfig.DOCLING_PICTURE_DESCRIPTION_API_URL}
  564. />
  565. </div>
  566. <div class="flex items-center gap-2">
  567. <div class="min-w-fit text-xs font-medium">
  568. <Tooltip
  569. content={$i18n.t('The model name to use for remote picture description.')}
  570. placement="top-start"
  571. >
  572. {$i18n.t('Model')}
  573. </Tooltip>
  574. </div>
  575. <input
  576. 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"
  577. placeholder={$i18n.t('Enter Model Name')}
  578. bind:value={RAGConfig.DOCLING_PICTURE_DESCRIPTION_API_MODEL}
  579. />
  580. </div>
  581. <div class="flex items-center gap-2">
  582. <div class="min-w-fit text-xs font-medium">
  583. <Tooltip
  584. content={$i18n.t('Prompt to use for describing the image via remote API.')}
  585. placement="top-start"
  586. >
  587. {$i18n.t('Prompt')}
  588. </Tooltip>
  589. </div>
  590. <input
  591. 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"
  592. placeholder={$i18n.t('Describe this image in a few sentences.')}
  593. bind:value={RAGConfig.DOCLING_PICTURE_DESCRIPTION_API_PROMPT}
  594. />
  595. </div>
  596. </div>
  597. {/if}
  598. {/if}
  599. {:else if RAGConfig.CONTENT_EXTRACTION_ENGINE === 'document_intelligence'}
  600. <div class="my-0.5 flex gap-2 pr-2">
  601. <input
  602. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  603. placeholder={$i18n.t('Enter Document Intelligence Endpoint')}
  604. bind:value={RAGConfig.DOCUMENT_INTELLIGENCE_ENDPOINT}
  605. />
  606. <SensitiveInput
  607. placeholder={$i18n.t('Enter Document Intelligence Key')}
  608. bind:value={RAGConfig.DOCUMENT_INTELLIGENCE_KEY}
  609. />
  610. </div>
  611. {:else if RAGConfig.CONTENT_EXTRACTION_ENGINE === 'mistral_ocr'}
  612. <div class="my-0.5 flex gap-2 pr-2">
  613. <SensitiveInput
  614. placeholder={$i18n.t('Enter Mistral API Key')}
  615. bind:value={RAGConfig.MISTRAL_OCR_API_KEY}
  616. />
  617. </div>
  618. {/if}
  619. </div>
  620. <div class=" mb-2.5 flex w-full justify-between">
  621. <div class=" self-center text-xs font-medium">
  622. <Tooltip content={$i18n.t('Full Context Mode')} placement="top-start">
  623. {$i18n.t('Bypass Embedding and Retrieval')}
  624. </Tooltip>
  625. </div>
  626. <div class="flex items-center relative">
  627. <Tooltip
  628. content={RAGConfig.BYPASS_EMBEDDING_AND_RETRIEVAL
  629. ? $i18n.t(
  630. 'Inject the entire content as context for comprehensive processing, this is recommended for complex queries.'
  631. )
  632. : $i18n.t(
  633. 'Default to segmented retrieval for focused and relevant content extraction, this is recommended for most cases.'
  634. )}
  635. >
  636. <Switch bind:state={RAGConfig.BYPASS_EMBEDDING_AND_RETRIEVAL} />
  637. </Tooltip>
  638. </div>
  639. </div>
  640. {#if !RAGConfig.BYPASS_EMBEDDING_AND_RETRIEVAL}
  641. <div class=" mb-2.5 flex w-full justify-between">
  642. <div class=" self-center text-xs font-medium">{$i18n.t('Text Splitter')}</div>
  643. <div class="flex items-center relative">
  644. <select
  645. class="dark:bg-gray-900 w-fit pr-8 rounded-sm px-2 text-xs bg-transparent outline-hidden text-right"
  646. bind:value={RAGConfig.TEXT_SPLITTER}
  647. >
  648. <option value="">{$i18n.t('Default')} ({$i18n.t('Character')})</option>
  649. <option value="token">{$i18n.t('Token')} ({$i18n.t('Tiktoken')})</option>
  650. </select>
  651. </div>
  652. </div>
  653. <div class=" mb-2.5 flex w-full justify-between">
  654. <div class=" flex gap-1.5 w-full">
  655. <div class=" w-full justify-between">
  656. <div class="self-center text-xs font-medium min-w-fit mb-1">
  657. {$i18n.t('Chunk Size')}
  658. </div>
  659. <div class="self-center">
  660. <input
  661. 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"
  662. type="number"
  663. placeholder={$i18n.t('Enter Chunk Size')}
  664. bind:value={RAGConfig.CHUNK_SIZE}
  665. autocomplete="off"
  666. min="0"
  667. />
  668. </div>
  669. </div>
  670. <div class="w-full">
  671. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  672. {$i18n.t('Chunk Overlap')}
  673. </div>
  674. <div class="self-center">
  675. <input
  676. 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"
  677. type="number"
  678. placeholder={$i18n.t('Enter Chunk Overlap')}
  679. bind:value={RAGConfig.CHUNK_OVERLAP}
  680. autocomplete="off"
  681. min="0"
  682. />
  683. </div>
  684. </div>
  685. </div>
  686. </div>
  687. {/if}
  688. </div>
  689. {#if !RAGConfig.BYPASS_EMBEDDING_AND_RETRIEVAL}
  690. <div class="mb-3">
  691. <div class=" mb-2.5 text-base font-medium">{$i18n.t('Embedding')}</div>
  692. <hr class=" border-gray-100 dark:border-gray-850 my-2" />
  693. <div class=" mb-2.5 flex flex-col w-full justify-between">
  694. <div class="flex w-full justify-between">
  695. <div class=" self-center text-xs font-medium">
  696. {$i18n.t('Embedding Model Engine')}
  697. </div>
  698. <div class="flex items-center relative">
  699. <select
  700. class="dark:bg-gray-900 w-fit pr-8 rounded-sm px-2 p-1 text-xs bg-transparent outline-hidden text-right"
  701. bind:value={embeddingEngine}
  702. placeholder="Select an embedding model engine"
  703. on:change={(e) => {
  704. if (e.target.value === 'ollama') {
  705. embeddingModel = '';
  706. } else if (e.target.value === 'openai') {
  707. embeddingModel = 'text-embedding-3-small';
  708. } else if (e.target.value === 'azure_openai') {
  709. embeddingModel = 'text-embedding-3-small';
  710. } else if (e.target.value === '') {
  711. embeddingModel = 'sentence-transformers/all-MiniLM-L6-v2';
  712. }
  713. }}
  714. >
  715. <option value="">{$i18n.t('Default (SentenceTransformers)')}</option>
  716. <option value="ollama">{$i18n.t('Ollama')}</option>
  717. <option value="openai">{$i18n.t('OpenAI')}</option>
  718. <option value="azure_openai">Azure OpenAI</option>
  719. </select>
  720. </div>
  721. </div>
  722. {#if embeddingEngine === 'openai'}
  723. <div class="my-0.5 flex gap-2 pr-2">
  724. <input
  725. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  726. placeholder={$i18n.t('API Base URL')}
  727. bind:value={OpenAIUrl}
  728. required
  729. />
  730. <SensitiveInput placeholder={$i18n.t('API Key')} bind:value={OpenAIKey} />
  731. </div>
  732. {:else if embeddingEngine === 'ollama'}
  733. <div class="my-0.5 flex gap-2 pr-2">
  734. <input
  735. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  736. placeholder={$i18n.t('API Base URL')}
  737. bind:value={OllamaUrl}
  738. required
  739. />
  740. <SensitiveInput
  741. placeholder={$i18n.t('API Key')}
  742. bind:value={OllamaKey}
  743. required={false}
  744. />
  745. </div>
  746. {:else if embeddingEngine === 'azure_openai'}
  747. <div class="my-0.5 flex flex-col gap-2 pr-2 w-full">
  748. <div class="flex gap-2">
  749. <input
  750. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  751. placeholder={$i18n.t('API Base URL')}
  752. bind:value={AzureOpenAIUrl}
  753. required
  754. />
  755. <SensitiveInput placeholder={$i18n.t('API Key')} bind:value={AzureOpenAIKey} />
  756. </div>
  757. <div class="flex gap-2">
  758. <input
  759. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  760. placeholder="Version"
  761. bind:value={AzureOpenAIVersion}
  762. required
  763. />
  764. </div>
  765. </div>
  766. {/if}
  767. </div>
  768. <div class=" mb-2.5 flex flex-col w-full">
  769. <div class=" mb-1 text-xs font-medium">{$i18n.t('Embedding Model')}</div>
  770. <div class="">
  771. {#if embeddingEngine === 'ollama'}
  772. <div class="flex w-full">
  773. <div class="flex-1 mr-2">
  774. <input
  775. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  776. bind:value={embeddingModel}
  777. placeholder={$i18n.t('Set embedding model')}
  778. required
  779. />
  780. </div>
  781. </div>
  782. {:else}
  783. <div class="flex w-full">
  784. <div class="flex-1 mr-2">
  785. <input
  786. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  787. placeholder={$i18n.t('Set embedding model (e.g. {{model}})', {
  788. model: embeddingModel.slice(-40)
  789. })}
  790. bind:value={embeddingModel}
  791. />
  792. </div>
  793. {#if embeddingEngine === ''}
  794. <button
  795. class="px-2.5 bg-transparent text-gray-800 dark:bg-transparent dark:text-gray-100 rounded-lg transition"
  796. on:click={() => {
  797. embeddingModelUpdateHandler();
  798. }}
  799. disabled={updateEmbeddingModelLoading}
  800. >
  801. {#if updateEmbeddingModelLoading}
  802. <div class="self-center">
  803. <svg
  804. class=" w-4 h-4"
  805. viewBox="0 0 24 24"
  806. fill="currentColor"
  807. xmlns="http://www.w3.org/2000/svg"
  808. >
  809. <style>
  810. .spinner_ajPY {
  811. transform-origin: center;
  812. animation: spinner_AtaB 0.75s infinite linear;
  813. }
  814. @keyframes spinner_AtaB {
  815. 100% {
  816. transform: rotate(360deg);
  817. }
  818. }
  819. </style>
  820. <path
  821. 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"
  822. opacity=".25"
  823. />
  824. <path
  825. 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"
  826. class="spinner_ajPY"
  827. />
  828. </svg>
  829. </div>
  830. {:else}
  831. <svg
  832. xmlns="http://www.w3.org/2000/svg"
  833. viewBox="0 0 16 16"
  834. fill="currentColor"
  835. class="w-4 h-4"
  836. >
  837. <path
  838. 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"
  839. />
  840. <path
  841. 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"
  842. />
  843. </svg>
  844. {/if}
  845. </button>
  846. {/if}
  847. </div>
  848. {/if}
  849. </div>
  850. <div class="mt-1 mb-1 text-xs text-gray-400 dark:text-gray-500">
  851. {$i18n.t(
  852. 'Warning: If you update or change your embedding model, you will need to re-import all documents.'
  853. )}
  854. </div>
  855. </div>
  856. {#if embeddingEngine === 'ollama' || embeddingEngine === 'openai' || embeddingEngine === 'azure_openai'}
  857. <div class=" mb-2.5 flex w-full justify-between">
  858. <div class=" self-center text-xs font-medium">
  859. {$i18n.t('Embedding Batch Size')}
  860. </div>
  861. <div class="">
  862. <input
  863. bind:value={embeddingBatchSize}
  864. type="number"
  865. class=" bg-transparent text-center w-14 outline-none"
  866. min="-2"
  867. max="16000"
  868. step="1"
  869. />
  870. </div>
  871. </div>
  872. {/if}
  873. </div>
  874. <div class="mb-3">
  875. <div class=" mb-2.5 text-base font-medium">{$i18n.t('Retrieval')}</div>
  876. <hr class=" border-gray-100 dark:border-gray-850 my-2" />
  877. <div class=" mb-2.5 flex w-full justify-between">
  878. <div class=" self-center text-xs font-medium">{$i18n.t('Full Context Mode')}</div>
  879. <div class="flex items-center relative">
  880. <Tooltip
  881. content={RAGConfig.RAG_FULL_CONTEXT
  882. ? $i18n.t(
  883. 'Inject the entire content as context for comprehensive processing, this is recommended for complex queries.'
  884. )
  885. : $i18n.t(
  886. 'Default to segmented retrieval for focused and relevant content extraction, this is recommended for most cases.'
  887. )}
  888. >
  889. <Switch bind:state={RAGConfig.RAG_FULL_CONTEXT} />
  890. </Tooltip>
  891. </div>
  892. </div>
  893. {#if !RAGConfig.RAG_FULL_CONTEXT}
  894. <div class=" mb-2.5 flex w-full justify-between">
  895. <div class=" self-center text-xs font-medium">{$i18n.t('Hybrid Search')}</div>
  896. <div class="flex items-center relative">
  897. <Switch
  898. bind:state={RAGConfig.ENABLE_RAG_HYBRID_SEARCH}
  899. />
  900. </div>
  901. </div>
  902. {#if RAGConfig.ENABLE_RAG_HYBRID_SEARCH === true}
  903. <div class=" mb-2.5 flex flex-col w-full justify-between">
  904. <div class="flex w-full justify-between">
  905. <div class=" self-center text-xs font-medium">
  906. {$i18n.t('Reranking Engine')}
  907. </div>
  908. <div class="flex items-center relative">
  909. <select
  910. class="dark:bg-gray-900 w-fit pr-8 rounded-sm px-2 p-1 text-xs bg-transparent outline-hidden text-right"
  911. bind:value={RAGConfig.RAG_RERANKING_ENGINE}
  912. placeholder="Select a reranking model engine"
  913. on:change={(e) => {
  914. if (e.target.value === 'external') {
  915. RAGConfig.RAG_RERANKING_MODEL = '';
  916. } else if (e.target.value === '') {
  917. RAGConfig.RAG_RERANKING_MODEL = 'BAAI/bge-reranker-v2-m3';
  918. }
  919. }}
  920. >
  921. <option value="">{$i18n.t('Default (SentenceTransformers)')}</option>
  922. <option value="external">{$i18n.t('External')}</option>
  923. </select>
  924. </div>
  925. </div>
  926. {#if RAGConfig.RAG_RERANKING_ENGINE === 'external'}
  927. <div class="my-0.5 flex gap-2 pr-2">
  928. <input
  929. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  930. placeholder={$i18n.t('API Base URL')}
  931. bind:value={RAGConfig.RAG_EXTERNAL_RERANKER_URL}
  932. required
  933. />
  934. <SensitiveInput
  935. placeholder={$i18n.t('API Key')}
  936. bind:value={RAGConfig.RAG_EXTERNAL_RERANKER_API_KEY}
  937. required={false}
  938. />
  939. </div>
  940. {/if}
  941. </div>
  942. <div class=" mb-2.5 flex flex-col w-full">
  943. <div class=" mb-1 text-xs font-medium">{$i18n.t('Reranking Model')}</div>
  944. <div class="">
  945. <div class="flex w-full">
  946. <div class="flex-1 mr-2">
  947. <input
  948. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  949. placeholder={$i18n.t('Set reranking model (e.g. {{model}})', {
  950. model: 'BAAI/bge-reranker-v2-m3'
  951. })}
  952. bind:value={RAGConfig.RAG_RERANKING_MODEL}
  953. />
  954. </div>
  955. </div>
  956. </div>
  957. </div>
  958. {/if}
  959. <div class=" mb-2.5 flex w-full justify-between">
  960. <div class=" self-center text-xs font-medium">{$i18n.t('Top K')}</div>
  961. <div class="flex items-center relative">
  962. <input
  963. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  964. type="number"
  965. placeholder={$i18n.t('Enter Top K')}
  966. bind:value={RAGConfig.TOP_K}
  967. autocomplete="off"
  968. min="0"
  969. />
  970. </div>
  971. </div>
  972. {#if RAGConfig.ENABLE_RAG_HYBRID_SEARCH === true}
  973. <div class="mb-2.5 flex w-full justify-between">
  974. <div class="self-center text-xs font-medium">{$i18n.t('Top K Reranker')}</div>
  975. <div class="flex items-center relative">
  976. <input
  977. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  978. type="number"
  979. placeholder={$i18n.t('Enter Top K Reranker')}
  980. bind:value={RAGConfig.TOP_K_RERANKER}
  981. autocomplete="off"
  982. min="0"
  983. />
  984. </div>
  985. </div>
  986. {/if}
  987. {#if RAGConfig.ENABLE_RAG_HYBRID_SEARCH === true}
  988. <div class=" mb-2.5 flex flex-col w-full justify-between">
  989. <div class=" flex w-full justify-between">
  990. <div class=" self-center text-xs font-medium">
  991. {$i18n.t('Relevance Threshold')}
  992. </div>
  993. <div class="flex items-center relative">
  994. <input
  995. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  996. type="number"
  997. step="0.01"
  998. placeholder={$i18n.t('Enter Score')}
  999. bind:value={RAGConfig.RELEVANCE_THRESHOLD}
  1000. autocomplete="off"
  1001. min="0.0"
  1002. title={$i18n.t(
  1003. 'The score should be a value between 0.0 (0%) and 1.0 (100%).'
  1004. )}
  1005. />
  1006. </div>
  1007. </div>
  1008. <div class="mt-1 text-xs text-gray-400 dark:text-gray-500">
  1009. {$i18n.t(
  1010. 'Note: If you set a minimum score, the search will only return documents with a score greater than or equal to the minimum score.'
  1011. )}
  1012. </div>
  1013. </div>
  1014. {/if}
  1015. {#if RAGConfig.ENABLE_RAG_HYBRID_SEARCH === true}
  1016. <div class="mb-2.5 flex w-full justify-between">
  1017. <div class="self-center text-xs font-medium">
  1018. {$i18n.t('Weight of BM25 Retrieval')}
  1019. </div>
  1020. <div class="flex items-center relative">
  1021. <input
  1022. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  1023. type="number"
  1024. step="0.01"
  1025. placeholder={$i18n.t('Enter BM25 Weight')}
  1026. bind:value={RAGConfig.HYBRID_BM25_WEIGHT}
  1027. autocomplete="off"
  1028. min="0.0"
  1029. max="1.0"
  1030. />
  1031. </div>
  1032. </div>
  1033. {/if}
  1034. {/if}
  1035. <div class=" mb-2.5 flex flex-col w-full justify-between">
  1036. <div class=" mb-1 text-xs font-medium">{$i18n.t('RAG Template')}</div>
  1037. <div class="flex w-full items-center relative">
  1038. <Tooltip
  1039. content={$i18n.t(
  1040. 'Leave empty to use the default prompt, or enter a custom prompt'
  1041. )}
  1042. placement="top-start"
  1043. className="w-full"
  1044. >
  1045. <Textarea
  1046. bind:value={RAGConfig.RAG_TEMPLATE}
  1047. placeholder={$i18n.t(
  1048. 'Leave empty to use the default prompt, or enter a custom prompt'
  1049. )}
  1050. />
  1051. </Tooltip>
  1052. </div>
  1053. </div>
  1054. </div>
  1055. {/if}
  1056. <div class="mb-3">
  1057. <div class=" mb-2.5 text-base font-medium">{$i18n.t('Files')}</div>
  1058. <hr class=" border-gray-100 dark:border-gray-850 my-2" />
  1059. <div class=" mb-2.5 flex w-full justify-between">
  1060. <div class=" self-center text-xs font-medium">{$i18n.t('Allowed File Extensions')}</div>
  1061. <div class="flex items-center relative">
  1062. <Tooltip
  1063. content={$i18n.t(
  1064. 'Allowed file extensions for upload. Separate multiple extensions with commas. Leave empty for all file types.'
  1065. )}
  1066. placement="top-start"
  1067. >
  1068. <input
  1069. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  1070. type="text"
  1071. placeholder={$i18n.t('e.g. pdf, docx, txt')}
  1072. bind:value={RAGConfig.ALLOWED_FILE_EXTENSIONS}
  1073. autocomplete="off"
  1074. />
  1075. </Tooltip>
  1076. </div>
  1077. </div>
  1078. <div class=" mb-2.5 flex w-full justify-between">
  1079. <div class=" self-center text-xs font-medium">{$i18n.t('Max Upload Size')}</div>
  1080. <div class="flex items-center relative">
  1081. <Tooltip
  1082. content={$i18n.t(
  1083. 'The maximum file size in MB. If the file size exceeds this limit, the file will not be uploaded.'
  1084. )}
  1085. placement="top-start"
  1086. >
  1087. <input
  1088. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  1089. type="number"
  1090. placeholder={$i18n.t('Leave empty for unlimited')}
  1091. bind:value={RAGConfig.FILE_MAX_SIZE}
  1092. autocomplete="off"
  1093. min="0"
  1094. />
  1095. </Tooltip>
  1096. </div>
  1097. </div>
  1098. <div class=" mb-2.5 flex w-full justify-between">
  1099. <div class=" self-center text-xs font-medium">{$i18n.t('Max Upload Count')}</div>
  1100. <div class="flex items-center relative">
  1101. <Tooltip
  1102. content={$i18n.t(
  1103. '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.'
  1104. )}
  1105. placement="top-start"
  1106. >
  1107. <input
  1108. class="flex-1 w-full text-sm bg-transparent outline-hidden"
  1109. type="number"
  1110. placeholder={$i18n.t('Leave empty for unlimited')}
  1111. bind:value={RAGConfig.FILE_MAX_COUNT}
  1112. autocomplete="off"
  1113. min="0"
  1114. />
  1115. </Tooltip>
  1116. </div>
  1117. </div>
  1118. </div>
  1119. <div class="mb-3">
  1120. <div class=" mb-2.5 text-base font-medium">{$i18n.t('Integration')}</div>
  1121. <hr class=" border-gray-100 dark:border-gray-850 my-2" />
  1122. <div class=" mb-2.5 flex w-full justify-between">
  1123. <div class=" self-center text-xs font-medium">{$i18n.t('Google Drive')}</div>
  1124. <div class="flex items-center relative">
  1125. <Switch bind:state={RAGConfig.ENABLE_GOOGLE_DRIVE_INTEGRATION} />
  1126. </div>
  1127. </div>
  1128. <div class=" mb-2.5 flex w-full justify-between">
  1129. <div class=" self-center text-xs font-medium">{$i18n.t('OneDrive')}</div>
  1130. <div class="flex items-center relative">
  1131. <Switch bind:state={RAGConfig.ENABLE_ONEDRIVE_INTEGRATION} />
  1132. </div>
  1133. </div>
  1134. </div>
  1135. <div class="mb-3">
  1136. <div class=" mb-2.5 text-base font-medium">{$i18n.t('Danger Zone')}</div>
  1137. <hr class=" border-gray-100 dark:border-gray-850 my-2" />
  1138. <div class=" mb-2.5 flex w-full justify-between">
  1139. <div class=" self-center text-xs font-medium">{$i18n.t('Reset Upload Directory')}</div>
  1140. <div class="flex items-center relative">
  1141. <button
  1142. class="text-xs"
  1143. on:click={() => {
  1144. showResetUploadDirConfirm = true;
  1145. }}
  1146. >
  1147. {$i18n.t('Reset')}
  1148. </button>
  1149. </div>
  1150. </div>
  1151. <div class=" mb-2.5 flex w-full justify-between">
  1152. <div class=" self-center text-xs font-medium">
  1153. {$i18n.t('Reset Vector Storage/Knowledge')}
  1154. </div>
  1155. <div class="flex items-center relative">
  1156. <button
  1157. class="text-xs"
  1158. on:click={() => {
  1159. showResetConfirm = true;
  1160. }}
  1161. >
  1162. {$i18n.t('Reset')}
  1163. </button>
  1164. </div>
  1165. </div>
  1166. <div class=" mb-2.5 flex w-full justify-between">
  1167. <div class=" self-center text-xs font-medium">
  1168. {$i18n.t('Reindex Knowledge Base Vectors')}
  1169. </div>
  1170. <div class="flex items-center relative">
  1171. <button
  1172. class="text-xs"
  1173. on:click={() => {
  1174. showReindexConfirm = true;
  1175. }}
  1176. >
  1177. {$i18n.t('Reindex')}
  1178. </button>
  1179. </div>
  1180. </div>
  1181. </div>
  1182. </div>
  1183. </div>
  1184. <div class="flex justify-end pt-3 text-sm font-medium">
  1185. <button
  1186. 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"
  1187. type="submit"
  1188. >
  1189. {$i18n.t('Save')}
  1190. </button>
  1191. </div>
  1192. {:else}
  1193. <div class="flex items-center justify-center h-full">
  1194. <Spinner />
  1195. </div>
  1196. {/if}
  1197. </form>