From 0cad85d4a7a9fc1bf56b7e5448c697ca44020495 Mon Sep 17 00:00:00 2001 From: Storme-bit Date: Fri, 17 Apr 2026 05:54:33 -0700 Subject: [PATCH] adding in entity extraction layer --- .../memory-service/src/entities/extraction.js | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/packages/memory-service/src/entities/extraction.js b/packages/memory-service/src/entities/extraction.js index 15c4d59..0bdf851 100644 --- a/packages/memory-service/src/entities/extraction.js +++ b/packages/memory-service/src/entities/extraction.js @@ -8,16 +8,33 @@ const ENTITY_TYPES = ['person', 'place', 'project', 'technology', 'concept', 'or function buildExtractionPrompt(userMessage, aiResponse) { return [ - 'Extract named entities from the conversation below.', - `Valid entity types: ${ENTITY_TYPES.join(', ')}.`, - 'Return ONLY a JSON array. No explanation, no markdown, no code fences.', - 'Each item must have exactly these fields: "name" (string), "type" (one of the valid types), "notes" (one sentence fact about this entity from the conversation).', - 'If no entities are found, return: []', + '<|im_start|>system', + 'You are an entity extraction assistant. You extract named entities from conversations and return them as a JSON array. You never return empty arrays when entities are present. You only output valid JSON.<|im_end|>', + '<|im_start|>user', + 'Extract all named entities from this conversation.', '', + `Valid types: ${ENTITY_TYPES.join(', ')}`, + '', + 'Examples of entities to extract:', + '- People: names of individuals', + '- Projects: software projects, systems, tools being built', + '- Technologies: databases, frameworks, languages, hardware', + '- Organizations: companies, teams', + '- Places: locations, servers, infrastructure', + '', + 'Return a JSON array where each item has:', + ' "name": the entity name', + ' "type": one of the valid types above', + ' "notes": one sentence describing this entity based on the conversation', + '', + '### Conversation:', `User: ${userMessage}`, `Assistant: ${aiResponse}`, '', - 'JSON array:', + '### Extracted entities as JSON array:', + '<|im_end|>', + '<|im_start|>assistant', + '[', ].join('\n'); } @@ -26,7 +43,7 @@ async function extractAndStoreEntities(userMessage, aiResponse) { userMessage: userMessage?.slice(0, 100), aiResponse: aiResponse?.slice(0, 100) }); - + console.log('[entities] Extraction triggered') try { const res = await fetch(`${EXTRACTION_URL}/api/generate`, {