This commit is contained in:
+32
-25
@@ -69,18 +69,13 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
embeddingProfile := knowledge.ResolveEmbeddingProfile(cfg.KnowledgeEmbeddingProfile, cfg.OllamaEmbeddingModel)
|
||||
k, err := knowledge.Load(ctx, cfg.KnowledgeDir, cfg.DataDir, o, cfg.RAGEnabled, cfg.KnowledgeAllowedSources, knowledge.ScoringConfig{
|
||||
k, err := knowledge.NewStore(cfg.KnowledgeDir, cfg.DataDir, o, cfg.RAGEnabled, cfg.KnowledgeAllowedSources, knowledge.ScoringConfig{
|
||||
SemanticWeight: cfg.KnowledgeSemanticWeight, TitleWeight: cfg.KnowledgeTitleWeight, LexicalWeight: cfg.KnowledgeLexicalWeight, KeywordWeight: cfg.KnowledgeKeywordWeight, CategoryWeight: cfg.KnowledgeCategoryWeight,
|
||||
EmbeddingProfile: embeddingProfile, EmbeddingIdentity: cfg.OllamaEmbeddingModel, ChunkWords: cfg.KnowledgeChunkWords, ChunkOverlap: cfg.KnowledgeChunkOverlapWords, MaxChunksPerDoc: cfg.KnowledgeMaxChunksPerDoc, MaxQueryChunks: cfg.KnowledgeMaxQueryChunks,
|
||||
CategoryMode: cfg.KnowledgeCategoryMode, CategoryMapFile: cfg.KnowledgeCategoryMapFile, IgnoreGlobs: cfg.KnowledgeIgnoreGlobs,
|
||||
})
|
||||
if err != nil {
|
||||
slog.Error("knowledge store initialization failed",
|
||||
"error", err,
|
||||
"knowledge_dir", cfg.KnowledgeDir,
|
||||
"data_dir", cfg.DataDir,
|
||||
"rag_enabled", cfg.RAGEnabled,
|
||||
)
|
||||
slog.Error("knowledge store configuration failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
l, err := learning.Open(cfg.DataDir, cfg.LearningMaxExamples)
|
||||
@@ -88,24 +83,7 @@ func main() {
|
||||
slog.Error("learning store initialization failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
stats := k.LoadStats()
|
||||
if stats.IgnoredFiles > 0 || stats.UnmappedCategoryFiles > 0 {
|
||||
slog.Warn("knowledge loaded with compatibility rules", "ignored_files", stats.IgnoredFiles, "unmapped_category_files", stats.UnmappedCategoryFiles, "unmapped_categories", stats.UnmappedCategories, "category_mode", cfg.KnowledgeCategoryMode)
|
||||
}
|
||||
m := metrics.New()
|
||||
m.SetKnowledgeDocs(k.Count())
|
||||
if cfg.GLPIKBEnabled {
|
||||
kbSync := glpikb.New(cfg, g, k, m)
|
||||
if err := kbSync.LoadCache(ctx); err != nil {
|
||||
slog.Warn("GLPI knowledge cache unavailable", "error", err)
|
||||
}
|
||||
syncCtx, syncCancel := context.WithTimeout(ctx, maxDuration(cfg.GLPITimeout*3, 30*time.Second))
|
||||
if err := kbSync.Sync(syncCtx); err != nil {
|
||||
slog.Error("initial GLPI knowledge base sync failed; continuing with local/cache knowledge", "error", err)
|
||||
}
|
||||
syncCancel()
|
||||
kbSync.Start(ctx)
|
||||
}
|
||||
q := queue.New(cfg.QueueSize)
|
||||
var kuma *uptimekuma.Client
|
||||
if cfg.UptimeKumaEnabled {
|
||||
@@ -113,7 +91,6 @@ func main() {
|
||||
}
|
||||
contextCollector := contextdata.New(cfg, g, kuma)
|
||||
svc := agent.New(cfg, g, o, k, l, st, q, m, contextCollector)
|
||||
svc.Start(ctx)
|
||||
web, err := webui.New(cfg, m, st, q, k, svc)
|
||||
if err != nil {
|
||||
slog.Error("web UI initialization failed", "error", err)
|
||||
@@ -127,6 +104,36 @@ func main() {
|
||||
cancel()
|
||||
}
|
||||
}()
|
||||
|
||||
// Large local knowledge bases are initialized after the HTTP server is up.
|
||||
// Ticket polling/workers remain paused until the local index is ready.
|
||||
go func() {
|
||||
slog.Info("knowledge initialization started in background", "knowledge_dir", cfg.KnowledgeDir, "rag_enabled", cfg.RAGEnabled)
|
||||
if err := k.Initialize(ctx); err != nil {
|
||||
slog.Error("knowledge store initialization failed; web UI remains available", "error", err, "knowledge_dir", cfg.KnowledgeDir, "data_dir", cfg.DataDir, "rag_enabled", cfg.RAGEnabled)
|
||||
return
|
||||
}
|
||||
m.SetKnowledgeDocs(k.Count())
|
||||
stats := k.LoadStats()
|
||||
if stats.IgnoredFiles > 0 || stats.UnmappedCategoryFiles > 0 {
|
||||
slog.Warn("knowledge loaded with compatibility rules", "ignored_files", stats.IgnoredFiles, "unmapped_category_files", stats.UnmappedCategoryFiles, "unmapped_categories", stats.UnmappedCategories, "category_mode", cfg.KnowledgeCategoryMode)
|
||||
}
|
||||
if cfg.GLPIKBEnabled {
|
||||
kbSync := glpikb.New(cfg, g, k, m)
|
||||
if err := kbSync.LoadCache(ctx); err != nil {
|
||||
slog.Warn("GLPI knowledge cache unavailable", "error", err)
|
||||
}
|
||||
syncCtx, syncCancel := context.WithTimeout(ctx, maxDuration(cfg.GLPITimeout*3, 30*time.Second))
|
||||
if err := kbSync.Sync(syncCtx); err != nil {
|
||||
slog.Error("initial GLPI knowledge base sync failed; continuing with local/cache knowledge", "error", err)
|
||||
}
|
||||
syncCancel()
|
||||
kbSync.Start(ctx)
|
||||
m.SetKnowledgeDocs(k.Count())
|
||||
}
|
||||
svc.Start(ctx)
|
||||
slog.Info("ticket processing started", "knowledge_docs", k.Count())
|
||||
}()
|
||||
<-ctx.Done()
|
||||
shutdownCtx, c := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer c()
|
||||
|
||||
Reference in New Issue
Block a user