Beyond RAG: Building Memory Injections for Your AI Assistants
From the publisher’s feed, collected in the ZeroLabs newsroom.
How we replaced reactive retrieval with proactive memory injection — and why the difference matters.Key InsightsMemory injection ≠ RAG. Instead of the model searching for context mid-conversation, SYNAPSE injects relevant memories into the context window before generation begins. The model thinks with memories already present.Association over similarity. Graph traversal along semantic edges retrieves contextually connected memories — not just documents that share keywords or embeddings.Hybrid extraction keeps latency under 300ms. A two-layer strategy (regex patterns + a local 1.7B model) identifies memory anchors without API calls, preserving both speed and privacy.Three retrieval strategies cover each other’s blind spots. Graph BFS, vector search, and keyword matching run in parallel, then deduplicate — no single method is reliable alone.The model doesn’t need to know. Memories injected as context (not tool results) produce more natural, integrated responses — consistent with how human memory works.The Problem With How AI “Remembers”Most memory-augmented AI systems follow the same pattern: the user says something, the model decides it needs context, calls a search tool, waits for results, then generates a response with the retrieved information appended. This is RAG — Retrieval-Augmented Generation. It works. It also fundamentally misunderstands how memory should function in conversational AI.RAG is reactive. The model receives a message, recognizes it needs information, and goes looking for it. The retrieved memories arrive as external data — tool results stapled to the side of the conversation. They inform the response, but they don’t shape the thinking.Human memory doesn’t work this way. When someone says “Paris,” you don’t pause, run a mental search query, wait for results, and then continue the conversation. The associations are already there — the morning chill from la Seine, the café on Rue de Rivoli, the argument you had at the Louvre, the sore feet — all activated simultaneously, before you’ve even formulated your response.We set out to build something closer to that.What We BuiltSYNAPSE is a middleware layer that sits between the user and the language model. It intercepts every incoming message, extracts associative anchors, traverses a memory graph along its edges, and injects relevant memories into the context window before generation begins.The model doesn’t search for memories. It starts thinking with them already present.SYNAPSE intercepts messages before they reach the model. Total overhead: under 300ms.Three design decisions define SYNAPSE. Each one departs from how memory systems are typically built.Decision 1: Middleware, Not a ToolStandard architecture gives the model a `search_memory` tool and lets it decide when to use it. This has three failure modes:- The model forgets to search. It generates a response from parametric knowledge, missing relevant context entirely.- The model searches too late. By the time retrieved memories arrive, the response direction is already set. Memories become afterthoughts.- The model searches for the wrong thing. It formulates a query based on what it thinks is relevant, not what actually connects to the conversation.SYNAPSE removes the model from the retrieval decision entirely. Memory injection is automatic, proactive, and invisible to the model. The language model sees retrieved memories as part of its context — indistinguishable from information it “already knows.”This is not a subtle distinction. Tool results are processed as external information (“I was told”). Context is processed as existing knowledge (“I know”). The difference shows up in response quality: memories that arrive as context are woven into the response naturally, not cited as retrieved facts. RAG introduces decision points at every stage — whether to search, what to search for, how much to trust the results. Each decision is a potential failure mode. SYNAPSE collapses the entire retrieval pipeline into a single atomic operation: the model receives the prompt and its associated memories as one unified context block. There is no intermediate decision, retrieval latency mid-generation, or moment where the model must reconcile external search results with its own reasoning.Decision 2: Association, Not SimilarityRAG retrieves documents by vector similarity — it finds content that looks like the query in embedding space. This works well for document QA. It fails for conversational memory.Consider a user mentioning they’re dealing with a headache during a work session. Standard vector search would retrieve other mentions of headaches. Useful, but shallow.An associative system traverses the memory graph differently. Starting from “headache,” it follows edges to a past event — a long walk in a foreign city where the user pushed through physical discomfort. From there, it reaches an abstracted pattern: productivity despite pain. And from that pattern, it finds a parallel — a similar episode three months ago. None of these memories contain the word “headache.” All of them are relevant.RAG finds documents that mention the same words. SYNAPSE follows graph edges to find memories that share context.“headache”→ past event: long walk in a foreign city (edge: co-occurrence)→ context: pushing through physical discomfort (edge: theme)→ insight: pattern of productivity despite pain (edge: abstraction)→ related: similar episode three months ago (edge: parallel)The retrieval follows edges, not similarity. It pulls in a subgraph of connected memories that provide actual context — not just content that contains the word “headache.”The implementation uses a recursive CTE for breadth-first graph traversal:WITH RECURSIVE graph AS ( -- Start from anchor nodes SELECT id, concept, summary, importance, 0 AS depth, ARRAY[id] AS path FROM memory_nodes WHERE id = ANY($1::uuid[]) UNION ALL -- Traverse edges (max depth 2, min edge strength 0.2) SELECT n.id, n.concept, n.summary, n.importance, g.depth + 1, g.path || n.id FROM graph g JOIN memory_edges e ON g.id = e.source_id JOIN memory_nodes n ON e.target_id = n.id WHERE g.depth AND e.strength > 0.2 AND NOT n.id = ANY(g.path))SELECT DISTINCT ON (id) *FROM graphORDER BY id, depth, importance DESCThis gives us a subgraph of associated memories in under 50ms — fast enough to be imperceptible in conversation.Decision 3: Hybrid ExtractionIdentifying what to look for is as important as how to look. SYNAPSE uses a two-layer extraction strategy:Layer 1: Pattern-based extraction (always runs, ~2ms)Regex patterns identify entities, temporal markers, technical terms, and emotional signals in the user’s message. These patterns are matched against a dictionary of known concepts loaded from the memory graph at session start. A match means we have an immediate entry point for graph traversal.Layer 2: Local model extraction (conditional, ~250ms)When pattern-based extraction finds insufficient anchor points, a small local language model (1.7B parameters, quantized, running on-device) analyzes the message for contextual anchors — concepts that regex can’t catch because they require understanding, not matching.The local model is critical for three reasons:- Latency: API calls add 200–500ms. Local inference on Apple Silicon: ~250ms including model overhead.- Privacy: Message content stays on-device. No second API call with conversation data.- Consistent content processing: The model processes all message content uniformly, without selective refusal — essential for systems designed to handle the full range of human conversation.Every anchor extracted by the model is validated against the original message (does this word actually appear in the input?) to prevent hallucinated anchors from polluting the retrieval pipeline.Multi-Strategy RetrievalOnce anchors are extracted, SYNAPSE doesn’t rely on a single retrieval method. Three strategies run in parallel:Each strategy covers the others’ blind spots. Results are deduplicated and filtered before injection.- Graph BFS — traverses edges via recursive CTE. Catches associated concepts that are connected to the anchors in the memory graph.- Vector search — embedding similarity against the memory store. Catches semantically related memories that may not have explicit graph edges.- Keyword search — plain substring matching on memory content. Catches exact topic matches that vector embeddings smooth over.Why all three? Because each has blind spots:- Vector search struggles with short, specific queries — embedding spaces compress topic-specific terms.- Graph traversal only works from known entry points — novel topics with no graph node get nothing.- Keyword search is crude but catches exact matches that vector embeddings smooth over.The results are deduplicated, filtered for relevance (keyword overlap with extracted anchors), and capped at a token budget that varies by detected conversation mode.What We LearnedAfter running SYNAPSE in production across multiple projects, several patterns emerged:Hub nodes poison everything. Some concepts connect to nearly every memory — they’re superhubs in the graph. Injecting them is worse than injecting nothing: they flood the context with generic information. We maintain an exclusion list of hub concepts that are always filtered out, regardless of relevance score.Session deduplication matters. Without it, the same memories get injected turn after turn if the topic doesn’t change. The system tracks which nodes have already been injected in the current session and skips them on subsequent turns.Relevance scoring needs morphological awareness. In languages with rich morphology (Ukrainian, German, Finnish, etc.), exact keyword matching misses obvious connections. Stem matching — comparing the first 5 characters of words — catches morphological variants without the overhead of a proper stemmer. It’s a heuristic, not a linguistic solution, and it breaks on short roots. But for a relevance filter that runs in Conversation mode changes the optimal injection volume. Casual conversation benefits from light context (1,000–1,500 tokens). Technical work sessions need more (2,000–3,000). Emotional or reflective conversations need less but more precise memory (1,000–1,200 tokens). Overloading the context window with irrelevant memories is worse than injecting nothing.The model doesn’t need to know. We initially considered telling the model that associative memories had been injected. We stopped. The model produces more natural responses when memories are simply present in context without meta-commentary about their origin. This is consistent with how human memory works — you don’t narrate to yourself that you’re remembering something.When to Use This (and When Not To)SYNAPSE makes sense when:- The system has long-term relationships with users (personal assistants, long-running work or research assistant, therapeutic tools, coaching systems)- Memory is structured as a graph with meaningful edges, not just a flat document store- Response latency tolerance is >300ms (conversational systems, not real-time autocomplete)- The full range of conversation content needs to be handled without content filteringStandard RAG is better when:- You’re doing document QA (find the answer in this corpus)- Memories are independent documents without meaningful relationships- You need citation and attribution (RAG’s explicit retrieval is a feature, not a bug)- Latency budget is The Theoretical FrameWhat SYNAPSE implements is, in cognitive science terms, spreading activation — a theory proposed by Collins & Loftus in 1975. In a semantic network, activating one node automatically spreads activation to connected nodes, with decay proportional to edge distance and strength.The application of spreading activation to LLM context windows — where “activation” means “presence in the attention computation” — remains underexplored in the literature. Memory-augmented LLM architectures (MemGPT, GraphRAG, Generative Agents) use retrieval mechanisms that are fundamentally search-based. SYNAPSE is activation-based: memory isn’t found, it’s triggered.Whether this distinction produces measurably better outcomes is an open question. Our qualitative observation is that responses feel more integrated — memories inform the response rather than being appended to it. Rigorous evaluation remains future work.ConclusionRAG solved the problem of giving language models access to external knowledge. For document retrieval, it remains the right tool. But for conversational AI that maintains long-term relationships, the retrieval paradigm has a fundamental mismatch: memory should be associative and proactive, not similarity-based and reactive.SYNAPSE is one implementation of this idea. The core insight is simple: inject memory before generation, traverse by association not similarity, and let the model think with memories already present rather than fetching them mid-thought.The result is a system that doesn’t search for memories. It remembers.Beyond RAG: Building Memory Injections for Your AI Assistants was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.