Memory & RAG
~7 min readUpdated: December 2026

GAPMem: Boundary-First Graph-Constrained Memory for Personalized Agents

GAPMem Boundary-First Graph-Constrained Agent Memory Architecture

GAPMem (arXiv:2612.05422) is a boundary-first, graph-constrained memory framework that prevents personalized LLM agents from over-generalizing user preferences across unrelated contexts. By separating explicit dialogue preferences from inferred tendencies and gating activation via typed graph scope relations, scenario-aware retrieval reaches 0.8235 F1 (0.8163 paired F1) with 0.0000 contradiction and scene-contamination rates.

Technical Review: Smoke Monkey Core Architecture Team
Tested on Node.js 18+ & BunTypeScript 5.x
Quick Answer & Executive Definition

GAPMem: Boundary-First Graph-Constrained Memory for Personalized Agents: GAPMem (arXiv:2612.05422) is a boundary-first, graph-constrained memory framework that prevents personalized LLM agents from over-generalizing user preferences across unrelated contexts. By separating explicit dialogue preferences from inferred tendencies and gating activation via typed graph scope relations, scenario-aware retrieval reaches 0.8235 F1 (0.8163 paired F1) with 0.0000 contradiction and scene-contamination rates. Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.

Key Architectural Takeaways
Quick Implementation Examplegapmem-scoped-memory-agent.ts
gapmem-scoped-memory-agent.tstypescript
import { createAgent } from '@smoke-monkey/harness';
// Enforce scenario-bounded preference retrieval before prompt injection
const agent = createAgent({
agentId: 'gapmem-personalized-agent',
provider: 'openai-compatible',
baseUrl: 'http://127.0.0.1:8000/v1',
model: 'Qwen/Qwen3-8B',
workspacePath: process.cwd(),
permissions: {
read_file: 'allow',
write_file: 'ask',
run_command: 'ask',
},
});
async function main() {
const result = await agent.run(
'Resolve user formatting preferences only where scenario="typescript-cli" and exclude preferences bound to "markdown-blog", citing source evidence IDs.'
);
console.log('Scoped Memory Output:', result.summary);
}
main().catch(console.error);
Video Guides

Watch: Related Video Guides

Agent Memory EXPLAINED - Complete Architecture

You Can Learn AI Agent Memory Layers | Graph RAG, Vector DB, SQLite, Hermes, Waku

What Is GAPMem and Why Do Vector Memories Leak Across Scenarios?

GAPMem (arXiv:2612.05422) is a boundary-first, graph-constrained preference memory framework designed for personalized LLM agents. Instead of storing flat text chunks in a vector database, GAPMem models each preference as a 9-tuple $p = (c, s, r, v, \tau, \pi, \sigma, o, E)$ capturing category, subject, relation, value, time validity, provenance, scenario scope, override priority, and source evidence.

Conventional RAG memory fails on personalization for three reasons: it treats one-off requests as permanent rules, blurs explicit instructions with weak guesses, and leaks preferences from one domain (such as casual travel chat) into an incompatible scenario (such as formal financial reporting). GAPMem enforces an evidence sufficiency gate $\operatorname{Suff}(p) = \mathbb{I}[\operatorname{Rep}(E_p) \ge \theta_r \land \operatorname{Cons}(E_p) \ge \theta_c \land \operatorname{Alt}(E_p) \le \theta_a]$ and filters graph boundaries before ranking. In exploratory CUPID evaluations:

Retrieval ConfigurationDiagnostic Strict CoveragePaired Strict CoveragePaired F1F1 Gain vs Raw MemoryContradiction / Contamination Rate
Raw Memory0.33330.00000.0000+0.00000.0000 / 0.0000
Raw Memory + Scenario-Aware0.50000.25000.2000+0.20000.0000 / 0.0000
Evidence-Based Preference1.00001.00000.6667+0.66670.0000 / 0.0000
Scenario-Aware Preference0.88890.83330.8163 (0.8235 overall)+0.81630.0000 / 0.0000

Enforcing Boundary-First Preference Filtering in Agent Memory Stores

Notice an important nuance in the authors' findings: raw vector memory improved from 0.3333 to 0.4667 F1 when adding scenario-aware filtering, yet still trailed structured graph-constrained preference retrieval (0.8235 F1). Note that the paper explicitly scopes these results as an exploratory 3-case CUPID retrieval study with model-based judgments rather than an end-to-end production guarantee.

In a TypeScript or Python MCP memory server, you can enforce GAPMem's pre-activation boundary check before vector similarity ranking runs:

python
def filter_preferences(prefs: list[dict], active_scenario: str) -> list[dict]:
    """Apply GAPMem boundary-first filtering prior to similarity ranking."""
    valid = []
    for p in prefs:
        if active_scenario in p.get("exclusions", []):
            continue
        if p.get("scope") and active_scenario not in p["scope"]:
            continue
        if p.get("evidence_count", 0) < 1 or p.get("superseded_by"):
            continue
        valid.append(p)
    return sorted(valid, key=lambda x: (x["explicit"], x["confidence"]), reverse=True)

Respect Exploratory Study Scope

GAPMem arXiv:2612.05422 reports descriptive metrics on 3 CUPID cases; treat its graph schema and boundary-first gating as an architectural blueprint and validate recall on your own agent telemetry.

Google Search Questions & Answers

Frequently Asked Questions

Q:What does boundary-first mean in GAPMem?

Boundary-first means checking scenario applicability, explicit exclusions, conflict edges, and source evidence sufficiency before activating or ranking a preference memory for prompt injection.

Q:How does GAPMem compare to raw vector memory retrieval?

In the CUPID retrieval study, scenario-aware preference retrieval achieved 0.8235 F1 overall (0.8163 paired F1) and evidence-based retrieval hit 1.0000 strict checklist coverage, compared to 0.0000 paired F1 for raw memory.

Q:How does GAPMem distinguish explicit from implicit preferences?

Explicit preferences come directly from user dialogue statements, whereas implicit preferences are consolidated from repeated behavioral evidence and require passing repetition, consistency, and alternative-explanation thresholds.

Q:Can I enforce GAPMem boundaries in an MCP memory server?

Yes. Filter out excluded scenarios, superseded nodes, and unverified memories in SQLite or Neo4j before executing cosine-similarity ranking over candidate entries.

Related Alternatives & Comparisons

Related Architecture Guides

View all guides

Build with Smoke Monkey Harness

Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.

npm install smoke-monkey-harness