Documents.svelte 23 KB

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