Documents.svelte 25 KB

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