feat: Add comprehensive documentation for WeKnora knowledge base and wiki features

- Introduced multiple new documentation files, including a complete documentation index, quick reference guides, and comprehensive analyses of the knowledge base and wiki settings.
- The new files provide detailed insights into the architecture, data models, API endpoints, and implementation strategies for the knowledge base and wiki functionalities.
- Enhanced navigation and usability for developers and team members by summarizing key components, configurations, and data flows related to the knowledge base system.

These additions significantly improve the clarity and accessibility of documentation, supporting better onboarding and reference for current and future team members.
This commit is contained in:
wizardchen
2026-04-20 19:16:46 +08:00
parent 53ecd5df5d
commit 28deb8282f
51 changed files with 13027 additions and 271 deletions
+4
View File
@@ -37,6 +37,10 @@ type AgentConfig struct {
// Whether to retrieve knowledge base only when explicitly mentioned with @ (default: false)
RetrieveKBOnlyWhenMentioned bool `json:"retrieve_kb_only_when_mentioned"`
// RetrievalPreference controls which retrieval tools the agent uses:
// "auto" (default), "vector_only", "wiki_only", "hybrid"
RetrievalPreference string `json:"retrieval_preference"`
// Whether to retain retrieval history (like wiki_read_page results) across turns (default: false)
RetainRetrievalHistory bool `json:"retain_retrieval_history"`
+10
View File
@@ -119,6 +119,13 @@ type CustomAgentConfig struct {
// When false, knowledge base retrieval happens according to KBSelectionMode
RetrieveKBOnlyWhenMentioned bool `yaml:"retrieve_kb_only_when_mentioned" json:"retrieve_kb_only_when_mentioned"`
// RetrievalPreference controls which retrieval tools the agent uses:
// "auto" - auto-detect from KB capabilities (default, preserves existing behavior)
// "vector_only" - only use vector/keyword search tools, no wiki tools
// "wiki_only" - only use wiki tools, no vector/keyword search tools
// "hybrid" - use both vector/keyword search AND wiki tools
RetrievalPreference string `yaml:"retrieval_preference" json:"retrieval_preference"`
// Whether to retain retrieval history across turns
RetainRetrievalHistory bool `yaml:"retain_retrieval_history" json:"retain_retrieval_history"`
@@ -262,6 +269,9 @@ func (a *CustomAgent) EnsureDefaults() {
if a.Config.FallbackStrategy == "" {
a.Config.FallbackStrategy = "model"
}
if a.Config.RetrievalPreference == "" {
a.Config.RetrievalPreference = "auto"
}
if a.Config.MaxCompletionTokens == 0 {
a.Config.MaxCompletionTokens = 2048
}
+77
View File
@@ -0,0 +1,77 @@
package types
import (
"database/sql/driver"
"encoding/json"
)
// IndexingStrategy controls which indexing pipelines are active for a knowledge base.
// Each boolean flag independently enables/disables a processing pipeline.
// When a document is uploaded, only the enabled pipelines will run.
type IndexingStrategy struct {
// VectorEnabled enables semantic vector embedding and search
VectorEnabled bool `yaml:"vector_enabled" json:"vector_enabled"`
// KeywordEnabled enables keyword-based (BM25) search
KeywordEnabled bool `yaml:"keyword_enabled" json:"keyword_enabled"`
// WikiEnabled enables automatic wiki page generation from documents
WikiEnabled bool `yaml:"wiki_enabled" json:"wiki_enabled"`
// GraphEnabled enables knowledge graph entity/relation extraction
GraphEnabled bool `yaml:"graph_enabled" json:"graph_enabled"`
}
// DefaultIndexingStrategy returns the default strategy matching the legacy behavior:
// vector and keyword indexing enabled, wiki and graph disabled.
func DefaultIndexingStrategy() IndexingStrategy {
return IndexingStrategy{
VectorEnabled: true,
KeywordEnabled: true,
WikiEnabled: false,
GraphEnabled: false,
}
}
// NeedsEmbedding returns true if any pipeline that requires an embedding model is enabled.
func (s IndexingStrategy) NeedsEmbedding() bool {
return s.VectorEnabled || s.KeywordEnabled
}
// NeedsChunks returns true if any pipeline that requires document chunks is enabled.
// Chunks are needed for vector indexing, keyword indexing, wiki generation, and graph extraction.
func (s IndexingStrategy) NeedsChunks() bool {
return s.VectorEnabled || s.KeywordEnabled || s.WikiEnabled || s.GraphEnabled
}
// HasAnyIndexing returns true if at least one indexing pipeline is enabled.
func (s IndexingStrategy) HasAnyIndexing() bool {
return s.VectorEnabled || s.KeywordEnabled || s.WikiEnabled || s.GraphEnabled
}
// IsZero returns true if the strategy has no pipelines enabled (zero value).
func (s IndexingStrategy) IsZero() bool {
return !s.VectorEnabled && !s.KeywordEnabled && !s.WikiEnabled && !s.GraphEnabled
}
// Value implements the driver.Valuer interface for GORM serialization.
func (s IndexingStrategy) Value() (driver.Value, error) {
return json.Marshal(s)
}
// Scan implements the sql.Scanner interface for GORM deserialization.
// When the database column is NULL (existing rows before migration),
// it returns DefaultIndexingStrategy() for backward compatibility.
func (s *IndexingStrategy) Scan(value interface{}) error {
if value == nil {
*s = DefaultIndexingStrategy()
return nil
}
b, ok := value.([]byte)
if !ok {
*s = DefaultIndexingStrategy()
return nil
}
if err := json.Unmarshal(b, s); err != nil {
*s = DefaultIndexingStrategy()
return nil
}
return nil
}
+4
View File
@@ -89,6 +89,10 @@ 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.
+55 -2
View File
@@ -82,6 +82,9 @@ type KnowledgeBase struct {
QuestionGenerationConfig *QuestionGenerationConfig `yaml:"question_generation_config" json:"question_generation_config" gorm:"column:question_generation_config;type:json"`
// WikiConfig stores wiki-specific configuration (only for wiki type knowledge bases)
WikiConfig *WikiConfig `yaml:"wiki_config" json:"wiki_config" gorm:"column:wiki_config;type:json"`
// IndexingStrategy controls which indexing pipelines are active for this knowledge base.
// Pipelines: vector search, keyword search, wiki generation, knowledge graph extraction.
IndexingStrategy IndexingStrategy `yaml:"indexing_strategy" json:"indexing_strategy" gorm:"column:indexing_strategy;type:json"`
// Whether this knowledge base is pinned to the top of the list
IsPinned bool `yaml:"is_pinned" json:"is_pinned" gorm:"default:false"`
// Time when the knowledge base was pinned (nil if not pinned)
@@ -114,6 +117,9 @@ type KnowledgeBaseConfig struct {
FAQConfig *FAQConfig `yaml:"faq_config" json:"faq_config"`
// Wiki configuration (only for wiki-enabled knowledge bases)
WikiConfig *WikiConfig `yaml:"wiki_config" json:"wiki_config"`
// IndexingStrategy controls which indexing pipelines are active.
// nil means "no change" when updating (preserves existing strategy).
IndexingStrategy *IndexingStrategy `yaml:"indexing_strategy" json:"indexing_strategy"`
}
// ParserEngineRule maps a set of file types to a specific parser engine.
@@ -508,12 +514,59 @@ func (kb *KnowledgeBase) EnsureDefaults() {
kb.FAQConfig.QuestionIndexMode = FAQQuestionIndexModeCombined
}
}
// Ensure IndexingStrategy has defaults.
// For existing rows where indexing_strategy is NULL, GORM Scan() returns
// DefaultIndexingStrategy() (vector+keyword=true). This block handles the
// case where a fresh struct was created in-memory without touching DB.
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
}
}
// 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.
// Wiki requires both IndexingStrategy.WikiEnabled and WikiConfig with Enabled=true.
func (kb *KnowledgeBase) IsWikiEnabled() bool {
return kb != nil && kb.WikiConfig != nil && kb.WikiConfig.Enabled
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
}
// IsVectorEnabled checks if vector (semantic) search is enabled.
func (kb *KnowledgeBase) IsVectorEnabled() bool {
return kb != nil && kb.IndexingStrategy.VectorEnabled
}
// IsKeywordEnabled checks if keyword (BM25) search is enabled.
func (kb *KnowledgeBase) IsKeywordEnabled() bool {
return kb != nil && kb.IndexingStrategy.KeywordEnabled
}
// IsGraphEnabled checks if knowledge graph extraction is enabled.
// Requires both the IndexingStrategy flag and a valid ExtractConfig.
func (kb *KnowledgeBase) IsGraphEnabled() bool {
return kb != nil && kb.IndexingStrategy.GraphEnabled &&
kb.ExtractConfig != nil && kb.ExtractConfig.Enabled
}
// NeedsEmbeddingModel returns true if any enabled pipeline requires an embedding model.
// Currently only vector and keyword search need embeddings.
func (kb *KnowledgeBase) NeedsEmbeddingModel() bool {
return kb != nil && kb.IndexingStrategy.NeedsEmbedding()
}
// IsMultimodalEnabled 判断多模态是否启用(兼容新老版本配置)