General.svelte 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. <script lang="ts">
  2. import { getDocs } from '$lib/apis/documents';
  3. import {
  4. getRAGConfig,
  5. updateRAGConfig,
  6. getQuerySettings,
  7. scanDocs,
  8. updateQuerySettings,
  9. resetVectorDB,
  10. getEmbeddingConfig,
  11. updateEmbeddingConfig,
  12. getRerankingConfig,
  13. updateRerankingConfig
  14. } from '$lib/apis/rag';
  15. import { documents, models } from '$lib/stores';
  16. import { onMount, getContext } from 'svelte';
  17. import { toast } from 'svelte-sonner';
  18. import Tooltip from '$lib/components/common/Tooltip.svelte';
  19. const i18n = getContext('i18n');
  20. export let saveHandler: Function;
  21. let scanDirLoading = false;
  22. let updateEmbeddingModelLoading = false;
  23. let updateRerankingModelLoading = false;
  24. let showResetConfirm = false;
  25. let embeddingEngine = '';
  26. let embeddingModel = '';
  27. let rerankingModel = '';
  28. let OpenAIKey = '';
  29. let OpenAIUrl = '';
  30. let chunkSize = 0;
  31. let chunkOverlap = 0;
  32. let pdfExtractImages = true;
  33. let querySettings = {
  34. template: '',
  35. r: 0.0,
  36. k: 4,
  37. hybrid: false
  38. };
  39. const scanHandler = async () => {
  40. scanDirLoading = true;
  41. const res = await scanDocs(localStorage.token);
  42. scanDirLoading = false;
  43. if (res) {
  44. await documents.set(await getDocs(localStorage.token));
  45. toast.success($i18n.t('Scan complete!'));
  46. }
  47. };
  48. const embeddingModelUpdateHandler = async () => {
  49. if (embeddingEngine === '' && embeddingModel.split('/').length - 1 > 1) {
  50. toast.error(
  51. $i18n.t(
  52. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  53. )
  54. );
  55. return;
  56. }
  57. if (embeddingEngine === 'ollama' && embeddingModel === '') {
  58. toast.error(
  59. $i18n.t(
  60. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  61. )
  62. );
  63. return;
  64. }
  65. if (embeddingEngine === 'openai' && embeddingModel === '') {
  66. toast.error(
  67. $i18n.t(
  68. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  69. )
  70. );
  71. return;
  72. }
  73. if ((embeddingEngine === 'openai' && OpenAIKey === '') || OpenAIUrl === '') {
  74. toast.error($i18n.t('OpenAI URL/Key required.'));
  75. return;
  76. }
  77. console.log('Update embedding model attempt:', embeddingModel);
  78. updateEmbeddingModelLoading = true;
  79. const res = await updateEmbeddingConfig(localStorage.token, {
  80. embedding_engine: embeddingEngine,
  81. embedding_model: embeddingModel,
  82. ...(embeddingEngine === 'openai'
  83. ? {
  84. openai_config: {
  85. key: OpenAIKey,
  86. url: OpenAIUrl
  87. }
  88. }
  89. : {})
  90. }).catch(async (error) => {
  91. toast.error(error);
  92. await setEmbeddingConfig();
  93. return null;
  94. });
  95. updateEmbeddingModelLoading = false;
  96. if (res) {
  97. console.log('embeddingModelUpdateHandler:', res);
  98. if (res.status === true) {
  99. toast.success($i18n.t('Embedding model set to "{{embedding_model}}"', res), {
  100. duration: 1000 * 10
  101. });
  102. }
  103. }
  104. };
  105. const rerankingModelUpdateHandler = async () => {
  106. console.log('Update reranking model attempt:', rerankingModel);
  107. updateRerankingModelLoading = true;
  108. const res = await updateRerankingConfig(localStorage.token, {
  109. reranking_model: rerankingModel
  110. }).catch(async (error) => {
  111. toast.error(error);
  112. await setRerankingConfig();
  113. return null;
  114. });
  115. updateRerankingModelLoading = false;
  116. if (res) {
  117. console.log('rerankingModelUpdateHandler:', res);
  118. if (res.status === true) {
  119. toast.success($i18n.t('Reranking model set to "{{reranking_model}}"', res), {
  120. duration: 1000 * 10
  121. });
  122. }
  123. }
  124. };
  125. const submitHandler = async () => {
  126. const res = await updateRAGConfig(localStorage.token, {
  127. pdf_extract_images: pdfExtractImages,
  128. chunk: {
  129. chunk_overlap: chunkOverlap,
  130. chunk_size: chunkSize
  131. }
  132. });
  133. querySettings = await updateQuerySettings(localStorage.token, querySettings);
  134. };
  135. const setEmbeddingConfig = async () => {
  136. const embeddingConfig = await getEmbeddingConfig(localStorage.token);
  137. if (embeddingConfig) {
  138. embeddingEngine = embeddingConfig.embedding_engine;
  139. embeddingModel = embeddingConfig.embedding_model;
  140. OpenAIKey = embeddingConfig.openai_config.key;
  141. OpenAIUrl = embeddingConfig.openai_config.url;
  142. }
  143. };
  144. const setRerankingConfig = async () => {
  145. const rerankingConfig = await getRerankingConfig(localStorage.token);
  146. if (rerankingConfig) {
  147. rerankingModel = rerankingConfig.reranking_model;
  148. }
  149. };
  150. const toggleHybridSearch = async () => {
  151. querySettings.hybrid = !querySettings.hybrid;
  152. querySettings = await updateQuerySettings(localStorage.token, querySettings);
  153. };
  154. onMount(async () => {
  155. const res = await getRAGConfig(localStorage.token);
  156. if (res) {
  157. pdfExtractImages = res.pdf_extract_images;
  158. chunkSize = res.chunk.chunk_size;
  159. chunkOverlap = res.chunk.chunk_overlap;
  160. }
  161. await setEmbeddingConfig();
  162. await setRerankingConfig();
  163. querySettings = await getQuerySettings(localStorage.token);
  164. });
  165. </script>
  166. <form
  167. class="flex flex-col h-full justify-between space-y-3 text-sm"
  168. on:submit|preventDefault={() => {
  169. submitHandler();
  170. saveHandler();
  171. }}
  172. >
  173. <div class=" space-y-3 pr-1.5 overflow-y-scroll max-h-[22rem]">
  174. <div>
  175. <div class=" mb-2 text-sm font-medium">{$i18n.t('General Settings')}</div>
  176. <div class=" flex w-full justify-between">
  177. <div class=" self-center text-xs font-medium">{$i18n.t('Hybrid Search')}</div>
  178. <button
  179. class="p-1 px-3 text-xs flex rounded transition"
  180. on:click={() => {
  181. toggleHybridSearch();
  182. }}
  183. type="button"
  184. >
  185. {#if querySettings.hybrid === true}
  186. <span class="ml-2 self-center">{$i18n.t('On')}</span>
  187. {:else}
  188. <span class="ml-2 self-center">{$i18n.t('Off')}</span>
  189. {/if}
  190. </button>
  191. </div>
  192. <div class=" flex w-full justify-between">
  193. <div class=" self-center text-xs font-medium">{$i18n.t('Embedding Model Engine')}</div>
  194. <div class="flex items-center relative">
  195. <select
  196. class="dark:bg-gray-900 w-fit pr-8 rounded px-2 p-1 text-xs bg-transparent outline-none text-right"
  197. bind:value={embeddingEngine}
  198. placeholder="Select an embedding model engine"
  199. on:change={(e) => {
  200. if (e.target.value === 'ollama') {
  201. embeddingModel = '';
  202. } else if (e.target.value === 'openai') {
  203. embeddingModel = 'text-embedding-3-small';
  204. }
  205. }}
  206. >
  207. <option value="">{$i18n.t('Default (SentenceTransformers)')}</option>
  208. <option value="ollama">{$i18n.t('Ollama')}</option>
  209. <option value="openai">{$i18n.t('OpenAI')}</option>
  210. </select>
  211. </div>
  212. </div>
  213. {#if embeddingEngine === 'openai'}
  214. <div class="mt-1 flex gap-2">
  215. <input
  216. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  217. placeholder={$i18n.t('API Base URL')}
  218. bind:value={OpenAIUrl}
  219. required
  220. />
  221. <input
  222. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  223. placeholder={$i18n.t('API Key')}
  224. bind:value={OpenAIKey}
  225. required
  226. />
  227. </div>
  228. {/if}
  229. </div>
  230. <div class="space-y-2">
  231. <div>
  232. <div class=" mb-2 text-sm font-medium">{$i18n.t('Update Embedding Model')}</div>
  233. {#if embeddingEngine === 'ollama'}
  234. <div class="flex w-full">
  235. <div class="flex-1 mr-2">
  236. <select
  237. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  238. bind:value={embeddingModel}
  239. placeholder={$i18n.t('Select a model')}
  240. required
  241. >
  242. {#if !embeddingModel}
  243. <option value="" disabled selected>{$i18n.t('Select a model')}</option>
  244. {/if}
  245. {#each $models.filter((m) => m.id && !m.external) as model}
  246. <option value={model.name} class="bg-gray-100 dark:bg-gray-700"
  247. >{model.name + ' (' + (model.size / 1024 ** 3).toFixed(1) + ' GB)'}</option
  248. >
  249. {/each}
  250. </select>
  251. </div>
  252. <button
  253. class="px-2.5 bg-gray-100 hover:bg-gray-200 text-gray-800 dark:bg-gray-850 dark:hover:bg-gray-800 dark:text-gray-100 rounded-lg transition"
  254. on:click={() => {
  255. embeddingModelUpdateHandler();
  256. }}
  257. disabled={updateEmbeddingModelLoading}
  258. >
  259. {#if updateEmbeddingModelLoading}
  260. <div class="self-center">
  261. <svg
  262. class=" w-4 h-4"
  263. viewBox="0 0 24 24"
  264. fill="currentColor"
  265. xmlns="http://www.w3.org/2000/svg"
  266. ><style>
  267. .spinner_ajPY {
  268. transform-origin: center;
  269. animation: spinner_AtaB 0.75s infinite linear;
  270. }
  271. @keyframes spinner_AtaB {
  272. 100% {
  273. transform: rotate(360deg);
  274. }
  275. }
  276. </style><path
  277. 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"
  278. opacity=".25"
  279. /><path
  280. 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"
  281. class="spinner_ajPY"
  282. /></svg
  283. >
  284. </div>
  285. {:else}
  286. <svg
  287. xmlns="http://www.w3.org/2000/svg"
  288. viewBox="0 0 16 16"
  289. fill="currentColor"
  290. class="w-4 h-4"
  291. >
  292. <path
  293. fill-rule="evenodd"
  294. d="M12.416 3.376a.75.75 0 0 1 .208 1.04l-5 7.5a.75.75 0 0 1-1.154.114l-3-3a.75.75 0 0 1 1.06-1.06l2.353 2.353 4.493-6.74a.75.75 0 0 1 1.04-.207Z"
  295. clip-rule="evenodd"
  296. />
  297. </svg>
  298. {/if}
  299. </button>
  300. </div>
  301. {:else}
  302. <div class="flex w-full">
  303. <div class="flex-1 mr-2">
  304. <input
  305. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  306. placeholder={$i18n.t('Update embedding model (e.g. {{model}})', {
  307. model: embeddingModel.slice(-40)
  308. })}
  309. bind:value={embeddingModel}
  310. />
  311. </div>
  312. <button
  313. class="px-2.5 bg-gray-100 hover:bg-gray-200 text-gray-800 dark:bg-gray-850 dark:hover:bg-gray-800 dark:text-gray-100 rounded-lg transition"
  314. on:click={() => {
  315. embeddingModelUpdateHandler();
  316. }}
  317. disabled={updateEmbeddingModelLoading}
  318. >
  319. {#if updateEmbeddingModelLoading}
  320. <div class="self-center">
  321. <svg
  322. class=" w-4 h-4"
  323. viewBox="0 0 24 24"
  324. fill="currentColor"
  325. xmlns="http://www.w3.org/2000/svg"
  326. ><style>
  327. .spinner_ajPY {
  328. transform-origin: center;
  329. animation: spinner_AtaB 0.75s infinite linear;
  330. }
  331. @keyframes spinner_AtaB {
  332. 100% {
  333. transform: rotate(360deg);
  334. }
  335. }
  336. </style><path
  337. 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"
  338. opacity=".25"
  339. /><path
  340. 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"
  341. class="spinner_ajPY"
  342. /></svg
  343. >
  344. </div>
  345. {:else}
  346. <svg
  347. xmlns="http://www.w3.org/2000/svg"
  348. viewBox="0 0 16 16"
  349. fill="currentColor"
  350. class="w-4 h-4"
  351. >
  352. <path
  353. 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"
  354. />
  355. <path
  356. 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"
  357. />
  358. </svg>
  359. {/if}
  360. </button>
  361. </div>
  362. {/if}
  363. <div class="mt-2 mb-1 text-xs text-gray-400 dark:text-gray-500">
  364. {$i18n.t(
  365. 'Warning: If you update or change your embedding model, you will need to re-import all documents.'
  366. )}
  367. </div>
  368. <hr class=" dark:border-gray-700 my-3" />
  369. {#if querySettings.hybrid === true}
  370. <div class=" ">
  371. <div class=" mb-2 text-sm font-medium">{$i18n.t('Update Reranking Model')}</div>
  372. <div class="flex w-full">
  373. <div class="flex-1 mr-2">
  374. <input
  375. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  376. placeholder={$i18n.t('Update reranking model (e.g. {{model}})', {
  377. model: rerankingModel.slice(-40)
  378. })}
  379. bind:value={rerankingModel}
  380. />
  381. </div>
  382. <button
  383. class="px-2.5 bg-gray-100 hover:bg-gray-200 text-gray-800 dark:bg-gray-850 dark:hover:bg-gray-800 dark:text-gray-100 rounded-lg transition"
  384. on:click={() => {
  385. rerankingModelUpdateHandler();
  386. }}
  387. disabled={updateRerankingModelLoading}
  388. >
  389. {#if updateRerankingModelLoading}
  390. <div class="self-center">
  391. <svg
  392. class=" w-4 h-4"
  393. viewBox="0 0 24 24"
  394. fill="currentColor"
  395. xmlns="http://www.w3.org/2000/svg"
  396. ><style>
  397. .spinner_ajPY {
  398. transform-origin: center;
  399. animation: spinner_AtaB 0.75s infinite linear;
  400. }
  401. @keyframes spinner_AtaB {
  402. 100% {
  403. transform: rotate(360deg);
  404. }
  405. }
  406. </style><path
  407. 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"
  408. opacity=".25"
  409. /><path
  410. 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"
  411. class="spinner_ajPY"
  412. /></svg
  413. >
  414. </div>
  415. {:else}
  416. <svg
  417. xmlns="http://www.w3.org/2000/svg"
  418. viewBox="0 0 16 16"
  419. fill="currentColor"
  420. class="w-4 h-4"
  421. >
  422. <path
  423. 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"
  424. />
  425. <path
  426. 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"
  427. />
  428. </svg>
  429. {/if}
  430. </button>
  431. </div>
  432. </div>
  433. <hr class=" dark:border-gray-700 my-3" />
  434. {/if}
  435. <div class=" flex w-full justify-between">
  436. <div class=" self-center text-xs font-medium">
  437. {$i18n.t('Scan for documents from {{path}}', { path: '/data/docs' })}
  438. </div>
  439. <button
  440. class=" self-center text-xs p-1 px-3 bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 rounded-lg flex flex-row space-x-1 items-center {scanDirLoading
  441. ? ' cursor-not-allowed'
  442. : ''}"
  443. on:click={() => {
  444. scanHandler();
  445. console.log('check');
  446. }}
  447. type="button"
  448. disabled={scanDirLoading}
  449. >
  450. <div class="self-center font-medium">{$i18n.t('Scan')}</div>
  451. {#if scanDirLoading}
  452. <div class="ml-3 self-center">
  453. <svg
  454. class=" w-3 h-3"
  455. viewBox="0 0 24 24"
  456. fill="currentColor"
  457. xmlns="http://www.w3.org/2000/svg"
  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><path
  469. 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"
  470. opacity=".25"
  471. /><path
  472. 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"
  473. class="spinner_ajPY"
  474. /></svg
  475. >
  476. </div>
  477. {/if}
  478. </button>
  479. </div>
  480. <hr class=" dark:border-gray-700 my-3" />
  481. <div class=" ">
  482. <div class=" text-sm font-medium">{$i18n.t('Chunk Params')}</div>
  483. <div class=" flex">
  484. <div class=" flex w-full justify-between">
  485. <div class="self-center text-xs font-medium min-w-fit">{$i18n.t('Chunk Size')}</div>
  486. <div class="self-center p-3">
  487. <input
  488. class=" w-full rounded-lg py-1.5 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  489. type="number"
  490. placeholder={$i18n.t('Enter Chunk Size')}
  491. bind:value={chunkSize}
  492. autocomplete="off"
  493. min="0"
  494. />
  495. </div>
  496. </div>
  497. <div class="flex w-full">
  498. <div class=" self-center text-xs font-medium min-w-fit">
  499. {$i18n.t('Chunk Overlap')}
  500. </div>
  501. <div class="self-center p-3">
  502. <input
  503. class="w-full rounded-lg py-1.5 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  504. type="number"
  505. placeholder={$i18n.t('Enter Chunk Overlap')}
  506. bind:value={chunkOverlap}
  507. autocomplete="off"
  508. min="0"
  509. />
  510. </div>
  511. </div>
  512. </div>
  513. <div class="pr-2">
  514. <div class="flex justify-between items-center text-xs">
  515. <div class=" text-xs font-medium">{$i18n.t('PDF Extract Images (OCR)')}</div>
  516. <button
  517. class=" text-xs font-medium text-gray-500"
  518. type="button"
  519. on:click={() => {
  520. pdfExtractImages = !pdfExtractImages;
  521. }}>{pdfExtractImages ? $i18n.t('On') : $i18n.t('Off')}</button
  522. >
  523. </div>
  524. </div>
  525. </div>
  526. <hr class=" dark:border-gray-700 my-3" />
  527. <div>
  528. <div class=" text-sm font-medium">{$i18n.t('Query Params')}</div>
  529. <div class=" flex">
  530. <div class=" flex w-full justify-between">
  531. <div class="self-center text-xs font-medium flex-1">{$i18n.t('Top K')}</div>
  532. <div class="self-center p-3">
  533. <input
  534. class=" w-full rounded-lg py-1.5 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  535. type="number"
  536. placeholder={$i18n.t('Enter Top K')}
  537. bind:value={querySettings.k}
  538. autocomplete="off"
  539. min="0"
  540. />
  541. </div>
  542. </div>
  543. </div>
  544. {#if querySettings.hybrid === true}
  545. <div class=" flex">
  546. <div class=" flex w-full justify-between">
  547. <div class="self-center text-xs font-medium flex-1">
  548. {$i18n.t('Relevance Threshold')}
  549. </div>
  550. <div class="self-center p-3">
  551. <input
  552. class=" w-full rounded-lg py-1.5 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  553. type="number"
  554. step="0.01"
  555. placeholder={$i18n.t('Enter Relevance Threshold')}
  556. bind:value={querySettings.r}
  557. autocomplete="off"
  558. min="0.0"
  559. />
  560. </div>
  561. </div>
  562. </div>
  563. {/if}
  564. <div>
  565. <div class=" mb-2.5 text-sm font-medium">{$i18n.t('RAG Template')}</div>
  566. <textarea
  567. bind:value={querySettings.template}
  568. class="w-full rounded-lg px-4 py-3 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none resize-none"
  569. rows="4"
  570. />
  571. </div>
  572. </div>
  573. <hr class=" dark:border-gray-700 my-3" />
  574. {#if showResetConfirm}
  575. <div class="flex justify-between rounded-md items-center py-2 px-3.5 w-full transition">
  576. <div class="flex items-center space-x-3">
  577. <svg
  578. xmlns="http://www.w3.org/2000/svg"
  579. viewBox="0 0 16 16"
  580. fill="currentColor"
  581. class="w-4 h-4"
  582. >
  583. <path d="M2 3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3Z" />
  584. <path
  585. fill-rule="evenodd"
  586. d="M13 6H3v6a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V6ZM5.72 7.47a.75.75 0 0 1 1.06 0L8 8.69l1.22-1.22a.75.75 0 1 1 1.06 1.06L9.06 9.75l1.22 1.22a.75.75 0 1 1-1.06 1.06L8 10.81l-1.22 1.22a.75.75 0 0 1-1.06-1.06l1.22-1.22-1.22-1.22a.75.75 0 0 1 0-1.06Z"
  587. clip-rule="evenodd"
  588. />
  589. </svg>
  590. <span>{$i18n.t('Are you sure?')}</span>
  591. </div>
  592. <div class="flex space-x-1.5 items-center">
  593. <button
  594. class="hover:text-white transition"
  595. on:click={() => {
  596. const res = resetVectorDB(localStorage.token).catch((error) => {
  597. toast.error(error);
  598. return null;
  599. });
  600. if (res) {
  601. toast.success($i18n.t('Success'));
  602. }
  603. showResetConfirm = false;
  604. }}
  605. >
  606. <svg
  607. xmlns="http://www.w3.org/2000/svg"
  608. viewBox="0 0 20 20"
  609. fill="currentColor"
  610. class="w-4 h-4"
  611. >
  612. <path
  613. fill-rule="evenodd"
  614. d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z"
  615. clip-rule="evenodd"
  616. />
  617. </svg>
  618. </button>
  619. <button
  620. class="hover:text-white transition"
  621. on:click={() => {
  622. showResetConfirm = false;
  623. }}
  624. >
  625. <svg
  626. xmlns="http://www.w3.org/2000/svg"
  627. viewBox="0 0 20 20"
  628. fill="currentColor"
  629. class="w-4 h-4"
  630. >
  631. <path
  632. d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
  633. />
  634. </svg>
  635. </button>
  636. </div>
  637. </div>
  638. {:else}
  639. <button
  640. class=" flex rounded-md py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
  641. on:click={() => {
  642. showResetConfirm = true;
  643. }}
  644. >
  645. <div class=" self-center mr-3">
  646. <svg
  647. xmlns="http://www.w3.org/2000/svg"
  648. viewBox="0 0 16 16"
  649. fill="currentColor"
  650. class="w-4 h-4"
  651. >
  652. <path
  653. fill-rule="evenodd"
  654. 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"
  655. clip-rule="evenodd"
  656. />
  657. </svg>
  658. </div>
  659. <div class=" self-center text-sm font-medium">{$i18n.t('Reset Vector Storage')}</div>
  660. </button>
  661. {/if}
  662. </div>
  663. </div>
  664. </div>
  665. <div class="flex justify-end pt-3 text-sm font-medium">
  666. <button
  667. class=" px-4 py-2 bg-emerald-700 hover:bg-emerald-800 text-gray-100 transition rounded-lg"
  668. type="submit"
  669. >
  670. {$i18n.t('Save')}
  671. </button>
  672. </div>
  673. </form>