From b814ea8b28320fa7a708fe0e1ca9d7d0846239e3 Mon Sep 17 00:00:00 2001 From: ztimson Date: Tue, 3 Mar 2026 00:26:00 -0500 Subject: [PATCH] Improved memory recall results --- package.json | 2 +- src/llm.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 9b6feca..fdf29e0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ztimson/ai-utils", - "version": "0.8.8", + "version": "0.8.9", "description": "AI Utility library", "author": "Zak Timson", "license": "MIT", diff --git a/src/llm.ts b/src/llm.ts index d17563d..3eb8e12 100644 --- a/src/llm.ts +++ b/src/llm.ts @@ -117,12 +117,13 @@ class LLM { const score = (o ? this.cosineSimilarity(m.embeddings[0], o[0].embedding) : 0) + (q ? this.cosineSimilarity(m.embeddings[1], q[0].embedding) : 0); return {...m, score}; - }).toSorted((a: any, b: any) => a.score - b.score).slice(0, limit); + }).toSorted((a: any, b: any) => a.score - b.score).slice(0, limit) + .map(m => `- ${m.owner}: ${m.fact}`).join('\n'); } options.system += '\nYou have RAG memory and will be given the top_k closest memories regarding the users query. Save anything new you have learned worth remembering from the user message using the remember tool and feel free to recall memories manually.\n'; const relevant = await search(message); - if(relevant.length) options.history.push({role: 'tool', name: 'recall', id: 'auto_recall_' + Math.random().toString(), args: {}, content: 'Things I remembered:\n' + relevant.map(m => `${m.owner}: ${m.fact}`).join('\n')}); + if(relevant.length) options.history.push({role: 'tool', name: 'recall', id: 'auto_recall_' + Math.random().toString(), args: {}, content: `Things I remembered:\n${relevant}`}); options.tools = [{ name: 'recall', description: 'Recall the closest memories you have regarding a query using RAG',