/** * RAG配置管理组件 * 提供可视化的RAG检索参数配置界面 */ import React, { useState, useEffect } from 'react'; import { RagGroundingConfig } from '../types/ragGrounding'; import { RagConfigOptimizer, RagConfigPresets } from '../utils/ragConfigOptimizer'; interface RagConfigManagerProps { config: RagGroundingConfig; onConfigChange: (config: RagGroundingConfig) => void; onClose?: () => void; } export const RagConfigManager: React.FC = ({ config, onConfigChange, onClose }) => { const [currentConfig, setCurrentConfig] = useState(config); const [selectedScenario, setSelectedScenario] = useState('BALANCED'); const [customPresets, setCustomPresets] = useState>({}); useEffect(() => { setCustomPresets(RagConfigPresets.getPresets()); }, []); const handleScenarioChange = (scenarioKey: string) => { setSelectedScenario(scenarioKey); const scenario = RagConfigOptimizer.SCENARIOS[scenarioKey]; if (scenario) { const newConfig = RagConfigOptimizer.applyScenario(currentConfig, scenario); setCurrentConfig(newConfig); onConfigChange(newConfig); } }; const handleConfigUpdate = (updates: Partial) => { const newConfig = { ...currentConfig, ...updates }; setCurrentConfig(newConfig); onConfigChange(newConfig); }; const handleSavePreset = () => { const name = prompt('请输入预设名称:'); if (name && name.trim()) { RagConfigPresets.savePreset(name.trim(), currentConfig); setCustomPresets(RagConfigPresets.getPresets()); } }; const handleLoadPreset = (presetName: string) => { const preset = RagConfigPresets.getPreset(presetName); if (preset) { setCurrentConfig(preset); onConfigChange(preset); } }; return (

RAG检索配置管理

{onClose && ( )}
{/* 预设场景选择 */}

优化场景

{Object.entries(RagConfigOptimizer.SCENARIOS).map(([key, scenario]) => ( ))}
{/* 详细配置 */}

详细配置

{/* 最大检索结果数量 */}
handleConfigUpdate({ max_retrieval_results: parseInt(e.target.value) })} className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" />

更多结果可能包含更多信息,但也可能降低相关性

{/* 相关性阈值 */}
handleConfigUpdate({ relevance_threshold: parseFloat(e.target.value) })} className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" />

较低的阈值会返回更多结果,较高的阈值会返回更相关的结果

{/* 搜索过滤器 */}
handleConfigUpdate({ search_filter: e.target.value || undefined })} placeholder="例如: category: ANY("服装", "搭配")" className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" />

使用Vertex AI Search过滤器语法限制搜索范围

{/* 包含摘要 */}

启用后会包含检索结果的摘要信息,有助于AI理解上下文

{/* 配置说明 */}

当前配置说明

{RagConfigOptimizer.getConfigExplanation(currentConfig)}

{/* 自定义预设管理 */}

自定义预设

{Object.keys(customPresets).length > 0 && (
{Object.keys(customPresets).map((presetName) => (
{presetName}
))}
)}
{/* 操作按钮 */}
{onClose && ( )}
); };