From 8eb172e68483ee06aa12433bcb6b098eb1cf285a Mon Sep 17 00:00:00 2001 From: John Cortright Date: Mon, 10 Aug 2026 23:04:58 -0700 Subject: [PATCH] fix(kb): purge qdrant points when a zim is deleted (#1170) delete() removed the file, the kiwix library entry, and the InstalledResource row, but never touched Qdrant or KbIngestState. A deleted ZIM kept surfacing as a search citation indefinitely. The sync sweep added in the previous commit would eventually catch these too, but no reason to wait for the next sync when we already know exactly what needs cleaning up right here. --- admin/app/services/zim_service.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/admin/app/services/zim_service.ts b/admin/app/services/zim_service.ts index 4cec723f..e7ac6c00 100644 --- a/admin/app/services/zim_service.ts +++ b/admin/app/services/zim_service.ts @@ -34,6 +34,8 @@ import { SERVICE_NAMES } from '../../constants/service_names.js' import { CollectionManifestService } from './collection_manifest_service.js' import { KiwixCatalogService } from './kiwix_catalog_service.js' import { KiwixLibraryService } from './kiwix_library_service.js' +import { RagService } from './rag_service.js' +import { OllamaService } from './ollama_service.js' import type { CategoryWithStatus } from '../../types/collections.js' import CustomLibrarySource from '#models/custom_library_source' import { assertNotPrivateUrl } from '#validators/common' @@ -745,6 +747,18 @@ export class ZimService { await deleteFileIfExists(fullPath) + // Purge this file's Qdrant points and KbIngestState row directly so a + // deleted ZIM stops surfacing as a stale search citation immediately, + // rather than waiting for the next scanAndSyncStorage reverse sweep to + // catch it (#1170). Never touched Qdrant here before — the file's points + // and state row would otherwise linger indefinitely. + try { + const ragService = new RagService(this.dockerService, new OllamaService()) + await ragService.purgeIndexedSource(fullPath) + } catch (err) { + logger.error(`[ZimService] Failed to purge knowledge-base entries for ${fullPath}:`, err) + } + // Remove from kiwix library XML so --monitorLibrary stops serving the deleted file const kiwixLibraryService = new KiwixLibraryService() await kiwixLibraryService.removeBook(fileName).catch((err) => {