feat: Introduce query expansion feature and enhance related configurations
- Added support for query expansion in conversation settings, allowing the system to generate additional queries when recall is low. - Updated localization files in English, Russian, and Chinese to include new strings for the query expansion feature. - Enhanced UI in AgentSettings.vue to allow users to toggle query expansion settings. - Refactored related API and service logic to accommodate the new query expansion functionality in session management and chat processing.
This commit is contained in:
@@ -123,7 +123,7 @@ func (p *PluginSearch) OnEvent(ctx context.Context,
|
||||
chatManage.SearchResult = allResults
|
||||
|
||||
// If recall is low, attempt query expansion with keyword-focused search
|
||||
if len(chatManage.SearchResult) < max(1, chatManage.EmbeddingTopK/2) {
|
||||
if chatManage.EnableQueryExpansion && len(chatManage.SearchResult) < max(1, chatManage.EmbeddingTopK/2) {
|
||||
pipelineInfo(ctx, "Search", "recall_low", map[string]interface{}{
|
||||
"current": len(chatManage.SearchResult),
|
||||
"threshold": chatManage.EmbeddingTopK / 2,
|
||||
|
||||
@@ -453,6 +453,7 @@ func (s *sessionService) KnowledgeQA(ctx context.Context, session *types.Session
|
||||
maxRounds := session.MaxRounds
|
||||
fallbackResponse := session.FallbackResponse
|
||||
enableRewrite := session.EnableRewrite
|
||||
enableQueryExpansion := true
|
||||
|
||||
summaryParams := session.SummaryParameters
|
||||
if summaryParams == nil {
|
||||
@@ -483,6 +484,7 @@ func (s *sessionService) KnowledgeQA(ctx context.Context, session *types.Session
|
||||
maxRounds = tenantConv.MaxRounds
|
||||
fallbackResponse = tenantConv.FallbackResponse
|
||||
enableRewrite = tenantConv.EnableRewrite
|
||||
enableQueryExpansion = tenantConv.EnableQueryExpansion
|
||||
|
||||
if tenantConv.MaxCompletionTokens != 0 {
|
||||
summaryConfig.MaxCompletionTokens = tenantConv.MaxCompletionTokens
|
||||
@@ -507,28 +509,29 @@ func (s *sessionService) KnowledgeQA(ctx context.Context, session *types.Session
|
||||
// Create chat management object with session settings
|
||||
logger.Infof(ctx, "Creating chat manage object, knowledge base IDs: %v, chat model ID: %s", knowledgeBaseIDs, chatModelID)
|
||||
chatManage := &types.ChatManage{
|
||||
Query: query,
|
||||
RewriteQuery: query,
|
||||
SessionID: session.ID,
|
||||
MessageID: assistantMessageID, // NEW: For event emission in pipeline
|
||||
KnowledgeBaseID: knowledgeBaseIDs[0], // For backward compatibility, use first KB ID
|
||||
KnowledgeBaseIDs: knowledgeBaseIDs, // Multi-KB support
|
||||
VectorThreshold: vectorThreshold,
|
||||
KeywordThreshold: keywordThreshold,
|
||||
EmbeddingTopK: embeddingTopK,
|
||||
RerankModelID: rerankModelID,
|
||||
RerankTopK: rerankTopK,
|
||||
RerankThreshold: rerankThreshold,
|
||||
MaxRounds: maxRounds,
|
||||
ChatModelID: chatModelID,
|
||||
SummaryConfig: summaryConfig,
|
||||
FallbackResponse: fallbackResponse,
|
||||
EventBus: eventBus.AsEventBusInterface(), // NEW: For pipeline to emit events directly
|
||||
WebSearchEnabled: webSearchEnabled,
|
||||
TenantID: session.TenantID,
|
||||
RewritePromptSystem: rewritePromptSystem,
|
||||
RewritePromptUser: rewritePromptUser,
|
||||
EnableRewrite: enableRewrite,
|
||||
Query: query,
|
||||
RewriteQuery: query,
|
||||
SessionID: session.ID,
|
||||
MessageID: assistantMessageID, // NEW: For event emission in pipeline
|
||||
KnowledgeBaseID: knowledgeBaseIDs[0], // For backward compatibility, use first KB ID
|
||||
KnowledgeBaseIDs: knowledgeBaseIDs, // Multi-KB support
|
||||
VectorThreshold: vectorThreshold,
|
||||
KeywordThreshold: keywordThreshold,
|
||||
EmbeddingTopK: embeddingTopK,
|
||||
RerankModelID: rerankModelID,
|
||||
RerankTopK: rerankTopK,
|
||||
RerankThreshold: rerankThreshold,
|
||||
MaxRounds: maxRounds,
|
||||
ChatModelID: chatModelID,
|
||||
SummaryConfig: summaryConfig,
|
||||
FallbackResponse: fallbackResponse,
|
||||
EventBus: eventBus.AsEventBusInterface(), // NEW: For pipeline to emit events directly
|
||||
WebSearchEnabled: webSearchEnabled,
|
||||
TenantID: session.TenantID,
|
||||
RewritePromptSystem: rewritePromptSystem,
|
||||
RewritePromptUser: rewritePromptUser,
|
||||
EnableRewrite: enableRewrite,
|
||||
EnableQueryExpansion: enableQueryExpansion,
|
||||
}
|
||||
|
||||
// Start knowledge QA event processing
|
||||
|
||||
Reference in New Issue
Block a user