e147209e77
This commit introduces the complete wiki feature for WeKnora, enabling AI-powered wiki page generation and management. The implementation includes: **Backend Changes:** - Wiki data model: WikiPage type with support for multiple page types (Summary, Entity, Concept, Index, Log) - Database schema: wiki_pages table with full migration support - WikiPageService: CRUD operations and page management - WikiPageRepository: GORM-based persistence layer - Wiki ingest pipeline: Automated generation of wiki pages from knowledge documents * Summary page generation using LLM * Entity and concept extraction in a single LLM call * Synthesis opportunity detection * Index page rebuilding * Log page maintenance - Wiki boost feature: Enhance chat retrieval with wiki context - Wiki linting: Maintenance and validation utilities - Agent wiki tools: Enable agents to query and interact with wiki pages - Wiki prompts: Comprehensive LLM prompt templates for all wiki generation tasks - Language support: Reuse existing middleware language infrastructure for LLM prompts **Frontend Changes:** - Wiki browser UI: View all wiki pages with filtering and search - Wiki API client: Knowledge base wiki management endpoints - Knowledge base editor: Configure wiki settings (language, auto-ingest, synthesis model) - i18n updates: Support for English, Korean, Russian, and Chinese interfaces **Configuration:** - Container DI: Wire up all wiki services - Router: Register wiki API endpoints - Task handling: Support async wiki ingest tasks **Testing:** - Unit tests for wiki page types - Service layer tests - Endpoint tests for wiki operations - Integration tests with LLM mocking **Documentation:** - Language refactoring analysis and guides - Implementation completion reports - Quick reference guides for developers **Key Features:** ✅ LLM-powered wiki page generation from documents ✅ Multi-language support (9+ languages) ✅ Automatic extraction of entities and concepts ✅ Synthesis opportunity detection ✅ Index and log page maintenance ✅ Progressive wiki building across multiple documents ✅ Agent-based wiki interaction ✅ Chat retrieval enhancement with wiki context ✅ Full frontend UI for wiki browsing Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
90 lines
2.7 KiB
Go
90 lines
2.7 KiB
Go
package chatpipeline
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/Tencent/WeKnora/internal/logger"
|
|
"github.com/Tencent/WeKnora/internal/types"
|
|
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
|
)
|
|
|
|
// wikiBoostFactor is the score multiplier applied to wiki page chunks.
|
|
// Wiki pages contain LLM-synthesized, cross-referenced knowledge and should
|
|
// be preferred over raw document chunks when both are available.
|
|
const wikiBoostFactor = 1.3
|
|
|
|
// PluginWikiBoost boosts the relevance score of wiki page chunks in search results.
|
|
// Wiki pages contain pre-synthesized knowledge that is more coherent and
|
|
// cross-referenced than raw document chunks, so they should rank higher.
|
|
//
|
|
// This plugin runs in the CHUNK_RERANK phase, after initial retrieval and reranking.
|
|
// It identifies chunks with ChunkType == "wiki_page" and multiplies their score.
|
|
type PluginWikiBoost struct {
|
|
kbService interfaces.KnowledgeBaseService
|
|
}
|
|
|
|
// NewPluginWikiBoost creates and registers the wiki boost plugin
|
|
func NewPluginWikiBoost(eventManager *EventManager, kbService interfaces.KnowledgeBaseService) *PluginWikiBoost {
|
|
p := &PluginWikiBoost{
|
|
kbService: kbService,
|
|
}
|
|
eventManager.Register(p)
|
|
return p
|
|
}
|
|
|
|
// ActivationEvents returns the event types this plugin handles
|
|
func (p *PluginWikiBoost) ActivationEvents() []types.EventType {
|
|
return []types.EventType{types.CHUNK_RERANK}
|
|
}
|
|
|
|
// OnEvent boosts wiki page chunk scores after reranking
|
|
func (p *PluginWikiBoost) OnEvent(
|
|
ctx context.Context,
|
|
eventType types.EventType,
|
|
chatManage *types.ChatManage,
|
|
next func() *PluginError,
|
|
) *PluginError {
|
|
// Run the normal reranking first
|
|
if err := next(); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Check if any search target is a wiki KB
|
|
hasWikiKB := false
|
|
for _, target := range chatManage.SearchTargets {
|
|
kb, err := p.kbService.GetKnowledgeBaseByIDOnly(ctx, target.KnowledgeBaseID)
|
|
if err == nil && kb.Type == types.KnowledgeBaseTypeWiki {
|
|
hasWikiKB = true
|
|
break
|
|
}
|
|
}
|
|
|
|
if !hasWikiKB {
|
|
return nil
|
|
}
|
|
|
|
// Boost wiki page chunks in RerankResult
|
|
boostedCount := 0
|
|
for i := range chatManage.RerankResult {
|
|
if chatManage.RerankResult[i].ChunkType == types.ChunkTypeWikiPage {
|
|
chatManage.RerankResult[i].Score *= wikiBoostFactor
|
|
boostedCount++
|
|
}
|
|
}
|
|
|
|
if boostedCount > 0 {
|
|
logger.Infof(ctx, "WikiBoost: boosted %d wiki page chunks by %.1fx", boostedCount, wikiBoostFactor)
|
|
|
|
// Re-sort by score after boosting
|
|
for i := 0; i < len(chatManage.RerankResult); i++ {
|
|
for j := i + 1; j < len(chatManage.RerankResult); j++ {
|
|
if chatManage.RerankResult[j].Score > chatManage.RerankResult[i].Score {
|
|
chatManage.RerankResult[i], chatManage.RerankResult[j] = chatManage.RerankResult[j], chatManage.RerankResult[i]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|