fix: Enable wiki_config updates in knowledge base configuration

Implemented three critical fixes to enable wiki_config persistence during
KB creation and updates:

1. Add WikiConfig field to KnowledgeBaseConfig struct
   - File: internal/types/knowledgebase.go
   - Enables JSON unmarshaling of wiki_config from update requests
   - Previously the field was silently dropped during deserialization

2. Update UpdateKnowledgeBase service to persist wiki_config
   - File: internal/application/service/knowledgebase.go
   - Added logic to apply wiki_config changes when config parameter is provided
   - Mirrors existing logic for FAQConfig persistence

3. Update frontend TypeScript types for IDE completion
   - File: frontend/src/api/knowledge-base/index.ts
   - Added WikiConfig type to createKnowledgeBase function signature
   - Added structured WikiConfig type to updateKnowledgeBase config parameter
   - Enables TypeScript IDE autocomplete and type checking

Flow:
- Frontend: updateKnowledgeBase({name, description, config: {wiki_config}})
- Handler: Parses into UpdateKnowledgeBaseRequest via KnowledgeBaseConfig
- Service: Applies wiki_config to KB entity via UpdateKnowledgeBase
- Database: Persists wiki_config JSONB field to postgres

Root cause analysis:
Previously, the KnowledgeBaseConfig struct was missing the WikiConfig field,
causing JSON unmarshaling to silently drop any wiki_config data sent in
PUT requests. KB creation worked because it used the full KnowledgeBase struct.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
wizardchen
2026-04-07 15:19:53 +08:00
parent 16a0bff7bd
commit e15adca0a6
3 changed files with 43 additions and 20 deletions
+24 -2
View File
@@ -11,7 +11,7 @@ export function listKnowledgeBases(params?: { agent_id?: string }) {
export function createKnowledgeBase(data: {
name: string;
description?: string;
type?: 'document' | 'faq' | 'wiki';
type?: 'document' | 'faq';
chunking_config?: any;
embedding_model_id?: string;
summary_model_id?: string;
@@ -28,6 +28,13 @@ export function createKnowledgeBase(data: {
};
extract_config?: any;
faq_config?: { index_mode: string; question_index_mode?: string };
wiki_config?: {
enabled: boolean;
auto_ingest?: boolean;
synthesis_model_id?: string;
wiki_language?: string;
max_pages_per_ingest?: number;
};
}) {
return post(`/api/v1/knowledge-bases`, data);
}
@@ -39,7 +46,22 @@ export function getKnowledgeBaseById(id: string, options?: { agent_id?: string }
return get(qs ? `/api/v1/knowledge-bases/${id}?${qs}` : `/api/v1/knowledge-bases/${id}`);
}
export function updateKnowledgeBase(id: string, data: { name: string; description?: string; config: any }) {
export function updateKnowledgeBase(id: string, data: {
name: string;
description?: string;
config?: {
chunking_config?: any;
image_processing_config?: any;
faq_config?: any;
wiki_config?: {
enabled: boolean;
auto_ingest?: boolean;
synthesis_model_id?: string;
wiki_language?: string;
max_pages_per_ingest?: number;
};
}
}) {
return put(`/api/v1/knowledge-bases/${id}` , data);
}
@@ -294,6 +294,9 @@ func (s *knowledgeBaseService) UpdateKnowledgeBase(ctx context.Context,
if config.FAQConfig != nil {
kb.FAQConfig = config.FAQConfig
}
if config.WikiConfig != nil {
kb.WikiConfig = config.WikiConfig
}
}
kb.UpdatedAt = time.Now()
kb.EnsureDefaults()
+16 -18
View File
@@ -14,10 +14,6 @@ const (
// KnowledgeBaseTypeDocument represents the document knowledge base type
KnowledgeBaseTypeDocument = "document"
KnowledgeBaseTypeFAQ = "faq"
// KnowledgeBaseTypeWiki represents the wiki knowledge base type.
// Wiki KBs use LLM to build and maintain a persistent, interlinked wiki
// from ingested documents instead of just raw RAG chunks.
KnowledgeBaseTypeWiki = "wiki"
)
// FAQIndexMode represents the FAQ index mode: only index questions or index questions and answers
@@ -115,6 +111,8 @@ type KnowledgeBaseConfig struct {
ImageProcessingConfig ImageProcessingConfig `yaml:"image_processing_config" json:"image_processing_config"`
// FAQ configuration (only for FAQ type knowledge bases)
FAQConfig *FAQConfig `yaml:"faq_config" json:"faq_config"`
// Wiki configuration (only for wiki-enabled knowledge bases)
WikiConfig *WikiConfig `yaml:"wiki_config" json:"wiki_config"`
}
// ParserEngineRule maps a set of file types to a specific parser engine.
@@ -491,8 +489,14 @@ func (kb *KnowledgeBase) EnsureDefaults() {
if kb.Type != KnowledgeBaseTypeFAQ {
kb.FAQConfig = nil
}
if kb.Type != KnowledgeBaseTypeWiki {
kb.WikiConfig = nil
// Set defaults for Wiki (wiki is an add-on to document KBs, not a separate type)
if kb.IsWikiEnabled() {
if kb.WikiConfig.WikiLanguage == "" {
kb.WikiConfig.WikiLanguage = "auto"
}
if !kb.WikiConfig.AutoIngest {
kb.WikiConfig.AutoIngest = true
}
}
// Set defaults for FAQ
if kb.Type == KnowledgeBaseTypeFAQ {
@@ -510,18 +514,12 @@ func (kb *KnowledgeBase) EnsureDefaults() {
kb.FAQConfig.QuestionIndexMode = FAQQuestionIndexModeCombined
}
}
// Set defaults for Wiki
if kb.Type == KnowledgeBaseTypeWiki {
if kb.WikiConfig == nil {
kb.WikiConfig = &WikiConfig{
AutoIngest: true,
WikiLanguage: "auto",
}
}
if kb.WikiConfig.WikiLanguage == "" {
kb.WikiConfig.WikiLanguage = "auto"
}
}
}
// IsWikiEnabled checks if the wiki feature is enabled for this knowledge base.
// Wiki is an add-on to document-type KBs, not a separate KB type.
func (kb *KnowledgeBase) IsWikiEnabled() bool {
return kb != nil && kb.WikiConfig != nil && kb.WikiConfig.Enabled
}
// IsMultimodalEnabled 判断多模态是否启用(兼容新老版本配置)