Documents.svelte 25 KB

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