From 586d5fda5888e5a01440fa0344f520e1a4cf6354 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Tue, 21 Apr 2026 20:24:20 +0800 Subject: [PATCH] feat: Implement conditional indexing for multimodal chunks based on embedding model availability - Added a check to skip vector and keyword indexing for knowledge bases that do not require an embedding model, preventing errors during the indexing process. - Ensured that chunks are marked as indexed even when skipping the indexing step, maintaining a consistent state for downstream processes. - Enhanced logging to provide clear information on the indexing status and any issues encountered while updating chunk statuses. These changes improve the robustness of the indexing process in the ImageMultimodalService, ensuring better handling of knowledge bases without embedding capabilities. --- .../application/service/image_multimodal.go | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/internal/application/service/image_multimodal.go b/internal/application/service/image_multimodal.go index 0d1c83d7..8adc66d2 100644 --- a/internal/application/service/image_multimodal.go +++ b/internal/application/service/image_multimodal.go @@ -254,6 +254,28 @@ func (s *ImageMultimodalService) indexChunks(ctx context.Context, payload types. return } + // Skip vector/keyword indexing when the KB has no embedding-based pipeline enabled + // (e.g. Wiki-only KBs). Without this check, GetEmbeddingModel would fail because + // EmbeddingModelID is intentionally empty for such KBs. The multimodal chunks + // themselves are already persisted in the DB above, so skipping index here is safe. + if !kb.NeedsEmbeddingModel() { + logger.Infof(ctx, "[ImageMultimodal] Vector/keyword indexing disabled for KB %s, skipping index for %d multimodal chunks", + kb.ID, len(chunks)) + // Still mark chunks as indexed so downstream finalization sees a consistent state. + for _, chunk := range chunks { + dbChunk, gerr := s.chunkService.GetChunkByIDOnly(ctx, chunk.ID) + if gerr != nil { + logger.Warnf(ctx, "[ImageMultimodal] Failed to fetch chunk %s for status update: %v", chunk.ID, gerr) + continue + } + dbChunk.Status = int(types.ChunkStatusIndexed) + if uerr := s.chunkService.UpdateChunk(ctx, dbChunk); uerr != nil { + logger.Warnf(ctx, "[ImageMultimodal] Failed to update chunk %s status to indexed: %v", chunk.ID, uerr) + } + } + return + } + embeddingModel, err := s.modelService.GetEmbeddingModel(ctx, kb.EmbeddingModelID) if err != nil { logger.Warnf(ctx, "[ImageMultimodal] Failed to get embedding model for indexing: %v", err)