Skip to content

Project NOMAD is an offline-first knowledge and education server. Wikipedia, thousands of books, courses, maps, and optional local AI, all running on hardware you own with no internet required.

TypeScript

fix(kb): guard ZIM delete purge and dedupe reconcile's delete pair

John Cortright7e24c7aeb8c4
diff --git a/admin/app/services/rag_service.ts b/admin/app/services/rag_service.ts
index 939b2e18..1956ea69 100644
--- a/admin/app/services/rag_service.ts
+++ b/admin/app/services/rag_service.ts
@@ -1978,8 +1978,7 @@ export class RagService {
// Order matters: remove the stale points and state row BEFORE queueing the
// new embed so a fresh index can't be conflated with the old one. Each step
// targets only `oldFilePath` / `newFilePath` — never another resource.
- await this._deletePointsBySource(oldFilePath)
- await KbIngestState.remove(oldFilePath)
+ await this.purgeIndexedSource(oldFilePath)
const { EmbedFileJob } = await import('#jobs/embed_file_job')
await EmbedFileJob.dispatch({ fileName, filePath: newFilePath })
}
diff --git a/admin/app/services/zim_service.ts b/admin/app/services/zim_service.ts
index e7ac6c00..d67d8edd 100644
--- a/admin/app/services/zim_service.ts
+++ b/admin/app/services/zim_service.ts
@@ -752,11 +752,18 @@ export class ZimService {
// 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)
+ //
+ // Guarded on the AI Assistant being installed at all — otherwise every
+ // delete on an install without it hits _initializeQdrantClient()'s
+ // "offline" throw and logs a misleading error for the common no-AI case.
+ const qdrantInstalled = !!(await this.dockerService.getServiceURL(SERVICE_NAMES.QDRANT))
+ if (qdrantInstalled) {
+ 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