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.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user