fix: update environment configuration for debugging and logging, enhance SQLite FTS5 table management, and improve API base URL handling
This commit is contained in:
@@ -15,15 +15,15 @@ import (
|
||||
|
||||
// PluginSearch implements search functionality for chat pipeline
|
||||
type PluginSearch struct {
|
||||
knowledgeBaseService interfaces.KnowledgeBaseService
|
||||
knowledgeService interfaces.KnowledgeService
|
||||
chunkService interfaces.ChunkService
|
||||
config *config.Config
|
||||
webSearchService interfaces.WebSearchService
|
||||
tenantService interfaces.TenantService
|
||||
sessionService interfaces.SessionService
|
||||
webSearchStateService interfaces.WebSearchStateService
|
||||
webSearchProviderRepo interfaces.WebSearchProviderRepository
|
||||
knowledgeBaseService interfaces.KnowledgeBaseService
|
||||
knowledgeService interfaces.KnowledgeService
|
||||
chunkService interfaces.ChunkService
|
||||
config *config.Config
|
||||
webSearchService interfaces.WebSearchService
|
||||
tenantService interfaces.TenantService
|
||||
sessionService interfaces.SessionService
|
||||
webSearchStateService interfaces.WebSearchStateService
|
||||
webSearchProviderRepo interfaces.WebSearchProviderRepository
|
||||
}
|
||||
|
||||
func NewPluginSearch(eventManager *EventManager,
|
||||
@@ -620,21 +620,34 @@ func (p *PluginSearch) searchWebIfEnabled(ctx context.Context, chatManage *types
|
||||
return nil
|
||||
}
|
||||
tenant, _ := types.TenantInfoFromContext(ctx)
|
||||
if tenant == nil || tenant.WebSearchConfig == nil {
|
||||
providerID := chatManage.WebSearchProviderID
|
||||
|
||||
var webConfig *types.WebSearchConfig
|
||||
if tenant != nil && tenant.WebSearchConfig != nil {
|
||||
// Clone tenant config so we can safely override MaxResults
|
||||
cfg := *tenant.WebSearchConfig
|
||||
webConfig = &cfg
|
||||
} else if providerID != "" {
|
||||
webConfig = &types.WebSearchConfig{
|
||||
MaxResults: 10,
|
||||
}
|
||||
} else {
|
||||
pipelineWarn(ctx, "Search", "web_config_missing", map[string]interface{}{
|
||||
"tenant_id": chatManage.TenantID,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// Use provider ID already resolved by session layer (agent config > tenant default)
|
||||
providerID := chatManage.WebSearchProviderID
|
||||
// Apply agent-level web search overrides
|
||||
if chatManage.WebSearchMaxResults > 0 {
|
||||
webConfig.MaxResults = chatManage.WebSearchMaxResults
|
||||
}
|
||||
|
||||
pipelineInfo(ctx, "Search", "web_request", map[string]interface{}{
|
||||
"tenant_id": chatManage.TenantID,
|
||||
"provider_id": providerID,
|
||||
})
|
||||
webResults, err := p.webSearchService.Search(ctx, providerID, tenant.WebSearchConfig, chatManage.RewriteQuery)
|
||||
webResults, err := p.webSearchService.Search(ctx, providerID, webConfig, chatManage.RewriteQuery)
|
||||
if err != nil {
|
||||
pipelineWarn(ctx, "Search", "web_search_error", map[string]interface{}{
|
||||
"tenant_id": chatManage.TenantID,
|
||||
@@ -643,22 +656,22 @@ func (p *PluginSearch) searchWebIfEnabled(ctx context.Context, chatManage *types
|
||||
return nil
|
||||
}
|
||||
// Build questions using RewriteQuery only
|
||||
questions := []string{strings.TrimSpace(chatManage.RewriteQuery)}
|
||||
// questions := []string{strings.TrimSpace(chatManage.RewriteQuery)}
|
||||
// Load session-scoped temp KB state from Redis using WebSearchStateRepository
|
||||
tempKBID, seen, ids := p.webSearchStateService.GetWebSearchTempKBState(ctx, chatManage.SessionID)
|
||||
compressed, kbID, newSeen, newIDs, err := p.webSearchService.CompressWithRAG(
|
||||
ctx, chatManage.SessionID, tempKBID, questions, webResults, tenant.WebSearchConfig,
|
||||
p.knowledgeBaseService, p.knowledgeService, seen, ids,
|
||||
)
|
||||
if err != nil {
|
||||
pipelineWarn(ctx, "Search", "web_compress_error", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
})
|
||||
} else {
|
||||
webResults = compressed
|
||||
// Persist temp KB state back into Redis using WebSearchStateRepository
|
||||
p.webSearchStateService.SaveWebSearchTempKBState(ctx, chatManage.SessionID, kbID, newSeen, newIDs)
|
||||
}
|
||||
// tempKBID, seen, ids := p.webSearchStateService.GetWebSearchTempKBState(ctx, chatManage.SessionID)
|
||||
// compressed, kbID, newSeen, newIDs, err := p.webSearchService.CompressWithRAG(
|
||||
// ctx, chatManage.SessionID, tempKBID, questions, webResults, webConfig,
|
||||
// p.knowledgeBaseService, p.knowledgeService, seen, ids,
|
||||
// )
|
||||
// if err != nil {
|
||||
// pipelineWarn(ctx, "Search", "web_compress_error", map[string]interface{}{
|
||||
// "error": err.Error(),
|
||||
// })
|
||||
// } else {
|
||||
// webResults = compressed
|
||||
// // Persist temp KB state back into Redis using WebSearchStateRepository
|
||||
// p.webSearchStateService.SaveWebSearchTempKBState(ctx, chatManage.SessionID, kbID, newSeen, newIDs)
|
||||
// }
|
||||
res := searchutil.ConvertWebSearchResults(webResults)
|
||||
pipelineInfo(ctx, "Search", "web_hits", map[string]interface{}{
|
||||
"hit_count": len(res),
|
||||
|
||||
@@ -115,6 +115,7 @@ func (s *sessionService) KnowledgeQA(
|
||||
RewritePromptUser: s.cfg.Conversation.RewritePromptUser,
|
||||
WebSearchEnabled: req.WebSearchEnabled,
|
||||
WebSearchProviderID: s.resolveWebSearchProviderID(ctx, req, retrievalTenantID),
|
||||
WebSearchMaxResults: s.resolveWebSearchMaxResults(ctx, req),
|
||||
WebFetchEnabled: s.resolveWebFetchEnabled(req),
|
||||
WebFetchTopN: s.resolveWebFetchTopN(req),
|
||||
TenantID: retrievalTenantID,
|
||||
@@ -841,3 +842,16 @@ func (s *sessionService) resolveWebFetchTopN(req *types.QARequest) int {
|
||||
}
|
||||
return 3
|
||||
}
|
||||
|
||||
// resolveWebSearchMaxResults returns the max results for web search.
|
||||
// Priority: agent config > tenant default > default (10)
|
||||
func (s *sessionService) resolveWebSearchMaxResults(ctx context.Context, req *types.QARequest) int {
|
||||
if req.CustomAgent != nil && req.CustomAgent.Config.WebSearchMaxResults > 0 {
|
||||
return req.CustomAgent.Config.WebSearchMaxResults
|
||||
}
|
||||
tenantInfo, _ := types.TenantInfoFromContext(ctx)
|
||||
if tenantInfo != nil && tenantInfo.WebSearchConfig != nil && tenantInfo.WebSearchConfig.MaxResults > 0 {
|
||||
return tenantInfo.WebSearchConfig.MaxResults
|
||||
}
|
||||
return 10
|
||||
}
|
||||
|
||||
@@ -176,6 +176,11 @@ func (s *sessionService) applyAgentOverridesToChatManage(
|
||||
cm.FallbackPrompt = customAgent.Config.FallbackPrompt
|
||||
}
|
||||
|
||||
// Override web search settings
|
||||
if customAgent.Config.WebSearchMaxResults > 0 {
|
||||
cm.WebSearchMaxResults = customAgent.Config.WebSearchMaxResults
|
||||
}
|
||||
|
||||
// Override history turns
|
||||
if customAgent.Config.HistoryTurns > 0 {
|
||||
cm.MaxRounds = customAgent.Config.HistoryTurns
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
infra_web_search "github.com/Tencent/WeKnora/internal/infrastructure/web_search"
|
||||
"github.com/Tencent/WeKnora/internal/config"
|
||||
infra_web_search "github.com/Tencent/WeKnora/internal/infrastructure/web_search"
|
||||
"github.com/Tencent/WeKnora/internal/logger"
|
||||
"github.com/Tencent/WeKnora/internal/searchutil"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
@@ -216,8 +216,8 @@ func (s *WebSearchService) CompressWithRAG(
|
||||
for _, q := range questions {
|
||||
params := types.SearchParams{
|
||||
QueryText: q,
|
||||
VectorThreshold: 0.5,
|
||||
KeywordThreshold: 0.5,
|
||||
VectorThreshold: 0.2,
|
||||
KeywordThreshold: 0.2,
|
||||
MatchCount: matchCount,
|
||||
}
|
||||
results, err := kbSvc.HybridSearch(ctx, tempKBID, params)
|
||||
|
||||
@@ -36,6 +36,9 @@ func (s *webSearchStateService) GetWebSearchTempKBState(
|
||||
ctx context.Context,
|
||||
sessionID string,
|
||||
) (tempKBID string, seenURLs map[string]bool, knowledgeIDs []string) {
|
||||
if s.redisClient == nil {
|
||||
return "", make(map[string]bool), []string{}
|
||||
}
|
||||
stateKey := fmt.Sprintf("tempkb:%s", sessionID)
|
||||
if raw, getErr := s.redisClient.Get(ctx, stateKey).Bytes(); getErr == nil && len(raw) > 0 {
|
||||
var state struct {
|
||||
@@ -65,6 +68,9 @@ func (s *webSearchStateService) SaveWebSearchTempKBState(
|
||||
seenURLs map[string]bool,
|
||||
knowledgeIDs []string,
|
||||
) {
|
||||
if s.redisClient == nil {
|
||||
return
|
||||
}
|
||||
stateKey := fmt.Sprintf("tempkb:%s", sessionID)
|
||||
state := struct {
|
||||
KBID string `json:"kbID"`
|
||||
|
||||
Reference in New Issue
Block a user