feat: 增强知识库和搜索功能的逻辑

This commit is contained in:
wizardchen
2025-12-22 11:23:25 +08:00
committed by lyingbug
parent f7900a5e9a
commit 3c83cf9873
4 changed files with 50 additions and 8 deletions
@@ -195,6 +195,11 @@ func (s *agentService) registerTools(
"database_query": true,
}
// If no knowledge and no web search, also disable todo_write (not useful for simple chat)
if !config.WebSearchEnabled {
kbTools["todo_write"] = true
}
for _, toolName := range allowedTools {
if !kbTools[toolName] {
filteredTools = append(filteredTools, toolName)
@@ -57,8 +57,9 @@ func (p *PluginSearch) ActivationEvents() []types.EventType {
func (p *PluginSearch) OnEvent(ctx context.Context,
eventType types.EventType, chatManage *types.ChatManage, next func() *PluginError,
) *PluginError {
// Check if we have search targets
if len(chatManage.SearchTargets) == 0 && len(chatManage.KnowledgeBaseIDs) == 0 && len(chatManage.KnowledgeIDs) == 0 {
// Check if we have search targets or web search enabled
hasKBTargets := len(chatManage.SearchTargets) > 0 || len(chatManage.KnowledgeBaseIDs) > 0 || len(chatManage.KnowledgeIDs) > 0
if !hasKBTargets && !chatManage.WebSearchEnabled {
pipelineError(ctx, "Search", "kb_not_found", map[string]interface{}{
"session_id": chatManage.SessionID,
})
+10 -5
View File
@@ -558,16 +558,21 @@ func (s *sessionService) KnowledgeQA(
EnableQueryExpansion: enableQueryExpansion,
}
// Determine pipeline based on knowledge bases availability
// If no knowledge bases are selected, use pure chat pipeline
// Determine pipeline based on knowledge bases availability and web search setting
// If no knowledge bases are selected AND web search is disabled, use pure chat pipeline
// Otherwise use rag_stream pipeline (which handles both KB search and web search)
var pipeline []types.EventType
if len(knowledgeBaseIDs) == 0 && len(knowledgeIDs) == 0 {
logger.Info(ctx, "No knowledge bases selected, using chat_stream pipeline")
if len(knowledgeBaseIDs) == 0 && len(knowledgeIDs) == 0 && !webSearchEnabled {
logger.Info(ctx, "No knowledge bases selected and web search disabled, using chat_stream pipeline")
pipeline = types.Pipline["chat_stream"]
// For pure chat, UserContent is the Query (since INTO_CHAT_MESSAGE is skipped)
chatManage.UserContent = query
} else {
logger.Info(ctx, "Knowledge bases selected, using rag_stream pipeline")
if webSearchEnabled && len(knowledgeBaseIDs) == 0 && len(knowledgeIDs) == 0 {
logger.Info(ctx, "Web search enabled without knowledge bases, using rag_stream pipeline for web search only")
} else {
logger.Info(ctx, "Knowledge bases selected, using rag_stream pipeline")
}
pipeline = types.Pipline["rag_stream"]
}