Documents.svelte 27 KB

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