From 405676edb5384bcbbf0742292af9fef3f83f1e77 Mon Sep 17 00:00:00 2001 From: Storme-bit Date: Mon, 20 Apr 2026 23:28:46 -0700 Subject: [PATCH] extraction error logging --- .../memory-service/src/entities/extraction.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/memory-service/src/entities/extraction.js b/packages/memory-service/src/entities/extraction.js index 65b7ff7..93b1e29 100644 --- a/packages/memory-service/src/entities/extraction.js +++ b/packages/memory-service/src/entities/extraction.js @@ -29,6 +29,9 @@ function buildExtractionPrompt(userMessage, aiResponse, knownEntities = []) { ' "type": one of the valid types above', ' "notes": one sentence describing this entity based on the conversation', '', + 'Extract all named entities from this conversation.', + 'Respond with ONLY a JSON array. Start your response with [ and end with ].', + 'Do not include any text before or after the array.', `User: ${userMessage}`, `Assistant: ${aiResponse}`, '<|end|>', @@ -68,7 +71,7 @@ async function extractAndStoreEntities(userMessage, aiResponse, projectId=null) stream: false, options: { temperature: 0.1, - num_predict: 768, + num_predict: 1024, }, }), }); @@ -80,8 +83,15 @@ async function extractAndStoreEntities(userMessage, aiResponse, projectId=null) console.log('[entities] raw response:', JSON.stringify(raw.slice(0, 300))); // Extract just the JSON array — everything from [ to the last ] - const stripped = raw.replace(/```(?:json)?/g, '').trim(); - const match = stripped.match(/\[[\s\S]*\]/); + let normalized = raw.replace(/```(?:json)?/g, '').trim(); + if (!normalized.startsWith('[')) { + normalized = '[' + normalized; + } + if (!normalized.endsWith(']')) { + // Trim any trailing comma or incomplete object before closing + normalized = normalized.replace(/,?\s*\{[^}]*$/, '') + ']'; + } + const match = normalized.match(/\[[\s\S]*\]/); if (!match) throw new Error('No JSON array found in response'); const clean = match[0];