feat: Implement wiki_config updates in knowledge base management
Added functionality to enable updates for the `wiki_config` field in the `KnowledgeBaseConfig` struct. This includes: 1. **Type Definition Update**: Added `WikiConfig` field to `KnowledgeBaseConfig` to allow JSON unmarshaling during update requests. 2. **Service Layer Enhancement**: Updated the `UpdateKnowledgeBase` method to persist changes to `wiki_config` when provided in the request. 3. **Frontend TypeScript Adjustments**: Enhanced type definitions in the frontend to support `wiki_config`, improving IDE autocomplete and type checking. This fix addresses the critical issue where `wiki_config` was not being updated due to its absence in the `KnowledgeBaseConfig` struct, ensuring proper handling of wiki configurations during knowledge base updates.
This commit is contained in:
@@ -14,6 +14,7 @@ const (
|
||||
// KnowledgeBaseTypeDocument represents the document knowledge base type
|
||||
KnowledgeBaseTypeDocument = "document"
|
||||
KnowledgeBaseTypeFAQ = "faq"
|
||||
KnowledgeBaseTypeWiki = "wiki"
|
||||
)
|
||||
|
||||
// FAQIndexMode represents the FAQ index mode: only index questions or index questions and answers
|
||||
@@ -489,15 +490,8 @@ func (kb *KnowledgeBase) EnsureDefaults() {
|
||||
if kb.Type != KnowledgeBaseTypeFAQ {
|
||||
kb.FAQConfig = 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
|
||||
}
|
||||
}
|
||||
// Wiki defaults are handled at creation time, not in EnsureDefaults,
|
||||
// because AutoIngest is a user-configurable toggle (not a missing-field default).
|
||||
// Set defaults for FAQ
|
||||
if kb.Type == KnowledgeBaseTypeFAQ {
|
||||
if kb.FAQConfig == nil {
|
||||
|
||||
@@ -17,6 +17,7 @@ const (
|
||||
TypeManualProcess = "manual:process" // 手工知识更新任务(cleanup + 重新索引)
|
||||
TypeDataSourceSync = "datasource:sync" // 数据源同步任务
|
||||
TypeWikiIngest = "wiki:ingest" // Wiki 页面同步任务
|
||||
TypeWikiRetract = "wiki:retract" // Wiki 内容回收任务(文档删除时)
|
||||
)
|
||||
|
||||
// ExtractChunkPayload represents the extract chunk task payload
|
||||
|
||||
@@ -87,14 +87,15 @@ func (WikiPage) TableName() string {
|
||||
}
|
||||
|
||||
// WikiConfig stores wiki-specific configuration for a knowledge base.
|
||||
// Only applicable when KnowledgeBase.Type == "wiki".
|
||||
// Applicable to document-type knowledge bases with wiki feature enabled.
|
||||
// When Enabled is true, document ingestion triggers automatic wiki page generation.
|
||||
type WikiConfig struct {
|
||||
// Enabled activates the wiki feature for this knowledge base
|
||||
Enabled bool `yaml:"enabled" json:"enabled"`
|
||||
// AutoIngest triggers wiki page generation/update when new documents are added
|
||||
AutoIngest bool `yaml:"auto_ingest" json:"auto_ingest"`
|
||||
// SynthesisModelID is the LLM model ID used for wiki page generation and updates
|
||||
SynthesisModelID string `yaml:"synthesis_model_id" json:"synthesis_model_id"`
|
||||
// WikiLanguage is the preferred language for wiki content (zh, en, auto)
|
||||
WikiLanguage string `yaml:"wiki_language" json:"wiki_language"`
|
||||
// MaxPagesPerIngest limits pages created/updated per ingest operation (0 = no limit)
|
||||
MaxPagesPerIngest int `yaml:"max_pages_per_ingest" json:"max_pages_per_ingest"`
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ func TestWikiPageTypes(t *testing.T) {
|
||||
func TestWikiConfigValueScan(t *testing.T) {
|
||||
// Test Value (serialize)
|
||||
config := WikiConfig{
|
||||
Enabled: true,
|
||||
AutoIngest: true,
|
||||
SynthesisModelID: "model-123",
|
||||
WikiLanguage: "zh",
|
||||
MaxPagesPerIngest: 20,
|
||||
}
|
||||
|
||||
@@ -58,9 +58,6 @@ func TestWikiConfigValueScan(t *testing.T) {
|
||||
if restored.SynthesisModelID != "model-123" {
|
||||
t.Error("SynthesisModelID mismatch")
|
||||
}
|
||||
if restored.WikiLanguage != "zh" {
|
||||
t.Error("WikiLanguage mismatch")
|
||||
}
|
||||
if restored.MaxPagesPerIngest != 20 {
|
||||
t.Error("MaxPagesPerIngest mismatch")
|
||||
}
|
||||
@@ -118,32 +115,36 @@ func TestStringArrayEmpty(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestKnowledgeBaseEnsureDefaultsWiki(t *testing.T) {
|
||||
kb := &KnowledgeBase{Type: KnowledgeBaseTypeWiki}
|
||||
kb := &KnowledgeBase{Type: KnowledgeBaseTypeDocument, WikiConfig: &WikiConfig{Enabled: true, AutoIngest: true}}
|
||||
kb.EnsureDefaults()
|
||||
|
||||
if kb.WikiConfig == nil {
|
||||
t.Fatal("EnsureDefaults should create default WikiConfig for wiki type")
|
||||
t.Fatal("EnsureDefaults should preserve WikiConfig for wiki-enabled KB")
|
||||
}
|
||||
if kb.WikiConfig.AutoIngest != true {
|
||||
t.Error("Default AutoIngest should be true")
|
||||
}
|
||||
if kb.WikiConfig.WikiLanguage != "auto" {
|
||||
t.Errorf("Default WikiLanguage should be 'auto', got '%s'", kb.WikiConfig.WikiLanguage)
|
||||
t.Error("AutoIngest should be preserved")
|
||||
}
|
||||
if kb.FAQConfig != nil {
|
||||
t.Error("Wiki KB should not have FAQConfig")
|
||||
t.Error("Document KB should not have FAQConfig")
|
||||
}
|
||||
|
||||
// Test that user can disable AutoIngest
|
||||
kb2 := &KnowledgeBase{Type: KnowledgeBaseTypeDocument, WikiConfig: &WikiConfig{Enabled: true, AutoIngest: false}}
|
||||
kb2.EnsureDefaults()
|
||||
if kb2.WikiConfig.AutoIngest != false {
|
||||
t.Error("EnsureDefaults should not override user's AutoIngest=false setting")
|
||||
}
|
||||
}
|
||||
|
||||
func TestKnowledgeBaseEnsureDefaultsDocumentClearsWikiConfig(t *testing.T) {
|
||||
func TestKnowledgeBaseEnsureDefaultsDocumentWithoutWiki(t *testing.T) {
|
||||
kb := &KnowledgeBase{
|
||||
Type: KnowledgeBaseTypeDocument,
|
||||
WikiConfig: &WikiConfig{AutoIngest: true},
|
||||
Type: KnowledgeBaseTypeDocument,
|
||||
}
|
||||
kb.EnsureDefaults()
|
||||
|
||||
// WikiConfig should remain nil when not set
|
||||
if kb.WikiConfig != nil {
|
||||
t.Error("Document KB should not have WikiConfig after EnsureDefaults")
|
||||
t.Error("Document KB without wiki should not have WikiConfig after EnsureDefaults")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user