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:
@@ -60,6 +60,7 @@ export interface ConversationConfig {
|
||||
rerank_model_id?: string
|
||||
rewrite_prompt_system?: string
|
||||
rewrite_prompt_user?: string
|
||||
enable_query_expansion?: boolean
|
||||
}
|
||||
|
||||
export function getSystemInfo(): Promise<{ data: SystemInfo }> {
|
||||
|
||||
@@ -1431,6 +1431,10 @@ export default {
|
||||
label: 'Enable Query Rewrite',
|
||||
desc: 'Automatically rewrite multi-turn queries for better recall'
|
||||
},
|
||||
enableQueryExpansion: {
|
||||
label: 'Enable LLM Query Expansion',
|
||||
desc: 'When recall is low, call a reasoning model to generate expansion queries (adds latency & cost)'
|
||||
},
|
||||
fallbackStrategy: {
|
||||
label: 'Fallback Strategy',
|
||||
desc: 'How to respond when no relevant documents are found',
|
||||
@@ -1506,6 +1510,7 @@ export default {
|
||||
rerankTopKSaved: 'ReRank TopK saved',
|
||||
rerankThresholdSaved: 'ReRank threshold saved',
|
||||
enableRewriteSaved: 'Query rewrite preference saved',
|
||||
enableQueryExpansionSaved: 'Query expansion preference saved',
|
||||
fallbackStrategySaved: 'Fallback strategy saved',
|
||||
fallbackResponseSaved: 'Fallback response saved',
|
||||
fallbackPromptSaved: 'Fallback prompt saved',
|
||||
|
||||
@@ -1237,6 +1237,15 @@ export default {
|
||||
autoDisabled: 'Конфигурация Agent неполная. Режим Agent автоматически выключен'
|
||||
}
|
||||
},
|
||||
conversationSettings: {
|
||||
enableQueryExpansion: {
|
||||
label: 'Включить расширение запросов',
|
||||
desc: 'При низкой выдаче обращаться к LLM для генерации дополнительных запросов (дороже и медленнее)'
|
||||
},
|
||||
toasts: {
|
||||
enableQueryExpansionSaved: 'Настройка расширения запросов сохранена'
|
||||
}
|
||||
},
|
||||
mcpSettings: {
|
||||
title: 'Сервисы MCP',
|
||||
description: 'Управление внешними сервисами MCP (Model Context Protocol) для использования инструментов и ресурсов в режиме Agent',
|
||||
|
||||
@@ -1435,6 +1435,10 @@ export default {
|
||||
label: "开启问题改写",
|
||||
desc: "多轮对话自动改写问题以获得更优召回",
|
||||
},
|
||||
enableQueryExpansion: {
|
||||
label: "启用查询扩展",
|
||||
desc: "召回不足时调用大模型生成扩展查询(增加时延与成本)",
|
||||
},
|
||||
fallbackStrategy: {
|
||||
label: "兜底策略",
|
||||
desc: "检索无结果时采用的处理方式",
|
||||
@@ -1510,6 +1514,7 @@ export default {
|
||||
rerankTopKSaved: "ReRank TopK 已保存",
|
||||
rerankThresholdSaved: "ReRank 阈值已保存",
|
||||
enableRewriteSaved: "问题改写开关已保存",
|
||||
enableQueryExpansionSaved: "查询扩展策略已保存",
|
||||
fallbackStrategySaved: "兜底策略已保存",
|
||||
fallbackResponseSaved: "兜底回复已保存",
|
||||
fallbackPromptSaved: "兜底 Prompt 已保存",
|
||||
|
||||
@@ -506,6 +506,20 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('conversationSettings.enableQueryExpansion.label') }}</label>
|
||||
<p class="desc">{{ $t('conversationSettings.enableQueryExpansion.desc') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch
|
||||
v-model="localEnableQueryExpansion"
|
||||
:label="[$t('common.off'), $t('common.on')]"
|
||||
@change="handleEnableQueryExpansionChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 改写 Prompt:仅在开启改写时展示 -->
|
||||
<div v-if="localEnableRewrite" class="setting-row vertical">
|
||||
<div class="setting-info">
|
||||
@@ -662,6 +676,7 @@ const getDefaultConversationConfig = (): ConversationConfig => ({
|
||||
rerank_top_k: 5,
|
||||
rerank_threshold: 0.5,
|
||||
enable_rewrite: true,
|
||||
enable_query_expansion: true,
|
||||
fallback_strategy: 'fixed',
|
||||
fallback_response: '',
|
||||
fallback_prompt: '',
|
||||
@@ -720,6 +735,7 @@ const localVectorThreshold = ref(0.5)
|
||||
const localRerankTopK = ref(5)
|
||||
const localRerankThreshold = ref(0.5)
|
||||
const localEnableRewrite = ref(true)
|
||||
const localEnableQueryExpansion = ref(true)
|
||||
const localFallbackStrategy = ref<'fixed' | 'model'>('fixed')
|
||||
const localFallbackResponse = ref('')
|
||||
const localFallbackPrompt = ref('')
|
||||
@@ -750,6 +766,7 @@ const syncConversationLocals = () => {
|
||||
localRerankTopK.value = cfg.rerank_top_k ?? 5
|
||||
localRerankThreshold.value = cfg.rerank_threshold ?? 0.5
|
||||
localEnableRewrite.value = cfg.enable_rewrite ?? true
|
||||
localEnableQueryExpansion.value = cfg.enable_query_expansion ?? true
|
||||
localFallbackStrategy.value = (cfg.fallback_strategy as 'fixed' | 'model') || 'fixed'
|
||||
localFallbackResponse.value = cfg.fallback_response ?? ''
|
||||
localFallbackPrompt.value = cfg.fallback_prompt ?? ''
|
||||
@@ -1798,6 +1815,18 @@ const handleEnableRewriteChange = async (value: boolean) => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleEnableQueryExpansionChange = async (value: boolean) => {
|
||||
try {
|
||||
await saveConversationConfig(
|
||||
{ enable_query_expansion: value },
|
||||
t('conversationSettings.toasts.enableQueryExpansionSaved')
|
||||
)
|
||||
} catch (error) {
|
||||
console.error('保存 enable_query_expansion 失败:', error)
|
||||
localEnableQueryExpansion.value = conversationConfig.value.enable_query_expansion ?? true
|
||||
}
|
||||
}
|
||||
|
||||
const handleFallbackStrategyChange = async (value: 'fixed' | 'model') => {
|
||||
try {
|
||||
await saveConversationConfig({ fallback_strategy: value }, t('conversationSettings.toasts.fallbackStrategySaved'))
|
||||
|
||||
Reference in New Issue
Block a user