feat: add a per-file reindex action to knowledge bases

This commit is contained in:
silentoplayz 2026-08-04 06:57:50 -04:00
parent 8dbbc206c5
commit 287edf3b84
3 changed files with 39 additions and 1 deletions

View file

@ -893,6 +893,28 @@
}
};
let reindexingFileIds = [];
const reindexFileHandler = async (fileId: string) => {
if (reindexingFileIds.includes(fileId)) {
return;
}
reindexingFileIds = [...reindexingFileIds, fileId];
try {
const res = await updateFileFromKnowledgeById(localStorage.token, id, fileId);
if (res) {
toast.success($i18n.t('File reindexed.'));
getItemsPage();
}
} catch (e) {
toast.error(`${e}`);
} finally {
reindexingFileIds = reindexingFileIds.filter((reindexedId) => reindexedId !== fileId);
}
};
let debounceTimeout = null;
let mediaQuery;
@ -1591,6 +1613,8 @@
deleteFileHandler(fileId);
}}
onRename={(fileId, name) => renameFileHandler(fileId, name)}
onReindex={(fileId) => reindexFileHandler(fileId)}
{reindexingFileIds}
onNavigateDirectory={(dirId) => navigateToDirectory(dirId)}
onRenameDirectory={(id, name) => renameDirectoryHandler(id, name)}
onDeleteDirectory={(id) => confirmDeleteDirectory(id)}

View file

@ -18,6 +18,7 @@
import DropdownMenu from '$lib/components/common/DropdownMenu.svelte';
import DocumentPage from '$lib/components/icons/DocumentPage.svelte';
import EllipsisHorizontal from '$lib/components/icons/EllipsisHorizontal.svelte';
import ArrowPath from '$lib/components/icons/ArrowPath.svelte';
import Download from '$lib/components/icons/Download.svelte';
import GarbageBin from '$lib/components/icons/GarbageBin.svelte';
import Pencil from '$lib/components/icons/Pencil.svelte';
@ -28,10 +29,12 @@
export let selectedFileId = null;
export let files = [];
export let directories = [];
export let reindexingFileIds = [];
export let onClick = (fileId) => {};
export let onDelete = (fileId) => {};
export let onRename = (fileId: string, name: string) => {};
export let onReindex = (fileId: string) => {};
export let onNavigateDirectory = (directoryId: string) => {};
export let onRenameDirectory = (id: string, name: string) => {};
export let onDeleteDirectory = (id: string) => {};
@ -89,7 +92,7 @@
}}
>
<div class="flex items-center">
{#if file?.status !== 'uploading'}
{#if file?.status !== 'uploading' && !reindexingFileIds.includes(file?.id ?? file?.tempId)}
<button
class="p-1 rounded-full transition"
type="button"
@ -207,6 +210,16 @@
<Download className="size-3.5" />
{$i18n.t('Download')}
</button>
<button
type="button"
class="select-none flex h-[1.6875rem] w-full cursor-pointer items-center gap-2 rounded-xl bg-transparent px-2 text-xs transition hover:text-gray-900 dark:hover:text-gray-100"
on:click={() => {
onReindex(file?.id ?? file?.tempId);
}}
>
<ArrowPath className="size-3.5" />
{$i18n.t('Reindex')}
</button>
<button
type="button"
class="select-none flex h-[1.6875rem] w-full cursor-pointer items-center gap-2 rounded-xl bg-transparent px-2 text-xs transition hover:text-gray-900 dark:hover:text-gray-100"

View file

@ -1229,6 +1229,7 @@
"File moved.": "",
"File name": "",
"File not found.": "",
"File reindexed.": "",
"File removed successfully.": "",
"File renamed.": "",
"File size should not exceed {{maxSize}} MB.": "",