Documents.svelte 25 KB

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