UNPKG

@muhtalipdede/hierarchical-belief-memory-system

Version:

A simple hierarchical belief memory system using Model Context Protocol

26 lines (25 loc) 930 B
export function updateMemory(memoryContext, newEntry, strategy = "append") { const existingIndex = memoryContext.findIndex((m) => m.type === newEntry.type); if (existingIndex !== -1) { if (strategy === "overwrite") { memoryContext[existingIndex] = newEntry; } else if (strategy === "append") { memoryContext[existingIndex].content += ` ${newEntry.content}`; } else if (strategy === "merge") { memoryContext[existingIndex] = { ...memoryContext[existingIndex], content: mergeTexts(memoryContext[existingIndex].content, newEntry.content) }; } } else { memoryContext.push(newEntry); } return memoryContext; } function mergeTexts(text1, text2) { // Basit birleşim mantığı — NLP veya embedding benzerliği ile iyileştirilebilir return `${text1}\n\n${text2}`; }