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:
wizardchen
2025-11-19 20:23:30 +08:00
parent 5434768530
commit b9c1191dd2
15 changed files with 104 additions and 60 deletions
+14 -12
View File
@@ -6,8 +6,8 @@ type ChatManage struct {
SessionID string `json:"session_id"` // Unique identifier for the chat session
Query string `json:"query,omitempty"` // Original user query
ProcessedQuery string `json:"processed_query,omitempty"` // Query after preprocessing
RewriteQuery string `json:"rewrite_query,omitempty"` // Query after rewriting for better retrieval
QueryIntent string `json:"query_intent,omitempty"` // Parsed intent: definition/howto/compare/qa/general
RewriteQuery string `json:"rewrite_query,omitempty"` // Query after rewriting for better retrieval
QueryIntent string `json:"query_intent,omitempty"` // Parsed intent: definition/howto/compare/qa/general
History []*History `json:"history,omitempty"` // Chat history for context
KnowledgeBaseID string `json:"knowledge_base_id"` // ID of the knowledge base to search against (deprecated, use KnowledgeBaseIDs)
@@ -28,9 +28,10 @@ type ChatManage struct {
FallbackStrategy FallbackStrategy `json:"fallback_strategy"` // Strategy when no relevant results are found
FallbackResponse string `json:"fallback_response"` // Default response when fallback occurs
EnableRewrite bool `json:"enable_rewrite"` // Whether to enable rewrite
RewritePromptSystem string `json:"rewrite_prompt_system"` // Custom system prompt for rewrite stage
RewritePromptUser string `json:"rewrite_prompt_user"` // Custom user prompt for rewrite stage
EnableRewrite bool `json:"enable_rewrite"` // Whether to enable rewrite
EnableQueryExpansion bool `json:"enable_query_expansion"` // Whether to enable query expansion with LLM
RewritePromptSystem string `json:"rewrite_prompt_system"` // Custom system prompt for rewrite stage
RewritePromptUser string `json:"rewrite_prompt_user"` // Custom user prompt for rewrite stage
// Internal fields for pipeline data processing
SearchResult []*SearchResult `json:"-"` // Results from search phase
@@ -59,8 +60,8 @@ func (c *ChatManage) Clone() *ChatManage {
return &ChatManage{
Query: c.Query,
ProcessedQuery: c.ProcessedQuery,
RewriteQuery: c.RewriteQuery,
QueryIntent: c.QueryIntent,
RewriteQuery: c.RewriteQuery,
QueryIntent: c.QueryIntent,
SessionID: c.SessionID,
KnowledgeBaseID: c.KnowledgeBaseID,
KnowledgeBaseIDs: knowledgeBaseIDs,
@@ -87,11 +88,12 @@ func (c *ChatManage) Clone() *ChatManage {
Seed: c.SummaryConfig.Seed,
MaxCompletionTokens: c.SummaryConfig.MaxCompletionTokens,
},
FallbackStrategy: c.FallbackStrategy,
FallbackResponse: c.FallbackResponse,
RewritePromptSystem: c.RewritePromptSystem,
RewritePromptUser: c.RewritePromptUser,
EnableRewrite: c.EnableRewrite,
FallbackStrategy: c.FallbackStrategy,
FallbackResponse: c.FallbackResponse,
RewritePromptSystem: c.RewritePromptSystem,
RewritePromptUser: c.RewritePromptUser,
EnableRewrite: c.EnableRewrite,
EnableQueryExpansion: c.EnableQueryExpansion,
}
}
+8 -7
View File
@@ -86,13 +86,14 @@ type ConversationConfig struct {
MaxCompletionTokens int `json:"max_completion_tokens"`
// Retrieval & strategy parameters
MaxRounds int `json:"max_rounds"`
EmbeddingTopK int `json:"embedding_top_k"`
KeywordThreshold float64 `json:"keyword_threshold"`
VectorThreshold float64 `json:"vector_threshold"`
RerankTopK int `json:"rerank_top_k"`
RerankThreshold float64 `json:"rerank_threshold"`
EnableRewrite bool `json:"enable_rewrite"`
MaxRounds int `json:"max_rounds"`
EmbeddingTopK int `json:"embedding_top_k"`
KeywordThreshold float64 `json:"keyword_threshold"`
VectorThreshold float64 `json:"vector_threshold"`
RerankTopK int `json:"rerank_top_k"`
RerankThreshold float64 `json:"rerank_threshold"`
EnableRewrite bool `json:"enable_rewrite"`
EnableQueryExpansion bool `json:"enable_query_expansion"`
// Model configuration
SummaryModelID string `json:"summary_model_id"`