From eafa0cd80b3f5b548c6c288dd7139978f2f84ec4 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Wed, 3 Dec 2025 13:27:00 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E5=A4=9A?= =?UTF-8?q?=E6=A8=A1=E6=80=81=E9=85=8D=E7=BD=AE=E6=A3=80=E6=9F=A5=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E7=BB=9F=E4=B8=80=E4=BD=BF=E7=94=A8IsMultimo?= =?UTF-8?q?dalEnabled=E6=96=B9=E6=B3=95=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/application/service/knowledge.go | 18 ++++-------------- internal/types/knowledgebase.go | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/internal/application/service/knowledge.go b/internal/application/service/knowledge.go index e52d8c49..6a22e2a3 100644 --- a/internal/application/service/knowledge.go +++ b/internal/application/service/knowledge.go @@ -279,7 +279,7 @@ func (s *knowledgeService) CreateKnowledgeFromFile(ctx context.Context, if enableMultimodel != nil { enableMultimodelValue = *enableMultimodel } else { - enableMultimodelValue = kb.VLMConfig.IsEnabled() + enableMultimodelValue = kb.IsMultimodalEnabled() } // Check question generation config @@ -413,7 +413,7 @@ func (s *knowledgeService) CreateKnowledgeFromURL(ctx context.Context, if enableMultimodel != nil { enableMultimodelValue = *enableMultimodel } else { - enableMultimodelValue = kb.VLMConfig.IsEnabled() + enableMultimodelValue = kb.IsMultimodalEnabled() } // Check question generation config @@ -4155,7 +4155,7 @@ func (s *knowledgeService) triggerManualProcessing(ctx context.Context, fileType := "md" // 检查是否需要启用多模态(对于手动内容通常不需要,但保持一致性) - enableMultimodel := kb.VLMConfig.IsEnabled() && kb.StorageConfig.Provider != "" + enableMultimodel := kb.IsMultimodalEnabled() && kb.StorageConfig.Provider != "" var vlmConfig *proto.VLMConfig if enableMultimodel { @@ -4411,20 +4411,10 @@ func (s *knowledgeService) ProcessDocument(ctx context.Context, t *asynq.Task) e if err != nil { logger.GetLogger(ctx).WithField("knowledge_id", knowledge.ID). WithField("error", err).Errorf("processDocument build VLM config failed") - knowledge.ParseStatus = "failed" - knowledge.ErrorMessage = err.Error() - knowledge.UpdatedAt = time.Now() - s.repo.UpdateKnowledge(ctx, knowledge) - return nil } if vlmConfig == nil { logger.GetLogger(ctx).WithField("knowledge_id", knowledge.ID). - Error("processDocument enable multimodal but VLM config missing") - knowledge.ParseStatus = "failed" - knowledge.ErrorMessage = "VLM 配置缺失" - knowledge.UpdatedAt = time.Now() - s.repo.UpdateKnowledge(ctx, knowledge) - return nil + Warn("processDocument enable multimodal but VLM config missing") } } diff --git a/internal/types/knowledgebase.go b/internal/types/knowledgebase.go index 02cd9043..c9f25592 100644 --- a/internal/types/knowledgebase.go +++ b/internal/types/knowledgebase.go @@ -101,6 +101,8 @@ type ChunkingConfig struct { ChunkOverlap int `yaml:"chunk_overlap" json:"chunk_overlap"` // Separators Separators []string `yaml:"separators" json:"separators"` + // EnableMultimodal (deprecated, kept for backward compatibility with old data) + EnableMultimodal bool `yaml:"enable_multimodal,omitempty" json:"enable_multimodal,omitempty"` } // COSConfig represents the COS configuration @@ -325,3 +327,21 @@ func (kb *KnowledgeBase) EnsureDefaults() { kb.FAQConfig.QuestionIndexMode = FAQQuestionIndexModeCombined } } + +// IsMultimodalEnabled 判断多模态是否启用(兼容新老版本配置) +// 新版本:VLMConfig.IsEnabled() +// 老版本:ChunkingConfig.EnableMultimodal +func (kb *KnowledgeBase) IsMultimodalEnabled() bool { + if kb == nil { + return false + } + // 新版本配置优先 + if kb.VLMConfig.IsEnabled() { + return true + } + // 兼容老版本:chunking_config 中的 enable_multimodal 字段 + if kb.ChunkingConfig.EnableMultimodal { + return true + } + return false +}