Documents.svelte 23 KB

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