feat: Refactor knowledge base service and router for improved wiki handling
- Updated the knowledge base service to ensure WikiConfig is created when wiki indexing is enabled, enhancing backward compatibility. - Removed legacy syncing of WikiConfig.Enabled to IndexingStrategy.WikiEnabled, streamlining the logic for wiki enablement. - Introduced a custom retry delay function for asynq tasks to handle wiki ingest lock conflicts more effectively, improving task management. - Cleaned up the container file by removing unnecessary whitespace, contributing to better code readability.
This commit is contained in:
@@ -89,10 +89,6 @@ type KnowledgeService interface {
|
||||
) (*types.Knowledge, error)
|
||||
// ReparseKnowledge deletes existing document content and re-parses the knowledge asynchronously.
|
||||
ReparseKnowledge(ctx context.Context, knowledgeID string) (*types.Knowledge, error)
|
||||
// RebuildKnowledgeBaseIndex re-processes all documents in a knowledge base.
|
||||
// Used when the indexing strategy changes and existing documents need to be re-indexed.
|
||||
// Returns the number of documents enqueued for re-processing.
|
||||
RebuildKnowledgeBaseIndex(ctx context.Context, kbID string) (int, error)
|
||||
// CloneKnowledgeBase clones knowledge to another knowledge base.
|
||||
CloneKnowledgeBase(ctx context.Context, srcID, dstID string) error
|
||||
// UpdateImageInfo updates image information for a knowledge chunk.
|
||||
|
||||
@@ -496,8 +496,6 @@ func (kb *KnowledgeBase) EnsureDefaults() {
|
||||
if kb.Type != KnowledgeBaseTypeFAQ {
|
||||
kb.FAQConfig = nil
|
||||
}
|
||||
// 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 {
|
||||
@@ -522,10 +520,6 @@ func (kb *KnowledgeBase) EnsureDefaults() {
|
||||
if kb.IndexingStrategy.IsZero() {
|
||||
kb.IndexingStrategy = DefaultIndexingStrategy()
|
||||
}
|
||||
// Sync legacy WikiConfig.Enabled → IndexingStrategy.WikiEnabled
|
||||
if kb.WikiConfig != nil && kb.WikiConfig.Enabled && !kb.IndexingStrategy.WikiEnabled {
|
||||
kb.IndexingStrategy.WikiEnabled = true
|
||||
}
|
||||
// Sync legacy ExtractConfig.Enabled → IndexingStrategy.GraphEnabled
|
||||
if kb.ExtractConfig != nil && kb.ExtractConfig.Enabled && !kb.IndexingStrategy.GraphEnabled {
|
||||
kb.IndexingStrategy.GraphEnabled = true
|
||||
@@ -580,17 +574,12 @@ func (kb *KnowledgeBase) MarshalJSON() ([]byte, error) {
|
||||
}
|
||||
|
||||
// IsWikiEnabled checks if the wiki feature is enabled for this knowledge base.
|
||||
// Wiki requires both IndexingStrategy.WikiEnabled and WikiConfig with Enabled=true.
|
||||
// Wiki enablement is the single source of truth on IndexingStrategy.WikiEnabled.
|
||||
func (kb *KnowledgeBase) IsWikiEnabled() bool {
|
||||
if kb == nil {
|
||||
return false
|
||||
}
|
||||
// Primary: check IndexingStrategy (canonical source after migration)
|
||||
if kb.IndexingStrategy.WikiEnabled {
|
||||
return kb.WikiConfig != nil && kb.WikiConfig.Enabled
|
||||
}
|
||||
// Legacy fallback: direct WikiConfig check
|
||||
return kb.WikiConfig != nil && kb.WikiConfig.Enabled
|
||||
return kb.IndexingStrategy.WikiEnabled
|
||||
}
|
||||
|
||||
// IsVectorEnabled checks if vector (semantic) search is enabled.
|
||||
|
||||
Reference in New Issue
Block a user