Documents.svelte 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  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. processDocsDir,
  8. updateQuerySettings,
  9. resetVectorDB,
  10. getEmbeddingConfig,
  11. updateEmbeddingConfig,
  12. getRerankingConfig,
  13. updateRerankingConfig,
  14. resetUploadDir,
  15. getRAGConfig,
  16. updateRAGConfig
  17. } from '$lib/apis/retrieval';
  18. import { projects, models } from '$lib/stores';
  19. import { getProjects } from '$lib/apis/projects';
  20. import { deleteAllFiles, deleteFileById } from '$lib/apis/files';
  21. import ResetUploadDirConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
  22. import ResetVectorDBConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
  23. import SensitiveInput from '$lib/components/common/SensitiveInput.svelte';
  24. import Tooltip from '$lib/components/common/Tooltip.svelte';
  25. const i18n = getContext('i18n');
  26. let scanDirLoading = false;
  27. let updateEmbeddingModelLoading = false;
  28. let updateRerankingModelLoading = false;
  29. let showResetConfirm = false;
  30. let showResetUploadDirConfirm = false;
  31. let embeddingEngine = '';
  32. let embeddingModel = '';
  33. let rerankingModel = '';
  34. let fileMaxSize = null;
  35. let fileMaxCount = null;
  36. let contentExtractionEngine = 'default';
  37. let tikaServerUrl = '';
  38. let showTikaServerUrl = false;
  39. let chunkSize = 0;
  40. let chunkOverlap = 0;
  41. let pdfExtractImages = true;
  42. let OpenAIKey = '';
  43. let OpenAIUrl = '';
  44. let OpenAIBatchSize = 1;
  45. let querySettings = {
  46. template: '',
  47. r: 0.0,
  48. k: 4,
  49. hybrid: false
  50. };
  51. const scanHandler = async () => {
  52. scanDirLoading = true;
  53. const res = await processDocsDir(localStorage.token);
  54. scanDirLoading = false;
  55. if (res) {
  56. await projects.set(await getProjects(localStorage.token));
  57. toast.success($i18n.t('Scan complete!'));
  58. }
  59. };
  60. const embeddingModelUpdateHandler = async () => {
  61. if (embeddingEngine === '' && embeddingModel.split('/').length - 1 > 1) {
  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 === 'ollama' && 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' && embeddingModel === '') {
  78. toast.error(
  79. $i18n.t(
  80. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  81. )
  82. );
  83. return;
  84. }
  85. if ((embeddingEngine === 'openai' && OpenAIKey === '') || OpenAIUrl === '') {
  86. toast.error($i18n.t('OpenAI URL/Key required.'));
  87. return;
  88. }
  89. console.log('Update embedding model attempt:', embeddingModel);
  90. updateEmbeddingModelLoading = true;
  91. const res = await updateEmbeddingConfig(localStorage.token, {
  92. embedding_engine: embeddingEngine,
  93. embedding_model: embeddingModel,
  94. ...(embeddingEngine === 'openai'
  95. ? {
  96. openai_config: {
  97. key: OpenAIKey,
  98. url: OpenAIUrl,
  99. batch_size: OpenAIBatchSize
  100. }
  101. }
  102. : {})
  103. }).catch(async (error) => {
  104. toast.error(error);
  105. await setEmbeddingConfig();
  106. return null;
  107. });
  108. updateEmbeddingModelLoading = false;
  109. if (res) {
  110. console.log('embeddingModelUpdateHandler:', res);
  111. if (res.status === true) {
  112. toast.success($i18n.t('Embedding model set to "{{embedding_model}}"', res), {
  113. duration: 1000 * 10
  114. });
  115. }
  116. }
  117. };
  118. const rerankingModelUpdateHandler = async () => {
  119. console.log('Update reranking model attempt:', rerankingModel);
  120. updateRerankingModelLoading = true;
  121. const res = await updateRerankingConfig(localStorage.token, {
  122. reranking_model: rerankingModel
  123. }).catch(async (error) => {
  124. toast.error(error);
  125. await setRerankingConfig();
  126. return null;
  127. });
  128. updateRerankingModelLoading = false;
  129. if (res) {
  130. console.log('rerankingModelUpdateHandler:', res);
  131. if (res.status === true) {
  132. if (rerankingModel === '') {
  133. toast.success($i18n.t('Reranking model disabled', res), {
  134. duration: 1000 * 10
  135. });
  136. } else {
  137. toast.success($i18n.t('Reranking model set to "{{reranking_model}}"', res), {
  138. duration: 1000 * 10
  139. });
  140. }
  141. }
  142. }
  143. };
  144. const submitHandler = async () => {
  145. await embeddingModelUpdateHandler();
  146. if (querySettings.hybrid) {
  147. await rerankingModelUpdateHandler();
  148. }
  149. if (contentExtractionEngine === 'tika' && tikaServerUrl === '') {
  150. toast.error($i18n.t('Tika Server URL required.'));
  151. return;
  152. }
  153. const res = await updateRAGConfig(localStorage.token, {
  154. pdf_extract_images: pdfExtractImages,
  155. file: {
  156. max_size: fileMaxSize === '' ? null : fileMaxSize,
  157. max_count: fileMaxCount === '' ? null : fileMaxCount
  158. },
  159. chunk: {
  160. chunk_overlap: chunkOverlap,
  161. chunk_size: chunkSize
  162. },
  163. content_extraction: {
  164. engine: contentExtractionEngine,
  165. tika_server_url: tikaServerUrl
  166. }
  167. });
  168. await updateQuerySettings(localStorage.token, querySettings);
  169. dispatch('save');
  170. };
  171. const setEmbeddingConfig = async () => {
  172. const embeddingConfig = await getEmbeddingConfig(localStorage.token);
  173. if (embeddingConfig) {
  174. embeddingEngine = embeddingConfig.embedding_engine;
  175. embeddingModel = embeddingConfig.embedding_model;
  176. OpenAIKey = embeddingConfig.openai_config.key;
  177. OpenAIUrl = embeddingConfig.openai_config.url;
  178. OpenAIBatchSize = embeddingConfig.openai_config.batch_size ?? 1;
  179. }
  180. };
  181. const setRerankingConfig = async () => {
  182. const rerankingConfig = await getRerankingConfig(localStorage.token);
  183. if (rerankingConfig) {
  184. rerankingModel = rerankingConfig.reranking_model;
  185. }
  186. };
  187. const toggleHybridSearch = async () => {
  188. querySettings.hybrid = !querySettings.hybrid;
  189. querySettings = await updateQuerySettings(localStorage.token, querySettings);
  190. };
  191. onMount(async () => {
  192. await setEmbeddingConfig();
  193. await setRerankingConfig();
  194. querySettings = await getQuerySettings(localStorage.token);
  195. const res = await getRAGConfig(localStorage.token);
  196. if (res) {
  197. pdfExtractImages = res.pdf_extract_images;
  198. chunkSize = res.chunk.chunk_size;
  199. chunkOverlap = res.chunk.chunk_overlap;
  200. contentExtractionEngine = res.content_extraction.engine;
  201. tikaServerUrl = res.content_extraction.tika_server_url;
  202. showTikaServerUrl = contentExtractionEngine === 'tika';
  203. fileMaxSize = res?.file.max_size ?? '';
  204. fileMaxCount = res?.file.max_count ?? '';
  205. }
  206. });
  207. </script>
  208. <ResetUploadDirConfirmDialog
  209. bind:show={showResetUploadDirConfirm}
  210. on:confirm={async () => {
  211. const res = await deleteAllFiles(localStorage.token).catch((error) => {
  212. toast.error(error);
  213. return null;
  214. });
  215. if (res) {
  216. toast.success($i18n.t('Success'));
  217. }
  218. }}
  219. />
  220. <ResetVectorDBConfirmDialog
  221. bind:show={showResetConfirm}
  222. on:confirm={() => {
  223. const res = resetVectorDB(localStorage.token).catch((error) => {
  224. toast.error(error);
  225. return null;
  226. });
  227. if (res) {
  228. toast.success($i18n.t('Success'));
  229. }
  230. }}
  231. />
  232. <form
  233. class="flex flex-col h-full justify-between space-y-3 text-sm"
  234. on:submit|preventDefault={() => {
  235. submitHandler();
  236. }}
  237. >
  238. <div class=" space-y-2.5 overflow-y-scroll scrollbar-hidden h-full pr-1.5">
  239. <div class="flex flex-col gap-0.5">
  240. <div class=" mb-0.5 text-sm font-medium">{$i18n.t('General Settings')}</div>
  241. <div class=" flex w-full justify-between">
  242. <div class=" self-center text-xs font-medium">
  243. {$i18n.t('Scan for documents from {{path}}', { path: 'DOCS_DIR (/data/docs)' })}
  244. </div>
  245. <button
  246. class=" self-center text-xs p-1 px-3 bg-gray-50 dark:bg-gray-800 dark:hover:bg-gray-700 rounded-lg flex flex-row space-x-1 items-center {scanDirLoading
  247. ? ' cursor-not-allowed'
  248. : ''}"
  249. on:click={() => {
  250. scanHandler();
  251. console.log('check');
  252. }}
  253. type="button"
  254. disabled={scanDirLoading}
  255. >
  256. <div class="self-center font-medium">{$i18n.t('Scan')}</div>
  257. {#if scanDirLoading}
  258. <div class="ml-3 self-center">
  259. <svg
  260. class=" w-3 h-3"
  261. viewBox="0 0 24 24"
  262. fill="currentColor"
  263. xmlns="http://www.w3.org/2000/svg"
  264. >
  265. <style>
  266. .spinner_ajPY {
  267. transform-origin: center;
  268. animation: spinner_AtaB 0.75s infinite linear;
  269. }
  270. @keyframes spinner_AtaB {
  271. 100% {
  272. transform: rotate(360deg);
  273. }
  274. }
  275. </style>
  276. <path
  277. 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"
  278. opacity=".25"
  279. />
  280. <path
  281. 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"
  282. class="spinner_ajPY"
  283. />
  284. </svg>
  285. </div>
  286. {/if}
  287. </button>
  288. </div>
  289. <div class=" flex w-full justify-between">
  290. <div class=" self-center text-xs font-medium">{$i18n.t('Embedding Model Engine')}</div>
  291. <div class="flex items-center relative">
  292. <select
  293. class="dark:bg-gray-900 w-fit pr-8 rounded px-2 p-1 text-xs bg-transparent outline-none text-right"
  294. bind:value={embeddingEngine}
  295. placeholder="Select an embedding model engine"
  296. on:change={(e) => {
  297. if (e.target.value === 'ollama') {
  298. embeddingModel = '';
  299. } else if (e.target.value === 'openai') {
  300. embeddingModel = 'text-embedding-3-small';
  301. } else if (e.target.value === '') {
  302. embeddingModel = 'sentence-transformers/all-MiniLM-L6-v2';
  303. }
  304. }}
  305. >
  306. <option value="">{$i18n.t('Default (SentenceTransformers)')}</option>
  307. <option value="ollama">{$i18n.t('Ollama')}</option>
  308. <option value="openai">{$i18n.t('OpenAI')}</option>
  309. </select>
  310. </div>
  311. </div>
  312. {#if embeddingEngine === 'openai'}
  313. <div class="my-0.5 flex gap-2">
  314. <input
  315. class="flex-1 w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  316. placeholder={$i18n.t('API Base URL')}
  317. bind:value={OpenAIUrl}
  318. required
  319. />
  320. <SensitiveInput placeholder={$i18n.t('API Key')} bind:value={OpenAIKey} />
  321. </div>
  322. <div class="flex mt-0.5 space-x-2">
  323. <div class=" self-center text-xs font-medium">{$i18n.t('Embedding Batch Size')}</div>
  324. <div class=" flex-1">
  325. <input
  326. id="steps-range"
  327. type="range"
  328. min="1"
  329. max="2048"
  330. step="1"
  331. bind:value={OpenAIBatchSize}
  332. class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
  333. />
  334. </div>
  335. <div class="">
  336. <input
  337. bind:value={OpenAIBatchSize}
  338. type="number"
  339. class=" bg-transparent text-center w-14"
  340. min="-2"
  341. max="16000"
  342. step="1"
  343. />
  344. </div>
  345. </div>
  346. {/if}
  347. <div class=" flex w-full justify-between">
  348. <div class=" self-center text-xs font-medium">{$i18n.t('Hybrid Search')}</div>
  349. <button
  350. class="p-1 px-3 text-xs flex rounded transition"
  351. on:click={() => {
  352. toggleHybridSearch();
  353. }}
  354. type="button"
  355. >
  356. {#if querySettings.hybrid === true}
  357. <span class="ml-2 self-center">{$i18n.t('On')}</span>
  358. {:else}
  359. <span class="ml-2 self-center">{$i18n.t('Off')}</span>
  360. {/if}
  361. </button>
  362. </div>
  363. </div>
  364. <hr class="dark:border-gray-850" />
  365. <div class="space-y-2" />
  366. <div>
  367. <div class=" mb-2 text-sm font-medium">{$i18n.t('Embedding Model')}</div>
  368. {#if embeddingEngine === 'ollama'}
  369. <div class="flex w-full">
  370. <div class="flex-1 mr-2">
  371. <select
  372. class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  373. bind:value={embeddingModel}
  374. placeholder={$i18n.t('Select a model')}
  375. required
  376. >
  377. {#if !embeddingModel}
  378. <option value="" disabled selected>{$i18n.t('Select a model')}</option>
  379. {/if}
  380. {#each $models.filter((m) => m.id && m.ollama && !(m?.preset ?? false)) as model}
  381. <option value={model.id} class="bg-gray-50 dark:bg-gray-700">{model.name}</option>
  382. {/each}
  383. </select>
  384. </div>
  385. </div>
  386. {:else}
  387. <div class="flex w-full">
  388. <div class="flex-1 mr-2">
  389. <input
  390. class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  391. placeholder={$i18n.t('Set embedding model (e.g. {{model}})', {
  392. model: embeddingModel.slice(-40)
  393. })}
  394. bind:value={embeddingModel}
  395. />
  396. </div>
  397. {#if embeddingEngine === ''}
  398. <button
  399. class="px-2.5 bg-gray-50 hover:bg-gray-200 text-gray-800 dark:bg-gray-850 dark:hover:bg-gray-800 dark:text-gray-100 rounded-lg transition"
  400. on:click={() => {
  401. embeddingModelUpdateHandler();
  402. }}
  403. disabled={updateEmbeddingModelLoading}
  404. >
  405. {#if updateEmbeddingModelLoading}
  406. <div class="self-center">
  407. <svg
  408. class=" w-4 h-4"
  409. viewBox="0 0 24 24"
  410. fill="currentColor"
  411. xmlns="http://www.w3.org/2000/svg"
  412. >
  413. <style>
  414. .spinner_ajPY {
  415. transform-origin: center;
  416. animation: spinner_AtaB 0.75s infinite linear;
  417. }
  418. @keyframes spinner_AtaB {
  419. 100% {
  420. transform: rotate(360deg);
  421. }
  422. }
  423. </style>
  424. <path
  425. 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"
  426. opacity=".25"
  427. />
  428. <path
  429. 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"
  430. class="spinner_ajPY"
  431. />
  432. </svg>
  433. </div>
  434. {:else}
  435. <svg
  436. xmlns="http://www.w3.org/2000/svg"
  437. viewBox="0 0 16 16"
  438. fill="currentColor"
  439. class="w-4 h-4"
  440. >
  441. <path
  442. 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"
  443. />
  444. <path
  445. 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"
  446. />
  447. </svg>
  448. {/if}
  449. </button>
  450. {/if}
  451. </div>
  452. {/if}
  453. <div class="mt-2 mb-1 text-xs text-gray-400 dark:text-gray-500">
  454. {$i18n.t(
  455. 'Warning: If you update or change your embedding model, you will need to re-import all documents.'
  456. )}
  457. </div>
  458. {#if querySettings.hybrid === true}
  459. <div class=" ">
  460. <div class=" mb-2 text-sm font-medium">{$i18n.t('Reranking Model')}</div>
  461. <div class="flex w-full">
  462. <div class="flex-1 mr-2">
  463. <input
  464. class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  465. placeholder={$i18n.t('Set reranking model (e.g. {{model}})', {
  466. model: 'BAAI/bge-reranker-v2-m3'
  467. })}
  468. bind:value={rerankingModel}
  469. />
  470. </div>
  471. <button
  472. class="px-2.5 bg-gray-50 hover:bg-gray-200 text-gray-800 dark:bg-gray-850 dark:hover:bg-gray-800 dark:text-gray-100 rounded-lg transition"
  473. on:click={() => {
  474. rerankingModelUpdateHandler();
  475. }}
  476. disabled={updateRerankingModelLoading}
  477. >
  478. {#if updateRerankingModelLoading}
  479. <div class="self-center">
  480. <svg
  481. class=" w-4 h-4"
  482. viewBox="0 0 24 24"
  483. fill="currentColor"
  484. xmlns="http://www.w3.org/2000/svg"
  485. >
  486. <style>
  487. .spinner_ajPY {
  488. transform-origin: center;
  489. animation: spinner_AtaB 0.75s infinite linear;
  490. }
  491. @keyframes spinner_AtaB {
  492. 100% {
  493. transform: rotate(360deg);
  494. }
  495. }
  496. </style>
  497. <path
  498. 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"
  499. opacity=".25"
  500. />
  501. <path
  502. 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"
  503. class="spinner_ajPY"
  504. />
  505. </svg>
  506. </div>
  507. {:else}
  508. <svg
  509. xmlns="http://www.w3.org/2000/svg"
  510. viewBox="0 0 16 16"
  511. fill="currentColor"
  512. class="w-4 h-4"
  513. >
  514. <path
  515. 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"
  516. />
  517. <path
  518. 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"
  519. />
  520. </svg>
  521. {/if}
  522. </button>
  523. </div>
  524. </div>
  525. {/if}
  526. </div>
  527. <hr class=" dark:border-gray-850" />
  528. <div class="">
  529. <div class="text-sm font-medium">{$i18n.t('Content Extraction')}</div>
  530. <div class="flex w-full justify-between mt-2">
  531. <div class="self-center text-xs font-medium">{$i18n.t('Engine')}</div>
  532. <div class="flex items-center relative">
  533. <select
  534. class="dark:bg-gray-900 w-fit pr-8 rounded px-2 p-1 text-xs bg-transparent outline-none text-right"
  535. bind:value={contentExtractionEngine}
  536. on:change={(e) => {
  537. showTikaServerUrl = e.target.value === 'tika';
  538. }}
  539. >
  540. <option value="">{$i18n.t('Default')} </option>
  541. <option value="tika">{$i18n.t('Tika')}</option>
  542. </select>
  543. </div>
  544. </div>
  545. {#if showTikaServerUrl}
  546. <div class="flex w-full mt-2">
  547. <div class="flex-1 mr-2">
  548. <input
  549. class="w-full rounded-lg py-2 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  550. placeholder={$i18n.t('Enter Tika Server URL')}
  551. bind:value={tikaServerUrl}
  552. />
  553. </div>
  554. </div>
  555. {/if}
  556. </div>
  557. <hr class=" dark:border-gray-850" />
  558. <div class="">
  559. <div class="text-sm font-medium">{$i18n.t('Files')}</div>
  560. <div class=" my-2 flex gap-1.5">
  561. <div class="w-full">
  562. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  563. {$i18n.t('Max Upload Size')}
  564. </div>
  565. <div class="self-center">
  566. <Tooltip
  567. content={$i18n.t(
  568. 'The maximum file size in MB. If the file size exceeds this limit, the file will not be uploaded.'
  569. )}
  570. placement="top-start"
  571. >
  572. <input
  573. class="w-full rounded-lg py-1.5 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  574. type="number"
  575. placeholder={$i18n.t('Leave empty for unlimited')}
  576. bind:value={fileMaxSize}
  577. autocomplete="off"
  578. min="0"
  579. />
  580. </Tooltip>
  581. </div>
  582. </div>
  583. <div class=" w-full">
  584. <div class="self-center text-xs font-medium min-w-fit mb-1">
  585. {$i18n.t('Max Upload Count')}
  586. </div>
  587. <div class="self-center">
  588. <Tooltip
  589. content={$i18n.t(
  590. '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.'
  591. )}
  592. placement="top-start"
  593. >
  594. <input
  595. class=" w-full rounded-lg py-1.5 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  596. type="number"
  597. placeholder={$i18n.t('Leave empty for unlimited')}
  598. bind:value={fileMaxCount}
  599. autocomplete="off"
  600. min="0"
  601. />
  602. </Tooltip>
  603. </div>
  604. </div>
  605. </div>
  606. </div>
  607. <hr class=" dark:border-gray-850" />
  608. <div class=" ">
  609. <div class=" text-sm font-medium">{$i18n.t('Query Params')}</div>
  610. <div class=" flex gap-1">
  611. <div class=" flex w-full justify-between">
  612. <div class="self-center text-xs font-medium min-w-fit">{$i18n.t('Top K')}</div>
  613. <div class="self-center p-3">
  614. <input
  615. class=" w-full rounded-lg py-1.5 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  616. type="number"
  617. placeholder={$i18n.t('Enter Top K')}
  618. bind:value={querySettings.k}
  619. autocomplete="off"
  620. min="0"
  621. />
  622. </div>
  623. </div>
  624. {#if querySettings.hybrid === true}
  625. <div class=" flex w-full justify-between">
  626. <div class=" self-center text-xs font-medium min-w-fit">
  627. {$i18n.t('Minimum Score')}
  628. </div>
  629. <div class="self-center p-3">
  630. <input
  631. class=" w-full rounded-lg py-1.5 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  632. type="number"
  633. step="0.01"
  634. placeholder={$i18n.t('Enter Score')}
  635. bind:value={querySettings.r}
  636. autocomplete="off"
  637. min="0.0"
  638. title={$i18n.t('The score should be a value between 0.0 (0%) and 1.0 (100%).')}
  639. />
  640. </div>
  641. </div>
  642. {/if}
  643. </div>
  644. {#if querySettings.hybrid === true}
  645. <div class="mt-2 mb-1 text-xs text-gray-400 dark:text-gray-500">
  646. {$i18n.t(
  647. 'Note: If you set a minimum score, the search will only return documents with a score greater than or equal to the minimum score.'
  648. )}
  649. </div>
  650. <hr class=" dark:border-gray-850 my-3" />
  651. {/if}
  652. <div>
  653. <div class=" mb-2.5 text-sm font-medium">{$i18n.t('RAG Template')}</div>
  654. <Tooltip
  655. content={$i18n.t('Leave empty to use the default prompt, or enter a custom prompt')}
  656. placement="top-start"
  657. >
  658. <textarea
  659. bind:value={querySettings.template}
  660. placeholder={$i18n.t('Leave empty to use the default prompt, or enter a custom prompt')}
  661. class="w-full rounded-lg px-4 py-3 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none resize-none"
  662. rows="4"
  663. />
  664. </Tooltip>
  665. </div>
  666. </div>
  667. <hr class=" dark:border-gray-850" />
  668. <div class=" ">
  669. <div class=" text-sm font-medium">{$i18n.t('Chunk Params')}</div>
  670. <div class=" my-2 flex gap-1.5">
  671. <div class=" w-full justify-between">
  672. <div class="self-center text-xs font-medium min-w-fit mb-1">{$i18n.t('Chunk Size')}</div>
  673. <div class="self-center">
  674. <input
  675. class=" w-full rounded-lg py-1.5 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  676. type="number"
  677. placeholder={$i18n.t('Enter Chunk Size')}
  678. bind:value={chunkSize}
  679. autocomplete="off"
  680. min="0"
  681. />
  682. </div>
  683. </div>
  684. <div class="w-full">
  685. <div class=" self-center text-xs font-medium min-w-fit mb-1">
  686. {$i18n.t('Chunk Overlap')}
  687. </div>
  688. <div class="self-center">
  689. <input
  690. class="w-full rounded-lg py-1.5 px-4 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-none"
  691. type="number"
  692. placeholder={$i18n.t('Enter Chunk Overlap')}
  693. bind:value={chunkOverlap}
  694. autocomplete="off"
  695. min="0"
  696. />
  697. </div>
  698. </div>
  699. </div>
  700. <div class="my-3">
  701. <div class="flex justify-between items-center text-xs">
  702. <div class=" text-xs font-medium">{$i18n.t('PDF Extract Images (OCR)')}</div>
  703. <button
  704. class=" text-xs font-medium text-gray-500"
  705. type="button"
  706. on:click={() => {
  707. pdfExtractImages = !pdfExtractImages;
  708. }}>{pdfExtractImages ? $i18n.t('On') : $i18n.t('Off')}</button
  709. >
  710. </div>
  711. </div>
  712. </div>
  713. <hr class=" dark:border-gray-850" />
  714. <div>
  715. <button
  716. class=" flex rounded-xl py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
  717. on:click={() => {
  718. showResetUploadDirConfirm = true;
  719. }}
  720. type="button"
  721. >
  722. <div class=" self-center mr-3">
  723. <svg
  724. xmlns="http://www.w3.org/2000/svg"
  725. viewBox="0 0 24 24"
  726. fill="currentColor"
  727. class="size-4"
  728. >
  729. <path
  730. fill-rule="evenodd"
  731. 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"
  732. clip-rule="evenodd"
  733. />
  734. <path
  735. 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"
  736. />
  737. </svg>
  738. </div>
  739. <div class=" self-center text-sm font-medium">{$i18n.t('Reset Upload Directory')}</div>
  740. </button>
  741. <button
  742. class=" flex rounded-xl py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
  743. on:click={() => {
  744. showResetConfirm = true;
  745. }}
  746. type="button"
  747. >
  748. <div class=" self-center mr-3">
  749. <svg
  750. xmlns="http://www.w3.org/2000/svg"
  751. viewBox="0 0 16 16"
  752. fill="currentColor"
  753. class="w-4 h-4"
  754. >
  755. <path
  756. fill-rule="evenodd"
  757. 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"
  758. clip-rule="evenodd"
  759. />
  760. </svg>
  761. </div>
  762. <div class=" self-center text-sm font-medium">{$i18n.t('Reset Vector Storage')}</div>
  763. </button>
  764. </div>
  765. </div>
  766. <div class="flex justify-end pt-3 text-sm font-medium">
  767. <button
  768. class=" px-4 py-2 bg-emerald-700 hover:bg-emerald-800 text-gray-100 transition rounded-lg"
  769. type="submit"
  770. >
  771. {$i18n.t('Save')}
  772. </button>
  773. </div>
  774. </form>