Documents.svelte 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. <script lang="ts">
  2. import { getDocs } from '$lib/apis/documents';
  3. import {
  4. getQuerySettings,
  5. scanDocs,
  6. updateQuerySettings,
  7. resetVectorDB,
  8. getEmbeddingConfig,
  9. updateEmbeddingConfig,
  10. getRerankingConfig,
  11. updateRerankingConfig,
  12. resetUploadDir,
  13. getRAGConfig,
  14. updateRAGConfig
  15. } from '$lib/apis/rag';
  16. import ResetUploadDirConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
  17. import ResetVectorDBConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
  18. import { documents, models } from '$lib/stores';
  19. import { onMount, getContext } from 'svelte';
  20. import { toast } from 'svelte-sonner';
  21. const i18n = getContext('i18n');
  22. export let saveHandler: Function;
  23. let scanDirLoading = false;
  24. let updateEmbeddingModelLoading = false;
  25. let updateRerankingModelLoading = false;
  26. let showResetConfirm = false;
  27. let showResetUploadDirConfirm = false;
  28. let embeddingEngine = '';
  29. let embeddingModel = '';
  30. let rerankingModel = '';
  31. let chunkSize = 0;
  32. let chunkOverlap = 0;
  33. let pdfExtractImages = true;
  34. let OpenAIKey = '';
  35. let OpenAIUrl = '';
  36. let OpenAIBatchSize = 1;
  37. let querySettings = {
  38. template: '',
  39. r: 0.0,
  40. k: 4,
  41. hybrid: false
  42. };
  43. const scanHandler = async () => {
  44. scanDirLoading = true;
  45. const res = await scanDocs(localStorage.token);
  46. scanDirLoading = false;
  47. if (res) {
  48. await documents.set(await getDocs(localStorage.token));
  49. toast.success($i18n.t('Scan complete!'));
  50. }
  51. };
  52. const embeddingModelUpdateHandler = async () => {
  53. if (embeddingEngine === '' && embeddingModel.split('/').length - 1 > 1) {
  54. toast.error(
  55. $i18n.t(
  56. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  57. )
  58. );
  59. return;
  60. }
  61. if (embeddingEngine === 'ollama' && embeddingModel === '') {
  62. toast.error(
  63. $i18n.t(
  64. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  65. )
  66. );
  67. return;
  68. }
  69. if (embeddingEngine === 'openai' && embeddingModel === '') {
  70. toast.error(
  71. $i18n.t(
  72. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  73. )
  74. );
  75. return;
  76. }
  77. if ((embeddingEngine === 'openai' && OpenAIKey === '') || OpenAIUrl === '') {
  78. toast.error($i18n.t('OpenAI URL/Key required.'));
  79. return;
  80. }
  81. console.log('Update embedding model attempt:', embeddingModel);
  82. updateEmbeddingModelLoading = true;
  83. const res = await updateEmbeddingConfig(localStorage.token, {
  84. embedding_engine: embeddingEngine,
  85. embedding_model: embeddingModel,
  86. ...(embeddingEngine === 'openai'
  87. ? {
  88. openai_config: {
  89. key: OpenAIKey,
  90. url: OpenAIUrl,
  91. batch_size: OpenAIBatchSize
  92. }
  93. }
  94. : {})
  95. }).catch(async (error) => {
  96. toast.error(error);
  97. await setEmbeddingConfig();
  98. return null;
  99. });
  100. updateEmbeddingModelLoading = false;
  101. if (res) {
  102. console.log('embeddingModelUpdateHandler:', res);
  103. if (res.status === true) {
  104. toast.success($i18n.t('Embedding model set to "{{embedding_model}}"', res), {
  105. duration: 1000 * 10
  106. });
  107. }
  108. }
  109. };
  110. const rerankingModelUpdateHandler = async () => {
  111. console.log('Update reranking model attempt:', rerankingModel);
  112. updateRerankingModelLoading = true;
  113. const res = await updateRerankingConfig(localStorage.token, {
  114. reranking_model: rerankingModel
  115. }).catch(async (error) => {
  116. toast.error(error);
  117. await setRerankingConfig();
  118. return null;
  119. });
  120. updateRerankingModelLoading = false;
  121. if (res) {
  122. console.log('rerankingModelUpdateHandler:', res);
  123. if (res.status === true) {
  124. if (rerankingModel === '') {
  125. toast.success($i18n.t('Reranking model disabled', res), {
  126. duration: 1000 * 10
  127. });
  128. } else {
  129. toast.success($i18n.t('Reranking model set to "{{reranking_model}}"', res), {
  130. duration: 1000 * 10
  131. });
  132. }
  133. }
  134. }
  135. };
  136. const submitHandler = async () => {
  137. embeddingModelUpdateHandler();
  138. if (querySettings.hybrid) {
  139. rerankingModelUpdateHandler();
  140. }
  141. const res = await updateRAGConfig(localStorage.token, {
  142. pdf_extract_images: pdfExtractImages,
  143. chunk: {
  144. chunk_overlap: chunkOverlap,
  145. chunk_size: chunkSize
  146. }
  147. });
  148. await updateQuerySettings(localStorage.token, querySettings);
  149. };
  150. const setEmbeddingConfig = async () => {
  151. const embeddingConfig = await getEmbeddingConfig(localStorage.token);
  152. if (embeddingConfig) {
  153. embeddingEngine = embeddingConfig.embedding_engine;
  154. embeddingModel = embeddingConfig.embedding_model;
  155. OpenAIKey = embeddingConfig.openai_config.key;
  156. OpenAIUrl = embeddingConfig.openai_config.url;
  157. OpenAIBatchSize = embeddingConfig.openai_config.batch_size ?? 1;
  158. }
  159. };
  160. const setRerankingConfig = async () => {
  161. const rerankingConfig = await getRerankingConfig(localStorage.token);
  162. if (rerankingConfig) {
  163. rerankingModel = rerankingConfig.reranking_model;
  164. }
  165. };
  166. const toggleHybridSearch = async () => {
  167. querySettings.hybrid = !querySettings.hybrid;
  168. querySettings = await updateQuerySettings(localStorage.token, querySettings);
  169. };
  170. onMount(async () => {
  171. await setEmbeddingConfig();
  172. await setRerankingConfig();
  173. querySettings = await getQuerySettings(localStorage.token);
  174. const res = await getRAGConfig(localStorage.token);
  175. if (res) {
  176. pdfExtractImages = res.pdf_extract_images;
  177. chunkSize = res.chunk.chunk_size;
  178. chunkOverlap = res.chunk.chunk_overlap;
  179. }
  180. });
  181. </script>
  182. <ResetUploadDirConfirmDialog
  183. bind:show={showResetUploadDirConfirm}
  184. on:confirm={() => {
  185. const res = resetUploadDir(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. <ResetVectorDBConfirmDialog
  195. bind:show={showResetConfirm}
  196. on:confirm={() => {
  197. const res = resetVectorDB(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. saveHandler();
  211. }}
  212. >
  213. <div class=" space-y-2.5 overflow-y-scroll scrollbar-hidden h-full">
  214. <div class="flex flex-col gap-0.5">
  215. <div class=" mb-0.5 text-sm font-medium">{$i18n.t('General Settings')}</div>
  216. <div class=" flex w-full justify-between">
  217. <div class=" self-center text-xs font-medium">
  218. {$i18n.t('Scan for documents from {{path}}', { path: 'DOCS_DIR (/data/docs)' })}
  219. </div>
  220. <button
  221. class=" self-center text-xs p-1 px-3 bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 rounded-lg flex flex-row space-x-1 items-center {scanDirLoading
  222. ? ' cursor-not-allowed'
  223. : ''}"
  224. on:click={() => {
  225. scanHandler();
  226. console.log('check');
  227. }}
  228. type="button"
  229. disabled={scanDirLoading}
  230. >
  231. <div class="self-center font-medium">{$i18n.t('Scan')}</div>
  232. {#if scanDirLoading}
  233. <div class="ml-3 self-center">
  234. <svg
  235. class=" w-3 h-3"
  236. viewBox="0 0 24 24"
  237. fill="currentColor"
  238. xmlns="http://www.w3.org/2000/svg"
  239. ><style>
  240. .spinner_ajPY {
  241. transform-origin: center;
  242. animation: spinner_AtaB 0.75s infinite linear;
  243. }
  244. @keyframes spinner_AtaB {
  245. 100% {
  246. transform: rotate(360deg);
  247. }
  248. }
  249. </style><path
  250. 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"
  251. opacity=".25"
  252. /><path
  253. 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"
  254. class="spinner_ajPY"
  255. /></svg
  256. >
  257. </div>
  258. {/if}
  259. </button>
  260. </div>
  261. <div class=" flex w-full justify-between">
  262. <div class=" self-center text-xs font-medium">{$i18n.t('Embedding Model Engine')}</div>
  263. <div class="flex items-center relative">
  264. <select
  265. class="dark:bg-gray-900 w-fit pr-8 rounded px-2 p-1 text-xs bg-transparent outline-none text-right"
  266. bind:value={embeddingEngine}
  267. placeholder="Select an embedding model engine"
  268. on:change={(e) => {
  269. if (e.target.value === 'ollama') {
  270. embeddingModel = '';
  271. } else if (e.target.value === 'openai') {
  272. embeddingModel = 'text-embedding-3-small';
  273. } else if (e.target.value === '') {
  274. embeddingModel = 'sentence-transformers/all-MiniLM-L6-v2';
  275. }
  276. }}
  277. >
  278. <option value="">{$i18n.t('Default (SentenceTransformers)')}</option>
  279. <option value="ollama">{$i18n.t('Ollama')}</option>
  280. <option value="openai">{$i18n.t('OpenAI')}</option>
  281. </select>
  282. </div>
  283. </div>
  284. {#if embeddingEngine === 'openai'}
  285. <div class="my-0.5 flex gap-2">
  286. <input
  287. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  288. placeholder={$i18n.t('API Base URL')}
  289. bind:value={OpenAIUrl}
  290. required
  291. />
  292. <input
  293. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  294. placeholder={$i18n.t('API Key')}
  295. bind:value={OpenAIKey}
  296. required
  297. />
  298. </div>
  299. <div class="flex mt-0.5 space-x-2">
  300. <div class=" self-center text-xs font-medium">{$i18n.t('Embedding Batch Size')}</div>
  301. <div class=" flex-1">
  302. <input
  303. id="steps-range"
  304. type="range"
  305. min="1"
  306. max="2048"
  307. step="1"
  308. bind:value={OpenAIBatchSize}
  309. class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
  310. />
  311. </div>
  312. <div class="">
  313. <input
  314. bind:value={OpenAIBatchSize}
  315. type="number"
  316. class=" bg-transparent text-center w-14"
  317. min="-2"
  318. max="16000"
  319. step="1"
  320. />
  321. </div>
  322. </div>
  323. {/if}
  324. <div class=" flex w-full justify-between">
  325. <div class=" self-center text-xs font-medium">{$i18n.t('Hybrid Search')}</div>
  326. <button
  327. class="p-1 px-3 text-xs flex rounded transition"
  328. on:click={() => {
  329. toggleHybridSearch();
  330. }}
  331. type="button"
  332. >
  333. {#if querySettings.hybrid === true}
  334. <span class="ml-2 self-center">{$i18n.t('On')}</span>
  335. {:else}
  336. <span class="ml-2 self-center">{$i18n.t('Off')}</span>
  337. {/if}
  338. </button>
  339. </div>
  340. </div>
  341. <hr class=" dark:border-gray-850 my-1" />
  342. <div class="space-y-2" />
  343. <div>
  344. <div class=" mb-2 text-sm font-medium">{$i18n.t('Embedding Model')}</div>
  345. {#if embeddingEngine === 'ollama'}
  346. <div class="flex w-full">
  347. <div class="flex-1 mr-2">
  348. <select
  349. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  350. bind:value={embeddingModel}
  351. placeholder={$i18n.t('Select a model')}
  352. required
  353. >
  354. {#if !embeddingModel}
  355. <option value="" disabled selected>{$i18n.t('Select a model')}</option>
  356. {/if}
  357. {#each $models.filter((m) => m.id && m.ollama && !(m?.preset ?? false)) as model}
  358. <option value={model.id} class="bg-gray-100 dark:bg-gray-700">{model.name}</option>
  359. {/each}
  360. </select>
  361. </div>
  362. </div>
  363. {:else}
  364. <div class="flex w-full">
  365. <div class="flex-1 mr-2">
  366. <input
  367. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  368. placeholder={$i18n.t('Set embedding model (e.g. {{model}})', {
  369. model: embeddingModel.slice(-40)
  370. })}
  371. bind:value={embeddingModel}
  372. />
  373. </div>
  374. {#if embeddingEngine === ''}
  375. <button
  376. class="px-2.5 bg-gray-100 hover:bg-gray-200 text-gray-800 dark:bg-gray-850 dark:hover:bg-gray-800 dark:text-gray-100 rounded-lg transition"
  377. on:click={() => {
  378. embeddingModelUpdateHandler();
  379. }}
  380. disabled={updateEmbeddingModelLoading}
  381. >
  382. {#if updateEmbeddingModelLoading}
  383. <div class="self-center">
  384. <svg
  385. class=" w-4 h-4"
  386. viewBox="0 0 24 24"
  387. fill="currentColor"
  388. xmlns="http://www.w3.org/2000/svg"
  389. ><style>
  390. .spinner_ajPY {
  391. transform-origin: center;
  392. animation: spinner_AtaB 0.75s infinite linear;
  393. }
  394. @keyframes spinner_AtaB {
  395. 100% {
  396. transform: rotate(360deg);
  397. }
  398. }
  399. </style><path
  400. 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"
  401. opacity=".25"
  402. /><path
  403. 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"
  404. class="spinner_ajPY"
  405. /></svg
  406. >
  407. </div>
  408. {:else}
  409. <svg
  410. xmlns="http://www.w3.org/2000/svg"
  411. viewBox="0 0 16 16"
  412. fill="currentColor"
  413. class="w-4 h-4"
  414. >
  415. <path
  416. 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"
  417. />
  418. <path
  419. 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"
  420. />
  421. </svg>
  422. {/if}
  423. </button>
  424. {/if}
  425. </div>
  426. {/if}
  427. <div class="mt-2 mb-1 text-xs text-gray-400 dark:text-gray-500">
  428. {$i18n.t(
  429. 'Warning: If you update or change your embedding model, you will need to re-import all documents.'
  430. )}
  431. </div>
  432. {#if querySettings.hybrid === true}
  433. <div class=" ">
  434. <div class=" mb-2 text-sm font-medium">{$i18n.t('Reranking Model')}</div>
  435. <div class="flex w-full">
  436. <div class="flex-1 mr-2">
  437. <input
  438. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  439. placeholder={$i18n.t('Set reranking model (e.g. {{model}})', {
  440. model: 'BAAI/bge-reranker-v2-m3'
  441. })}
  442. bind:value={rerankingModel}
  443. />
  444. </div>
  445. <button
  446. class="px-2.5 bg-gray-100 hover:bg-gray-200 text-gray-800 dark:bg-gray-850 dark:hover:bg-gray-800 dark:text-gray-100 rounded-lg transition"
  447. on:click={() => {
  448. rerankingModelUpdateHandler();
  449. }}
  450. disabled={updateRerankingModelLoading}
  451. >
  452. {#if updateRerankingModelLoading}
  453. <div class="self-center">
  454. <svg
  455. class=" w-4 h-4"
  456. viewBox="0 0 24 24"
  457. fill="currentColor"
  458. xmlns="http://www.w3.org/2000/svg"
  459. ><style>
  460. .spinner_ajPY {
  461. transform-origin: center;
  462. animation: spinner_AtaB 0.75s infinite linear;
  463. }
  464. @keyframes spinner_AtaB {
  465. 100% {
  466. transform: rotate(360deg);
  467. }
  468. }
  469. </style><path
  470. 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"
  471. opacity=".25"
  472. /><path
  473. 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"
  474. class="spinner_ajPY"
  475. /></svg
  476. >
  477. </div>
  478. {:else}
  479. <svg
  480. xmlns="http://www.w3.org/2000/svg"
  481. viewBox="0 0 16 16"
  482. fill="currentColor"
  483. class="w-4 h-4"
  484. >
  485. <path
  486. 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"
  487. />
  488. <path
  489. 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"
  490. />
  491. </svg>
  492. {/if}
  493. </button>
  494. </div>
  495. </div>
  496. {/if}
  497. </div>
  498. <hr class=" dark:border-gray-850" />
  499. <div class=" ">
  500. <div class=" text-sm font-medium">{$i18n.t('Query Params')}</div>
  501. <div class=" flex">
  502. <div class=" flex w-full justify-between">
  503. <div class="self-center text-xs font-medium min-w-fit">{$i18n.t('Top K')}</div>
  504. <div class="self-center p-3">
  505. <input
  506. class=" w-full rounded-lg py-1.5 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  507. type="number"
  508. placeholder={$i18n.t('Enter Top K')}
  509. bind:value={querySettings.k}
  510. autocomplete="off"
  511. min="0"
  512. />
  513. </div>
  514. </div>
  515. {#if querySettings.hybrid === true}
  516. <div class="flex w-full">
  517. <div class=" self-center text-xs font-medium min-w-fit">
  518. {$i18n.t('Minimum Score')}
  519. </div>
  520. <div class="self-center p-3">
  521. <input
  522. class=" w-full rounded-lg py-1.5 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  523. type="number"
  524. step="0.01"
  525. placeholder={$i18n.t('Enter Score')}
  526. bind:value={querySettings.r}
  527. autocomplete="off"
  528. min="0.0"
  529. title={$i18n.t('The score should be a value between 0.0 (0%) and 1.0 (100%).')}
  530. />
  531. </div>
  532. </div>
  533. {/if}
  534. </div>
  535. {#if querySettings.hybrid === true}
  536. <div class="mt-2 mb-1 text-xs text-gray-400 dark:text-gray-500">
  537. {$i18n.t(
  538. 'Note: If you set a minimum score, the search will only return documents with a score greater than or equal to the minimum score.'
  539. )}
  540. </div>
  541. <hr class=" dark:border-gray-850 my-3" />
  542. {/if}
  543. <div>
  544. <div class=" mb-2.5 text-sm font-medium">{$i18n.t('RAG Template')}</div>
  545. <textarea
  546. bind:value={querySettings.template}
  547. class="w-full rounded-lg px-4 py-3 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none resize-none"
  548. rows="4"
  549. />
  550. </div>
  551. </div>
  552. <hr class=" dark:border-gray-850" />
  553. <div class=" ">
  554. <div class=" text-sm font-medium">{$i18n.t('Chunk Params')}</div>
  555. <div class=" my-2 flex gap-1.5">
  556. <div class=" w-full justify-between">
  557. <div class="self-center text-xs font-medium min-w-fit mb-1">{$i18n.t('Chunk Size')}</div>
  558. <div class="self-center">
  559. <input
  560. class=" w-full rounded-lg py-1.5 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  561. type="number"
  562. placeholder={$i18n.t('Enter Chunk Size')}
  563. bind:value={chunkSize}
  564. autocomplete="off"
  565. min="0"
  566. />
  567. </div>
  568. </div>
  569. <div class="w-full">
  570. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  571. {$i18n.t('Chunk Overlap')}
  572. </div>
  573. <div class="self-center">
  574. <input
  575. class="w-full rounded-lg py-1.5 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  576. type="number"
  577. placeholder={$i18n.t('Enter Chunk Overlap')}
  578. bind:value={chunkOverlap}
  579. autocomplete="off"
  580. min="0"
  581. />
  582. </div>
  583. </div>
  584. </div>
  585. <div class="my-3">
  586. <div class="flex justify-between items-center text-xs">
  587. <div class=" text-xs font-medium">{$i18n.t('PDF Extract Images (OCR)')}</div>
  588. <button
  589. class=" text-xs font-medium text-gray-500"
  590. type="button"
  591. on:click={() => {
  592. pdfExtractImages = !pdfExtractImages;
  593. }}>{pdfExtractImages ? $i18n.t('On') : $i18n.t('Off')}</button
  594. >
  595. </div>
  596. </div>
  597. </div>
  598. <hr class=" dark:border-gray-850" />
  599. <div>
  600. <button
  601. class=" flex rounded-xl py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
  602. on:click={() => {
  603. showResetUploadDirConfirm = true;
  604. }}
  605. type="button"
  606. >
  607. <div class=" self-center mr-3">
  608. <svg
  609. xmlns="http://www.w3.org/2000/svg"
  610. viewBox="0 0 24 24"
  611. fill="currentColor"
  612. class="size-4"
  613. >
  614. <path
  615. fill-rule="evenodd"
  616. d="M5.625 1.5H9a3.75 3.75 0 0 1 3.75 3.75v1.875c0 1.036.84 1.875 1.875 1.875H16.5a3.75 3.75 0 0 1 3.75 3.75v7.875c0 1.035-.84 1.875-1.875 1.875H5.625a1.875 1.875 0 0 1-1.875-1.875V3.375c0-1.036.84-1.875 1.875-1.875ZM9.75 14.25a.75.75 0 0 0 0 1.5H15a.75.75 0 0 0 0-1.5H9.75Z"
  617. clip-rule="evenodd"
  618. />
  619. <path
  620. d="M14.25 5.25a5.23 5.23 0 0 0-1.279-3.434 9.768 9.768 0 0 1 6.963 6.963A5.23 5.23 0 0 0 16.5 7.5h-1.875a.375.375 0 0 1-.375-.375V5.25Z"
  621. />
  622. </svg>
  623. </div>
  624. <div class=" self-center text-sm font-medium">{$i18n.t('Reset Upload Directory')}</div>
  625. </button>
  626. <button
  627. class=" flex rounded-xl py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
  628. on:click={() => {
  629. showResetConfirm = true;
  630. }}
  631. type="button"
  632. >
  633. <div class=" self-center mr-3">
  634. <svg
  635. xmlns="http://www.w3.org/2000/svg"
  636. viewBox="0 0 16 16"
  637. fill="currentColor"
  638. class="w-4 h-4"
  639. >
  640. <path
  641. fill-rule="evenodd"
  642. d="M3.5 2A1.5 1.5 0 0 0 2 3.5v9A1.5 1.5 0 0 0 3.5 14h9a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 12.5 4H9.621a1.5 1.5 0 0 1-1.06-.44L7.439 2.44A1.5 1.5 0 0 0 6.38 2H3.5Zm6.75 7.75a.75.75 0 0 0 0-1.5h-4.5a.75.75 0 0 0 0 1.5h4.5Z"
  643. clip-rule="evenodd"
  644. />
  645. </svg>
  646. </div>
  647. <div class=" self-center text-sm font-medium">{$i18n.t('Reset Vector Storage')}</div>
  648. </button>
  649. </div>
  650. </div>
  651. <div class="flex justify-end pt-3 text-sm font-medium">
  652. <button
  653. class=" px-4 py-2 bg-emerald-700 hover:bg-emerald-800 text-gray-100 transition rounded-lg"
  654. type="submit"
  655. >
  656. {$i18n.t('Save')}
  657. </button>
  658. </div>
  659. </form>