Representing memory as a directed labeled graph to support relational reasoning
Mem0g extends Mem0 with graph structure, modeling memory as a directed labeled graph
Each entity node contains:
When new triples arrive, the system processes them through these steps:
Mem0g supports two recall paths simultaneously.
Introducing graph structure incurs additional overhead:
G = (V, E, L). It suits scenarios requiring cross-entity relational reasoning, such as timeline reconstruction, social relationship tracking, and complex event causal chains.
Basic Graph Components
| Element | Role | Example |
|---|---|---|
| Node V | Entity | Alice, San_Francisco |
| Edge E | Relation | lives_in |
| Label L | Semantic type | Alice: Person, San_Francisco: City |
- Type classification: Person, Location, Event, etc.
- Embedding vector e_v: Semantic representation
- Metadata: Creation timestamp
t_v
(v_s, r, v_d), where v_s is the source node, v_d is the target node, and r is the relation label.
Extraction Pipeline
- Entity Extractor: Identifies information units such as people, places, objects, concepts, events, attributes
- Relation Generator: Analyzes language and context to select appropriate relation labels (e.g.,
lives_in,prefers,owns,happened_on)
Update and Conflict Detection
When new triples arrive, the system processes them through these steps:
1
Compute Embeddings
Generate vector representations for both source and target nodes.
2
Node Matching
Match existing nodes within threshold
t; create new nodes if missing.3
Conflict Detection
Identify potentially conflicting relations.
4
Update Decision
LLM determines whether old relations are obsolete; marks as invalid rather than physical deletion.
Soft deletion preserves temporality: Obsolete relations are not physically deleted, only marked invalid for subsequent temporal reasoning.
Retrieval: Dual-Channel Strategy
Mem0g supports two recall paths simultaneously.
| Channel | Suitable Queries | Mechanism |
|---|---|---|
| Entity-centric | Questions about a person/place | Find anchor node, expand incoming/outgoing edges to build subgraph |
| Semantic triple | Broad conceptual questions | Match query vector against text encoding of all triples via similarity |
Implementation Choices
| Component | Technology Used |
|---|---|
| Graph database | Neo4j |
| Extraction / update model | GPT-4o-mini (with function calling) |
| Embeddings | Dense vectors |
Cost of Graph Memory
Introducing graph structure incurs additional overhead:
- Average token usage ~14k per conversation (double Mem0's 7k)
- Retrieval p50 latency ~0.476s (vs. Mem0's 0.148s)