global memories

This commit is contained in:
Luna
2026-03-03 21:40:44 +01:00
parent 68d7dd747f
commit 1eb850423c
4 changed files with 5 additions and 1 deletions

View File

@@ -17,6 +17,8 @@ SHORT_TERM_LIMIT=12
ENABLE_SHORT_TERM_SUMMARY=true ENABLE_SHORT_TERM_SUMMARY=true
# Number of short-term turns before an automatic summary request (default 12) # Number of short-term turns before an automatic summary request (default 12)
SUMMARY_TRIGGER_TURNS=12 SUMMARY_TRIGGER_TURNS=12
# Enable global memory retrieval by default (set to false to scope per user)
ENABLE_GLOBAL_MEMORIES=true
ENABLE_WEB_SEARCH=true ENABLE_WEB_SEARCH=true
OPENAI_API_KEY=your_openai_api_key OPENAI_API_KEY=your_openai_api_key
# Memory retrieval cooldown (ms) before the same long-term entry can be reused # Memory retrieval cooldown (ms) before the same long-term entry can be reused

View File

@@ -101,6 +101,7 @@ okay
- **Importance scoring:** Messages mentioning intent words ("plan", "remember", etc.), showing length, or emotional weight receive higher scores. When the store exceeds its cap, the lowest-importance/oldest memories are pruned. You can also call `pruneLowImportanceMemories()` manually if needed. - **Importance scoring:** Messages mentioning intent words ("plan", "remember", etc.), showing length, or emotional weight receive higher scores. When the store exceeds its cap, the lowest-importance/oldest memories are pruned. You can also call `pruneLowImportanceMemories()` manually if needed.
- **Pattern-aware long-term recall:** Long-term memory is only queried when Nova detects a recall cue (`remember`, `do you know`, `we talked`, `refresh my memory`, etc.). When a cue fires, she fetches the top cosine-similar memories but only keeps the ones whose score meets `MEMORY_RECALL_SIMILARITY_THRESHOLD` (default 0.62); otherwise the conversation stays anchored on the short-term buffer and summary. This keeps memory-driven context from popping up during casual chat unless you explicitly ask for it. - **Pattern-aware long-term recall:** Long-term memory is only queried when Nova detects a recall cue (`remember`, `do you know`, `we talked`, `refresh my memory`, etc.). When a cue fires, she fetches the top cosine-similar memories but only keeps the ones whose score meets `MEMORY_RECALL_SIMILARITY_THRESHOLD` (default 0.62); otherwise the conversation stays anchored on the short-term buffer and summary. This keeps memory-driven context from popping up during casual chat unless you explicitly ask for it.
- **Global recall:** `ENABLE_GLOBAL_MEMORIES` is true by default, so Nova now considers every users long-term memories (tagged with their `user_id`) whenever she runs recall logic. Set it to `false` only if you need strict per-user isolation again.
- **What gets embedded:** After every user→bot turn, `recordInteraction()` (see [src/memory.js](src/memory.js)) bundles the pair, scores its importance, asks OpenAI for an embedding, and stores `{ content, embedding, importance, timestamp }` inside the SQLite tables. - **What gets embedded:** After every user→bot turn, `recordInteraction()` (see [src/memory.js](src/memory.js)) bundles the pair, scores its importance, asks OpenAI for an embedding, and stores `{ content, embedding, importance, timestamp }` inside the SQLite tables.
- **Why so many numbers:** Cosine similarity needs raw vectors to compare new thoughts to past ones. When a fresh message arrives, `retrieveRelevantMemories()` embeds it too, calculates cosine similarity against every stored vector, adds a small importance boost, and returns the top five memories to inject into the system prompt. - **Why so many numbers:** Cosine similarity needs raw vectors to compare new thoughts to past ones. When a fresh message arrives, `retrieveRelevantMemories()` embeds it too, calculates cosine similarity against every stored vector, adds a small importance boost, and returns the top five memories to inject into the system prompt.
- **Memory cooldown:** `MEMORY_COOLDOWN_MS` (defaults to 180000 ms) keeps a long-term memory out of the retrieval window for a few minutes after it was just used so Nova has to pull fresh context before repeating herself, while still falling back automatically if there isnt anything new to surface. - **Memory cooldown:** `MEMORY_COOLDOWN_MS` (defaults to 180000 ms) keeps a long-term memory out of the retrieval window for a few minutes after it was just used so Nova has to pull fresh context before repeating herself, while still falling back automatically if there isnt anything new to surface.

View File

@@ -53,6 +53,7 @@ export const config = {
: 0.62, : 0.62,
memoryRecallTriggerPatterns, memoryRecallTriggerPatterns,
relevantMemoryCount: 3, relevantMemoryCount: 3,
enableGlobalMemories: process.env.ENABLE_GLOBAL_MEMORIES !== 'false',
longTermFetchLimit: 120, longTermFetchLimit: 120,
// Optional local dashboard that runs alongside the bot. Enable with // Optional local dashboard that runs alongside the bot. Enable with
// `ENABLE_DASHBOARD=true` and customize port with `DASHBOARD_PORT`. // `ENABLE_DASHBOARD=true` and customize port with `DASHBOARD_PORT`.

View File

@@ -93,8 +93,8 @@ export async function buildPrompt(userId, incomingText, options = {}) {
blockedSearchTerm = null, blockedSearchTerm = null,
searchOutage = null, searchOutage = null,
context: providedContext = null, context: providedContext = null,
useGlobalMemories = false,
userName = null, userName = null,
useGlobalMemories = config.enableGlobalMemories,
includeMemories = false, includeMemories = false,
similarityThreshold = null, similarityThreshold = null,
} = options; } = options;