feat(kb): VikingDB纯检索+重排+Redis上下文+全库搜索+别名扩展+KB保护窗口+RAG语气引导
- 新增 kbRetriever.js: VikingDB search_knowledge 纯检索替代 Ark chat/completions, doubao-seed-rerank 重排, RAG payload 语气引导缓解音色差异 - 新增 redisClient.js: Redis 连接管理 + 5轮对话历史 + KB缓存双写 - toolExecutor.js: 产品别名扩展25条, 全库检索topK=25, 检索阈值0.01, 精简 buildDeterministicKnowledgeQuery - nativeVoiceGateway.js: isPureChitchat扩展, KB保护窗口60s, prequery参数调优 - realtimeDialogRouting.js: resolveReply感知KB保护窗口, fast-path适配raw模式 - app.js: 健康检查新增 redis/reranker/kbRetrievalMode - 新增测试: alias A/B测试, KB retriever测试, Redis客户端测试, raw模式集成测试
This commit is contained in:
@@ -9,6 +9,7 @@ const voiceRoutes = require('./routes/voice');
|
||||
const chatRoutes = require('./routes/chat');
|
||||
const sessionRoutes = require('./routes/session');
|
||||
const { setupNativeVoiceGateway } = require('./services/nativeVoiceGateway');
|
||||
const redisClient = require('./services/redisClient');
|
||||
|
||||
// ========== 环境变量校验 ==========
|
||||
function validateEnv() {
|
||||
@@ -54,6 +55,8 @@ function validateEnv() {
|
||||
{ key: 'VOLC_S2S_SPEAKER_ID', desc: '自定义音色' },
|
||||
{ key: 'VOLC_ARK_KNOWLEDGE_BASE_IDS', desc: '方舟私域知识库(语音)' },
|
||||
{ key: 'ASSISTANT_PROFILE_API_URL', desc: '外接助手资料接口' },
|
||||
{ key: 'REDIS_URL', desc: 'Redis(对话上下文+KB缓存)' },
|
||||
{ key: 'ENABLE_RERANKER', desc: '重排模型' },
|
||||
];
|
||||
const configuredOptional = optional.filter(({ key }) => {
|
||||
const v = process.env[key];
|
||||
@@ -107,6 +110,9 @@ app.get('/api/health', (req, res) => {
|
||||
webSearch: !!process.env.VOLC_WEBSEARCH_API_KEY && !process.env.VOLC_WEBSEARCH_API_KEY.startsWith('your_'),
|
||||
customSpeaker: !!process.env.VOLC_S2S_SPEAKER_ID && !process.env.VOLC_S2S_SPEAKER_ID.startsWith('your_'),
|
||||
arkKnowledgeBase: !!process.env.VOLC_ARK_KNOWLEDGE_BASE_IDS && !process.env.VOLC_ARK_KNOWLEDGE_BASE_IDS.startsWith('your_'),
|
||||
redis: redisClient.isAvailable(),
|
||||
reranker: process.env.ENABLE_RERANKER === 'true' ? (process.env.VOLC_ARK_RERANKER_MODEL || 'doubao-seed-rerank') : false,
|
||||
kbRetrievalMode: process.env.VOLC_ARK_KB_RETRIEVAL_MODE || 'answer',
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -144,6 +150,15 @@ async function start() {
|
||||
console.warn('[DB] Continuing without database — context switching will use in-memory fallback');
|
||||
}
|
||||
|
||||
// Redis 初始化(可选,失败不阻塞启动)
|
||||
try {
|
||||
redisClient.createClient();
|
||||
console.log('[Redis] Client created, connecting...');
|
||||
} catch (err) {
|
||||
console.warn('[Redis] Initialization failed:', err.message);
|
||||
console.warn('[Redis] Continuing without Redis — will use in-memory fallback');
|
||||
}
|
||||
|
||||
if (process.env.ENABLE_NATIVE_VOICE_GATEWAY !== 'false') {
|
||||
setupNativeVoiceGateway(server);
|
||||
console.log('[NativeVoice] Gateway enabled at /ws/realtime-dialog');
|
||||
|
||||
Reference in New Issue
Block a user