other
- Location
hooks/postResponse.js:237- Finding
Automatic Disclosure of Conversations and Persistent Memories to an External Embedding Service
- Content
View full analysis
{ if (!fs.existsSync(d)) fs.mkdirSync(d, { recursive: true }); }); const id = `conv_${Date.now()}`; const messages = [ { role: 'user', content: userMsg }, { role: 'assistant', content: assistantMsg } ]; // 保存原始 fs.writeFileSync(path.join(rawDir, `${id}.json`), JSON.stringify({ id, messages }, null, 2)); // 生成向量 const text = messages.map(m => `${m.role}: ${m.content}`).join('\n'); const embedding = await generateEmbedding(text); if (embedding) { fs.writeFileSync(path.join(vecDir, `${id}.json`), JSON.stringify({ id, embedding, text: text.substring(0, 500) }, null, 2)); } } catch (e) { logger.hookWarn(`对话存储失败: ${e.message}`, 'postResponse'); } } ``` ```js async function postResponseHook(ctx, plugin) { const userMessage = ctx.userMessage || ''; const assistantMessage = ctx ...[truncated 4070 chars]- Remediation
View remediation
