Production-Grade Agent Memory Framework for Agentic AI
Project description
๐ง GraphMem
The Human Brain for Your AI Agents
"Memory is the treasury and guardian of all things." โ Cicero
GraphMem is the first memory system that thinks like a human brain. It doesn't just store dataโit forgets, consolidates, prioritizes, and evolves exactly like biological memory does.
This is the future of enterprise AI agents.
๐งฌ Why GraphMem Changes Everything
The Problem with Current AI Memory
Every production AI agent faces the same crisis:
Day 1: "Who is the CEO?" โ "Elon Musk" โ
Day 100: Context window: OVERFLOW ๐ฅ
Day 365: "Who is the CEO?" โ "John... or was it Jane... maybe Elon?" ๐คฏ
Vector databases don't forget. They accumulate garbage until your agent drowns in irrelevant, conflicting, outdated information.
The GraphMem Solution: Memory That Thinks
GraphMem implements the four pillars of human memory:
| Human Brain | GraphMem | Why It Matters |
|---|---|---|
| ๐ง Forgetting Curve | Memory Decay | Irrelevant memories fade naturally |
| ๐ Neural Networks | Knowledge Graph | Relationships between concepts |
| โญ Importance Weighting | PageRank Centrality | Hub concepts (Elon Musk) > peripheral ones |
| โฐ Episodic Memory | Temporal Validity | "CEO in 2015" vs "CEO now" |
๐ Revolutionary Features
1. ๐ฐ๏ธ Point-in-Time Memory (Temporal Validity)
"Who was CEO in 2015?" โ No other memory system can answer this.
from datetime import datetime
from graphmem import GraphMem, MemoryConfig
memory = GraphMem(config)
# GraphMem tracks WHEN facts are true
memory.ingest("John Smith was CEO of ACME from 2010 to 2018")
memory.ingest("Jane Doe became CEO of ACME in July 2018")
# Point-in-time queries - like human episodic memory!
memory.query("Who was CEO in 2015?") # โ "John Smith" โ
memory.query("Who is CEO now?") # โ "Jane Doe" โ
memory.query("Who was CEO in 2019?") # โ "Jane Doe" โ
Use Cases:
- ๐ "What contracts were active last quarter?"
- ๐ "Who was our legal counsel before 2020?"
- ๐ "What was our strategy during COVID?"
2. โญ PageRank Centrality (Hub Detection)
GraphMem uses Google's PageRank algorithm to identify important entities:
Importance Formula: ฯ(e) = w1ยทf1 + w2ยทf2 + w3ยทf3 + w4ยทf4
where:
f1 = Temporal recency (recent = important)
f2 = Access frequency (used often = important)
f3 = PageRank centrality (well-connected = important) โ NEW!
f4 = User feedback (explicit signals)
Result: "Elon Musk" (connected to Tesla, SpaceX, Neuralink) scores 3x higher than "Austin, Texas" (connected only to Tesla HQ).
# PageRank automatically identifies hub entities
Elon Musk: PR = 1.000 โโโโโโโโโโโโโโโโโโโโ # Hub - many connections
Tesla: PR = 0.774 โโโโโโโโโโโโโโโ # Important company
Austin: PR = 0.520 โโโโโโโโโโ # Just a location
3. ๐ง Self-Evolution (Like Human Memory)
memory.evolve() # This single line triggers:
| Mechanism | What Happens | Human Equivalent |
|---|---|---|
| Decay | Old unused memories fade (importance โ 0) | Forgetting curve |
| Consolidation | 5 mentions of "user likes Python" โ 1 strong memory | Sleep consolidation |
| Rehydration | Contradictions resolved ("CEO is John" โ "CEO is Jane") | Memory updating |
| Importance Scoring | PageRank recalculated | Synaptic strengthening |
Result: 80% memory reduction while keeping what matters.
4. ๐ข Enterprise Multi-Tenant Isolation
Each user gets their own brain. Complete data separation.
# Alice's memory
alice = GraphMem(config, user_id="alice", memory_id="chat")
alice.ingest("I work at Google as a senior engineer")
# Bob's memory (COMPLETELY ISOLATED)
bob = GraphMem(config, user_id="bob", memory_id="chat")
bob.ingest("I'm a doctor at Mayo Clinic")
# Alice can NEVER see Bob's data
alice.query("What does Bob do?") # โ "No information found" โ
# Bob can NEVER see Alice's data
bob.query("Where does Alice work?") # โ "No information found" โ
Architecture:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Neo4j Global Instance โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ USER: alice โ USER: bob โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ๐ข Google โ ๐ค Alice โ โ โ ๐ฅ Mayo Clinic โ ๐ค Bob โ โ
โ โ โ โ โ โ โ โ โ
โ โ ๐ผ Senior Engineer โ โ โ ๐ฉบ Doctor โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Redis Cache (Also Isolated by user_id) โ
โ alice:query:* alice:search:* โ bob:query:* bob:search:* โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ก The 3-Line API
from graphmem import GraphMem, MemoryConfig
# Initialize (works with ANY OpenAI-compatible API)
config = MemoryConfig(
llm_provider="openai_compatible",
llm_api_key="your-key",
llm_api_base="https://openrouter.ai/api/v1",
llm_model="google/gemini-2.0-flash-001",
embedding_provider="openai_compatible",
embedding_api_key="your-key",
embedding_api_base="https://openrouter.ai/api/v1",
embedding_model="openai/text-embedding-3-small",
)
memory = GraphMem(config)
# That's it. 3 methods:
memory.ingest("Tesla is led by CEO Elon Musk...") # โ Extract knowledge
memory.query("Who is the CEO?") # โ Ask questions
memory.evolve() # โ Let memory mature
๐๏ธ Architecture
High-Level Overview
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ง GraphMem โ
โ The Human Brain for AI Agents โ
โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ ingest() โ โ query() โ โ evolve() โ โ
โ โ Learn new โ โ Recall + โ โ Mature โ โ
โ โ knowledge โ โ Reasoning โ โ memories โ โ
โ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โ
โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ
โผ โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ MULTI-TENANT LAYER โ
โ โ
โ Every operation is scoped by: user_id + memory_id โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ USER: alice โ โ USER: bob โ โ
โ โ memory_id: chat_1 โ โ memory_id: chat_1 โ โ
โ โ memory_id: notes โ โ memory_id: work โ โ
โ โ โโโโโโโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโโโโโโ โ โ
โ โ Complete isolation โ
โ โ Complete isolation โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ธ๏ธ KNOWLEDGE GRAPH ENGINE โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ โ
โ โ ENTITY EXTRACTION โ โ RELATIONSHIP โ โ COMMUNITY โ โ
โ โ โ โ DETECTION โ โ DETECTION โ โ
โ โ โข LLM-powered โ โ โ โ โ โ
โ โ โข Named entities โ โ โข Semantic links โ โ โข Louvain algo โ โ
โ โ โข Type inference โ โ โข Temporal bounds โ โ โข Auto-clustering โ โ
โ โ โข Descriptions โ โ โข [t_s, t_e] โ โ โข LLM summaries โ โ
โ โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ โ
โ โ ENTITY RESOLUTION โ โ SEMANTIC โ โ QUERY ENGINE โ โ
โ โ โ โ SEARCH โ โ โ โ
โ โ โข Alias merging โ โ โ โ โข Multi-hop โ โ
โ โ โข Canonicalizationโ โ โข Vector index โ โ โข Cross-cluster โ โ
โ โ โข 95% accuracy โ โ โข Cosine sim โ โ โข Context assemblyโ โ
โ โ โข user_id aware โ โ โข user_id filter โ โ โข LLM synthesis โ โ
โ โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ EVOLUTION ENGINE โ
โ (Human Memory Simulation) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โญ PAGERANK CENTRALITY โ โ
โ โ โ โ
โ โ PR(A) = (1-d) + d ร ฮฃ(PR(Ti)/C(Ti)) where d = 0.85 โ โ
โ โ โ โ
โ โ Hub Detection: โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ Elon Musk โโโโโโฌโโโโ Tesla โโโโ Austin โ โ โ
โ โ โ (HUB) โโโโโ SpaceX โโโโ Hawthorne โ โ โ
โ โ โ PR=1.00 โโโโโ Neuralink โ โ โ
โ โ โ โ โ โ
โ โ โ PageRank: Elon(1.00) > Tesla(0.77) > SpaceX(0.77) > Austin(0.52)โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโ โ
โ โ MEMORY DECAY โ โ CONSOLIDATION โ โ TEMPORAL VALIDITY โ โ
โ โ โ โ โ โ โ โ
โ โ Ebbinghaus Curve: โ โ LLM-based merging: โ โ Time bounds: โ โ
โ โ โ โ โ โ โ โ
โ โ I(t) = Iโยทe^(-ฮปt) โ โ 5 mentions โ โ โ valid_from: t_s โ โ
โ โ โ โ 1 strong memory โ โ valid_until: t_e โ โ
โ โ ฮป = decay rate โ โ โ โ โ โ
โ โ โ โ 80% reduction โ โ is_valid_at(t) โ โ
โ โ Unused โ archived โ โ while keeping value โ โ supersede(end) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ Importance Formula: ฯ(e) = w1ยทf1 + w2ยทf2 + w3ยทf3 + w4ยทf4 โ
โ โโโ f1: Recency (0.3) - Recent access = important โ
โ โโโ f2: Frequency (0.3) - Used often = important โ
โ โโโ f3: PageRank (0.2) - Well-connected = important (HUB) โ
โ โโโ f4: User signal (0.2) - Explicit importance โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐พ STORAGE LAYER โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ CHOOSE YOUR STORAGE BACKEND โโ
โ โ โโ
โ โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โโ
โ โ โ InMemory โ โ ๐ฅ TURSO ๐ฅ โ โ NEO4J โ โโ
โ โ โ (Default) โ โ (Embedded) โ โ (Enterprise) โ โโ
โ โ โโโโโโโโโโโโโโโค โโโโโโโโโโโโโโโโโโโค โโโโโโโโโโโโโโโโโโโโโโโค โโ
โ โ โ No persist โ โ SQLite file โ โ Full graph DB โ โโ
โ โ โ Zero config โ โ Works offline โ โ ACID + clustering โ โโ
โ โ โ Dev/testing โ โ Cloud sync opt โ โ Native Cypher โ โโ
โ โ โ Python vec โ โ Native vec ๐ โ โ HNSW vec ๐ โ โโ
โ โ โ โ โ ~10ms search โ โ ~5ms search โ โโ
โ โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โโ
โ โ โ โ โ โโ
โ โ โ ALL BACKENDS GET THE SAME FEATURES: โ โโ
โ โ โ โ
Multi-tenant โ
Temporal validity โ โโ
โ โ โ โ
PageRank โ
Memory evolution โ โโ
โ โ โ โ
Communities โ
Entity resolution โ โโ
โ โ โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโ โโ
โ โ โ โโ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ๐๏ธ NEO4J GRAPH โ โ โก REDIS CACHE โ โ
โ โ (Enterprise Option) โ โ (Optional Layer) โ โ
โ โ โ โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ ENTITY NODES โ โ โ โ EMBEDDING CACHE โ โ โ
โ โ โ โข id, name, type โ โ โ โ โ โ โ
โ โ โ โข embedding[1536] โ โ โ โ Key: emb:{text_hash} โ โ โ
โ โ โ โข user_id โ ISOLATION โ โ โ โ TTL: 24 hours โ โ โ
โ โ โ โข memory_id โ โ โ โ 3x faster embeddings โ โ โ
โ โ โ โข importance, access_count โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ
โ โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ QUERY CACHE โ โ โ
โ โ โ RELATIONSHIP EDGES โ โ โ โ (Multi-Tenant!) โ โ โ
โ โ โ โข valid_from โ TEMPORAL โ โ โ โ โ โ โ
โ โ โ โข valid_until โ VALIDITY โ โ โ โ Key: query:{user}:* โ โ โ
โ โ โ โข user_id โ ISOLATION โ โ โ โ TTL: 5 minutes โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ Instant repeat: 0ms โ โ โ
โ โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ
โ โ โ VECTOR INDEX (HNSW) โ โ โ Auto-Invalidation: โ โ
โ โ โ Dimension: 1536, cosine โ โ โ โข ingest() โ clear cache โ โ
โ โ โ ~5ms similarity search โ โ โ โข evolve() โ clear cache โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โข clear() โ clear cache โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ๐ฅ TURSO (SQLite) - RECOMMENDED! โ โ ๐ฅ TURSO CACHE โ โ
โ โ (Edge/Offline Option) โ โ (Built-in to TursoStore) โ โ
โ โ โ โ โ โ
โ โ pip install "agentic-graph-mem[libsql]" โ โโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ โ โ No Redis needed! โ โ โ
โ โ โ
Persists to local .db file โ โ โ SQLite-based cache โ โ โ
โ โ โ
Works completely offline โ โ โ TTL support โ โ โ
โ โ โ
Optional Turso Cloud sync โ โ โ Multi-tenant keys โ โ โ
โ โ โ
Native F32_BLOB vector search โ โ โ Survives restarts โ โ โ
โ โ โ
~10ms vector similarity โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ โ โ โ
โ โ SAME FEATURES AS NEO4J: โ โ Great for: โ โ
โ โ โข Temporal validity โ
โ โ โข Edge AI devices โ โ
โ โ โข PageRank centrality โ
โ โ โข Offline agents โ โ
โ โ โข Multi-tenant isolation โ
โ โ โข Mobile apps โ โ
โ โ โข Point-in-time queries โ
โ โ โข Cost-sensitive deploys โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ค LLM PROVIDERS โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โ
โ โ OpenAI โ โ Azure โ โAnthropic โ โ Groq โ โ Together โ โ Ollama โ โ
โ โ GPT-4o โ โ OpenAI โ โ Claude โ โ Llama โ โ AI โ โ Local โ โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ OpenRouter (100+ Models) โ โ
โ โ google/gemini-2.0-flash โ anthropic/claude-3.5 โ meta-llama/llama-3 โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Data Flow: Ingest โ Query โ Evolve
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ INGEST FLOW โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Input Document Knowledge Extraction Storage
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโ
โ "Tesla is โ โโโโโโโโโโโถ โ LLM extracts: โ โโโโโโโโโโโถ โ Neo4j OR โ
โ led by CEO โ โ โ โ ๐ฅTurso โ
โ Elon Musk" โ โ Entities: โ โ โ
โโโโโโโโโโโโโโโโ โ โข Tesla [Org] โ โ (Tesla)โโโโ
โ โ โข Elon Musk [Per]โ โ โ โ
โ โ โ โ โผ โ
โ โ Relations: โ โ CEO_OF โ
โ โ โข (Elon)โCEOโโถ โ โ โ โ
โ โ (Tesla) โ โ โผ โ
โ โ โ โ (Elon) โ
โ โ Temporal: โ โโโโโโโโโโโโโ
โ โ โข valid_from=now โ โ
โ โ โข valid_until=โ โ โผ
โ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโ
โ โ โ Redis OR โ
โ โ โ TursoCacheโ
โ โผ โโโโโโโโโโโโโ
โ โโโโโโโโโโโโโโโโโโโโ
โ โ Entity Resolutionโ
โ โ โ
โ โ "Elon" = "Musk" โ
โ โ = "Elon Musk" โ
โ โ โ Canonical: "Elon Musk"
โ โโโโโโโโโโโโโโโโโโโโ
โ
โโโโ user_id + memory_id tagged on ALL nodes/edges
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ QUERY FLOW โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
User Question Cache Check Retrieval Answer
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโ โโโโโโโโโโโโโ โโโโโโโโโโโโ
โ "Who is the โ โโโโถ โ Redis โ HIT โ โ โโโโถ โ "Elon โ
โ CEO?" โ โ Cache โ โโโโถ โ SKIP! โ โ Musk" โ
โ โ โ โ โ โ โ โ
โ user: alice โ โ Key: โ โโโโโโโโโโโโโ โโโโโโโโโโโโ
โ mem: chat_1 โ โ query: โ
โโโโโโโโโโโโโโโโ โ alice: โ MISS
โ โ chat_1: โ โโโโถ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ {hash} โ โ RETRIEVAL โ
โ โโโโโโโโโโโโโ โ โ
โ โ 1. Embed query โ
โ โ 2. Vector search (Neo4j/Turso)โ
โ โ WHERE user_id = 'alice' โ
โ โ AND memory_id = 'chat_1' โ
โ โ 3. Get related edges โ
โ โ 4. Filter by temporal โ
โ โ is_valid_at(now) โ
โ
โ โ 5. Rank by importance โ
โ โ (PageRank score) โ
โ โ 6. Build context โ
โ โ 7. LLM generates answer โ
โ โ 8. Cache result in Redis โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโ user_id ensures Alice NEVER sees Bob's data
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ EVOLVE FLOW โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Trigger Evolution Cycle Result
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโ
โ memory โ โโโโถ โ โ โ โ
โ .evolve() โ โ 1. PAGERANK RECALCULATION โ โ โข Hubs โ
โ โ โ Build graph from edges โ โ identifiedโ
โ user: alice โ โ Compute PR scores โ โ โ
โ โ โ Update importance โ โ โข 80% โ
โโโโโโโโโโโโโโโโ โ โ โ memory โ
โ โ 2. MEMORY DECAY โ โ reduced โ
โ โ I(t) = Iโ ร e^(-ฮปt) โ โ โ
โ โ Archive if I < 0.1 โ โ โข Conflictsโ
โ โ โ โ resolved โ
โ โ 3. CONSOLIDATION โ โ โ
โ โ Find similar memories โ โ โข Cache โ
โ โ LLM merges duplicates โ โ cleared โ
โ โ โ โ โ
โ โ 4. REHYDRATION โ โโโโโโโโโโโโโโ
โ โ Update contradictions โ
โ โ "CEO=John" โ "CEO=Jane" โ
โ โ โ
โ โ 5. CACHE INVALIDATION โ
โ โ Clear Redis for user โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโ Only evolves Alice's data (user_id scoped)
Multi-Tenant Data Isolation
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ MULTI-TENANT ARCHITECTURE โ
โ (Works identically with Neo4j, Turso, or InMemory) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ STORAGE BACKEND (Neo4j / Turso / InMemory) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ GLOBAL VECTOR INDEX โ โ
โ โ (Entity.embedding, HNSW) โ โ
โ โ โ โ
โ โ Query: db.index.vector.queryNodes( โ โ
โ โ 'entity_embedding_index', โ โ
โ โ $top_k * 10, โ Fetch extra for filtering โ โ
โ โ $query_embedding โ โ
โ โ ) โ โ
โ โ WHERE node.user_id = $user_id โ ISOLATION โ โ
โ โ AND node.memory_id = $memory_id โ โ
โ โ RETURN node LIMIT $top_k โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ USER: alice โ โ USER: bob โ โ
โ โ โ โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ memory: chat_1 โ โ โ โ memory: chat_1 โ โ โ
โ โ โ โโโโโโโ โโโโโโโ โ โ โ โ โโโโโโโ โโโโโโโ โ โ โ
โ โ โ โAliceโโโโโถโGoogleโ โ โ โ โ โ Bob โโโโโถโMayo โ โ โ โ
โ โ โ โโโโโโโ โโโโโโโ โ โ โ โ โโโโโโโ โClinicโ โ โ โ
โ โ โ โ โ โ โ โ โ โโโโโโโ โ โ โ
โ โ โ โผ โ โ โ โ โผ โ โ โ
โ โ โ โโโโโโโโโโ โ โ โ โ โโโโโโโโ โ โ โ
โ โ โ โEngineerโ โ โ โ โ โDoctorโ โ โ โ
โ โ โ โโโโโโโโโโ โ โ โ โ โโโโโโโโ โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ memory: notes โ โ โ โ memory: work โ โ โ
โ โ โ โโโโโโโโ โโโโโโโ โ โ โ โ โโโโโโโโโ โโโโโโโโ โ โ โ
โ โ โ โPythonโโโโถโ ML โ โ โ โ โ โPatientโโโโถโRecordโ โ โ โ
โ โ โ โโโโโโโโ โโโโโโโ โ โ โ โ โโโโโโโโโ โโโโโโโโ โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ REDIS CACHE (ISOLATED) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ โ
โ โ Alice's Keys: Bob's Keys: โ โ
โ โ โโโโโโโโโโโโโ โโโโโโโโโโ โ โ
โ โ query:alice:chat_1:abc123 query:bob:chat_1:xyz789 โ โ
โ โ search:alice:chat_1:def456 search:bob:chat_1:uvw321 โ โ
โ โ search:alice:notes:ghi789 search:bob:work:rst654 โ โ
โ โ โ โ
โ โ Shared (same text = same embedding): โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ emb:sha256_of_text โ [0.1, 0.2, ...] โ โ
โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โ
Alice can NEVER access Bob's cached queries โ
โ โ
Bob can NEVER access Alice's cached queries โ
โ โ
Embeddings shared (efficiency) - no sensitive data in embeddings โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Temporal Validity Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โฐ TEMPORAL VALIDITY โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ Every RELATIONSHIP has a time interval: [valid_from, valid_until] โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ CEO TRANSITIONS โ โ
โ โ โ โ
โ โ Timeline: 2010 2015 2018 2020 2025 โ โ
โ โ โ โ โ โ โ โ โ
โ โ โผ โผ โผ โผ โผ โ โ
โ โ โ โ
โ โ John โโCEO_OFโโโถ ACME โโโโโโโโโโโโโโโโโ โ โ
โ โ valid: [2010-01-01, 2018-06-30] โ โ โ
โ โ โ โ โ
โ โ Jane โโCEO_OFโโโถ ACME โโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ valid: [2018-07-01, NULL] โ NULL = still current โ โ
โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ Point-in-Time Queries: โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ โ
โ โ Q: "Who was CEO in 2015?" โ โ
โ โ โ โ
โ โ 1. Find edges WHERE relation_type = 'CEO_OF' โ โ
โ โ 2. Filter: is_valid_at(datetime(2015, 6, 1)) โ โ
โ โ โโโ John: valid_from=2010 โค 2015 โค valid_until=2018 โ
โ โ
โ โ โโโ Jane: valid_from=2018 > 2015 โ โ โ
โ โ 3. Return: "John Smith" โ โ
โ โ โ โ
โ โ Q: "Who is CEO now?" โ โ
โ โ โ โ
โ โ 1. Filter: is_valid_at(datetime.utcnow()) โ โ
โ โ โโโ John: valid_until=2018 < now โ โ โ
โ โ โโโ Jane: valid_from=2018 โค now, valid_until=NULL โ
โ โ
โ โ 2. Return: "Jane Doe" โ โ
โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ API: โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ โ
โ โ # Check validity at any point in time โ โ
โ โ edge.is_valid_at(datetime(2015, 6, 1)) # True/False โ โ
โ โ โ โ
โ โ # Mark relationship as ended โ โ
โ โ edge.supersede(end_time=datetime(2018, 6, 30)) โ โ
โ โ โ โ
โ โ # Query edges at specific time โ โ
โ โ store.query_edges_at_time( โ โ
โ โ memory_id="company_kb", โ โ
โ โ query_time=datetime(2015, 6, 1), โ โ
โ โ relation_type="CEO_OF" โ โ
โ โ ) โ โ
โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
File Structure
graphmem/
โโโ core/
โ โโโ memory.py # GraphMem main class
โ โโโ memory_types.py # MemoryNode, MemoryEdge (+ temporal validity)
โ โโโ exceptions.py # Custom exceptions
โ
โโโ graph/
โ โโโ knowledge_graph.py # LLM-based extraction
โ โโโ entity_resolver.py # Deduplication (user_id aware)
โ โโโ community_detector.py # Topic clustering
โ
โโโ evolution/
โ โโโ memory_evolution.py # Evolution orchestrator
โ โโโ importance_scorer.py # PageRank + multi-factor scoring
โ โโโ decay.py # Ebbinghaus forgetting curve
โ โโโ consolidation.py # LLM-based merging (user_id aware)
โ โโโ rehydration.py # Contradiction resolution
โ
โโโ retrieval/
โ โโโ query_engine.py # Multi-hop + cross-cluster
โ โโโ retriever.py # Context retrieval
โ โโโ semantic_search.py # Vector search (user_id filtered)
โ
โโโ stores/
โ โโโ neo4j_store.py # Graph + temporal + HNSW vector index
โ โโโ turso_store.py # SQLite + temporal + native vector (NEW!)
โ โโโ memory_store.py # In-memory (default)
โ โโโ redis_cache.py # Multi-tenant cache
โ
โโโ llm/
โ โโโ providers.py # 10+ LLM providers
โ โโโ embeddings.py # Embedding + cache
โ
โโโ context/
โโโ context_engine.py # Context assembly
โโโ chunker.py # Semantic chunking
โโโ multimodal.py # JSON, CSV, Markdown, Code, Web
๐ Why Enterprise Teams Choose GraphMem
Production Scale Performance
| Metric | Naive RAG | GraphMem | Advantage |
|---|---|---|---|
| 1K conversations | ๐ฅ Context overflow | โ Bounded | Handles growth |
| 10K entities | O(n) = 2.3s | O(1) = 50ms | 46x faster |
| 1 year history | 3,650 entries | ~100 consolidated | 97% reduction |
| Entity conflicts | Duplicates | Auto-resolved | Clean data |
| Temporal queries | โ Impossible | โ Native | Unique capability |
Cost Efficiency
Naive RAG: Send entire history every query = $$$$$
GraphMem: Retrieve only relevant subgraph = $
โโโโโ
99% savings
Enterprise Requirements
| Requirement | GraphMem |
|---|---|
| Multi-tenant isolation | โ
user_id on every node |
| ACID transactions | โ Neo4j backend |
| Horizontal scaling | โ Neo4j cluster + Redis |
| Audit trail | โ Temporal validity history |
| Data sovereignty | โ Self-hosted option |
๐ง Installation
# Core only (in-memory, for development)
pip install agentic-graph-mem
# ๐ฅ RECOMMENDED: Turso (SQLite persistence + offline)
pip install "agentic-graph-mem[libsql]"
# Enterprise: Neo4j + Redis (full graph power)
pip install "agentic-graph-mem[all]"
๐ฏ Which Backend Should You Choose?
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ STORAGE BACKEND DECISION TREE โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ "Do you need data to persist between restarts?" โ
โ โ โ
โ โโโโโโโโโโโโโโดโโโโโโโโโโโโโ โ
โ โ โ โ
โ NO YES โ
โ โ โ โ
โ โผ โผ โ
โ โโโโโโโโโโโโโโโโโโโ "Do you need complex graph queries โ
โ โ InMemory โ (multi-hop traversals, GDS algorithms)?" โ
โ โ โ โ โ
โ โ โข Development โ โโโโโโโโโโโโโโดโโโโโโโโโโโโโ โ
โ โ โข Testing โ โ โ โ
โ โ โข Quick POCs โ NO YES โ
โ โ โข Zero config โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโ โผ โผ โ
โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โ โ ๐ฅ TURSO โ โ NEO4J โ โ
โ โ โ โ โ โ
โ โ โข Edge/offline โ โ โข Enterprise โ โ
โ โ โข Mobile apps โ โ โข Complex graphsโ โ
โ โ โข Single-user โ โ โข Multi-tenant โ โ
โ โ โข No server โ โ โข Horizontal โ โ
โ โ โข Simple setup โ โ scaling โ โ
โ โ โข SQLite-based โ โ โข ACID + clusterโ โ
โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ "Add high-performance caching?" โ
โ โ โ
โ โโโโโโโโโดโโโโโโโโ โ
โ YES NO โ
โ โ โ โ
โ โผ โผ โ
โ โโโโโโโโโโโโโ โโโโโโโโโโโโโ โ
โ โ + REDIS โ โ Neo4j onlyโ โ
โ โ Cache โ โ (still โ โ
โ โ โ โ great!) โ โ
โ โโโโโโโโโโโโโ โโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Feature Comparison
| Feature | InMemory | Turso ๐ฅ | Neo4j |
|---|---|---|---|
| Persistence | โ | โ SQLite file | โ Server |
| Works Offline | โ | โ | โ |
| Vector Search | Python | Native F32_BLOB |
Native HNSW |
| Cloud Sync | โ | โ Optional | โ |
| Setup Complexity | None | One file path | Server required |
| Multi-hop Queries | โ NetworkX | โ NetworkX | โ Native Cypher |
| PageRank | โ | โ | โ |
| Temporal Validity | โ | โ | โ |
| Multi-tenant | โ | โ | โ |
| Best For | Dev/Test | Edge/Offline | Enterprise |
๐ Complete Examples
Basic Usage (In-Memory)
from graphmem import GraphMem, MemoryConfig
config = MemoryConfig(
llm_provider="openai_compatible",
llm_api_key="sk-or-v1-your-key",
llm_api_base="https://openrouter.ai/api/v1",
llm_model="google/gemini-2.0-flash-001",
embedding_provider="openai_compatible",
embedding_api_key="sk-or-v1-your-key",
embedding_api_base="https://openrouter.ai/api/v1",
embedding_model="openai/text-embedding-3-small",
)
memory = GraphMem(config)
# Learn
memory.ingest("Tesla is led by CEO Elon Musk. Founded in 2003.")
memory.ingest("SpaceX, founded by Elon Musk in 2002, builds rockets.")
memory.ingest("Neuralink develops brain-computer interfaces.")
# Recall
response = memory.query("What companies does Elon Musk lead?")
print(response.answer) # "Elon Musk leads Tesla, SpaceX, and Neuralink."
# Mature
memory.evolve() # Consolidates, decays, re-ranks importance
With Turso (SQLite Persistence + Offline Support) ๐
from graphmem import GraphMem, MemoryConfig
# Turso gives you persistence without running Neo4j!
# Data survives restarts, works offline, can sync to cloud
config = MemoryConfig(
llm_provider="openai_compatible",
llm_api_key="sk-or-v1-your-key",
llm_api_base="https://openrouter.ai/api/v1",
llm_model="google/gemini-2.0-flash-001",
embedding_provider="openai_compatible",
embedding_api_key="sk-or-v1-your-key",
embedding_api_base="https://openrouter.ai/api/v1",
embedding_model="openai/text-embedding-3-small",
# ๐ฅ Just add a file path - that's it!
turso_db_path="my_agent_memory.db",
# Optional: Sync to Turso Cloud for backups/multi-device
# turso_url="https://your-db.turso.io",
# turso_auth_token="your-token",
)
memory = GraphMem(config, user_id="alice")
# All data persists in my_agent_memory.db
memory.ingest("Alice is a software engineer at Google.")
memory.save() # Data survives restart!
# Later, in a new session:
memory2 = GraphMem(config, user_id="alice")
response = memory2.query("Where does Alice work?") # Still knows! โ
Why Turso over InMemory?
- โ Data survives restarts (SQLite file)
- โ Works offline (no network needed)
- โ Optional cloud sync (Turso Cloud)
- โ No server to manage (unlike Neo4j)
- โ Per-user database files (true isolation)
Production: Multi-Tenant Chat System
from graphmem import GraphMem, MemoryConfig
# Base config (shared across all users)
base_config = MemoryConfig(
llm_provider="openai_compatible",
llm_api_key="sk-or-v1-your-key",
llm_api_base="https://openrouter.ai/api/v1",
llm_model="google/gemini-2.0-flash-001",
embedding_provider="openai_compatible",
embedding_api_key="sk-or-v1-your-key",
embedding_api_base="https://openrouter.ai/api/v1",
embedding_model="openai/text-embedding-3-small",
# Production storage
neo4j_uri="neo4j+ssc://xxx.databases.neo4j.io",
neo4j_username="neo4j",
neo4j_password="your-password",
redis_url="redis://default:password@your-redis.cloud.redislabs.com:17983",
)
class ChatService:
def get_memory(self, user_id: str, session_id: str) -> GraphMem:
"""Each user gets isolated memory."""
return GraphMem(
base_config,
user_id=user_id, # โ Complete isolation
memory_id=session_id, # โ Per-session memory
)
def chat(self, user_id: str, session_id: str, message: str) -> str:
memory = self.get_memory(user_id, session_id)
# Store user message as memory
memory.ingest(message)
# Generate response using memory
response = memory.query(message)
return response.answer
# Usage
service = ChatService()
# Alice's session (isolated)
alice_response = service.chat("alice", "session_1", "I'm a software engineer at Google")
alice_response = service.chat("alice", "session_1", "What do I do?") # โ "Software engineer at Google"
# Bob's session (completely separate)
bob_response = service.chat("bob", "session_1", "I'm a doctor")
bob_response = service.chat("bob", "session_1", "What does Alice do?") # โ "No information found"
Temporal Queries: Track Changes Over Time
from datetime import datetime
from graphmem.core.memory_types import MemoryEdge
from graphmem.stores.neo4j_store import Neo4jStore
store = Neo4jStore(uri, user, password)
# Track CEO transitions
john_ceo = MemoryEdge(
id="john_ceo",
source_id="john_smith",
target_id="acme_corp",
relation_type="CEO_OF",
valid_from=datetime(2010, 1, 1),
valid_until=datetime(2018, 6, 30), # John left
)
jane_ceo = MemoryEdge(
id="jane_ceo",
source_id="jane_doe",
target_id="acme_corp",
relation_type="CEO_OF",
valid_from=datetime(2018, 7, 1),
valid_until=None, # Current CEO
)
# Query by time period
ceo_2015 = store.query_edges_at_time(
memory_id="company_kb",
query_time=datetime(2015, 6, 1),
relation_type="CEO_OF"
)
# โ Returns John Smith's edge
ceo_now = store.query_edges_at_time(
memory_id="company_kb",
query_time=datetime.utcnow(),
relation_type="CEO_OF"
)
# โ Returns Jane Doe's edge
# Mark relationship as ended
store.supersede_relationship(
memory_id="company_kb",
edge_id="jane_ceo",
end_time=datetime(2025, 12, 31) # Jane leaves
)
๐งช Run the Evaluation
cd graphmem/evaluation
python run_eval.py
Uses MultiHopRAG dataset (2,556 QA samples, 609 documents).
๐ฌ The Science Behind GraphMem
Ebbinghaus Forgetting Curve
importance(t) = importance_0 ร e^(-ฮป ร (t - last_access))
Just like human memory, unused information fades exponentially.
PageRank for Entity Importance
PR(A) = (1-d) + d ร ฮฃ(PR(Ti)/C(Ti))
Hub entities (connected to many concepts) are more importantโexactly like neural hubs in the brain.
Temporal Validity
valid(r, t) = 1[t_s(r) โค t โค t_e(r)]
Every relationship has a time interval, enabling episodic memory recall.
๐ญ Deployment Tiers
| Scale | Users | Strategy | Infrastructure |
|---|---|---|---|
| Development | 1 | InMemory (no persistence) | Nothing required |
| Personal/Edge | 1-10 | ๐ฅ Turso (local SQLite) | Single .db file per user |
| Startup | 1-100 | Turso + Cloud sync | Turso Cloud (free tier) |
| Growth | 100-10K | Neo4j + Redis | Neo4j Aura Pro + Redis Cloud |
| Enterprise | 10K-100K | Sharded by region | Neo4j Enterprise Cluster |
| Global | 100K+ | Database per tenant | Multi-region Neo4j Fabric |
When to Use Each Storage
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ STORAGE SELECTION GUIDE โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ ๐งช DEVELOPMENT / TESTING โ
โ โโโถ InMemory (default) โ
โ โข pip install agentic-graph-mem โ
โ โข config = MemoryConfig(...) # No storage params needed โ
โ โ
โ ๐ฑ EDGE / OFFLINE / SIMPLE APPS โ
โ โโโถ ๐ฅ Turso (RECOMMENDED) โ
โ โข pip install "agentic-graph-mem[libsql]" โ
โ โข config = MemoryConfig(..., turso_db_path="agent.db") โ
โ โข Works offline, data persists, no server! โ
โ โ
โ ๐ข ENTERPRISE / HIGH-SCALE โ
โ โโโถ Neo4j + Redis โ
โ โข pip install "agentic-graph-mem[all]" โ
โ โข config = MemoryConfig(..., neo4j_uri=..., redis_url=...) โ
โ โข Complex graph queries, horizontal scaling, ACID โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฆ Dependencies
# Core (no external services, in-memory only)
pip install agentic-graph-mem
# With Turso (SQLite persistence, offline-first) - SIMPLEST OPTION!
pip install agentic-graph-mem libsql
# With Neo4j persistence (full graph database)
pip install "agentic-graph-mem[neo4j]"
# With Redis caching (high-performance cache)
pip install "agentic-graph-mem[redis]"
# Full production stack (Neo4j + Redis)
pip install "agentic-graph-mem[all]"
Storage Backend Comparison
| Backend | Persistence | Vector Search | Graph Algorithms | Offline | Use Case |
|---|---|---|---|---|---|
| InMemory | โ | โ (in Python) | โ (NetworkX) | โ | Development, testing |
| Turso | โ | โ (native) | โ (NetworkX) | โ | Edge/offline AI, simple deploys |
| Neo4j | โ | โ (HNSW) | โ (GDS, native) | โ | Enterprise, complex graphs |
| Redis | โ ๏ธ (volatile) | โ | โ | โ | Caching layer only |
๐ฏ The Future of AI Memory
GraphMem isn't just another vector database wrapper. It's a paradigm shift:
| Old Way | GraphMem Way |
|---|---|
| Store everything | Remember what matters |
| Static forever | Evolves over time |
| No relationships | Rich knowledge graph |
| "Who is CEO?" | "Who was CEO in 2015?" |
| One user fits all | Enterprise multi-tenant |
| Hope for the best | PageRank prioritization |
The agents of tomorrow will have memories that think.
๐ค Contributing
We're building the future of AI memory. Join us!
- ๐ Report bugs
- ๐ก Request features
- ๐ Submit PRs
๐ License
MIT License - see LICENSE.
๐ Acknowledgments
- Inspired by cognitive neuroscience research on human memory
- Built on Neo4j, Redis, Turso (libSQL), and OpenAI
- PageRank algorithm by Larry Page and Sergey Brin
- Turso team for the amazing embedded SQLite with vector search
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentic_graph_mem-1.8.2.tar.gz.
File metadata
- Download URL: agentic_graph_mem-1.8.2.tar.gz
- Upload date:
- Size: 140.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad39efb93d7e03b9f7b51239480849b1554bcbf69cee53112b3b6f988c90ea6c
|
|
| MD5 |
1828506e2e1d9b899fbecfef69b11439
|
|
| BLAKE2b-256 |
057dd4126e32aad09a26c9d1843b28b1ce30a5c998608c5d64d20a61cfa92036
|
File details
Details for the file agentic_graph_mem-1.8.2-py3-none-any.whl.
File metadata
- Download URL: agentic_graph_mem-1.8.2-py3-none-any.whl
- Upload date:
- Size: 151.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1697e0125bab2b6c56bdbc338c5950d454be207db603cd9ac375980dc4028ba5
|
|
| MD5 |
0c6d6193756edcd74a2794dac8c12f31
|
|
| BLAKE2b-256 |
07bd2285811479fe67f93c7386f9f62d7902de3986f8594200420c07a1350a62
|