Documents.svelte 24 KB

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