Skip to main content
Architecture

Mem0g Graph Memory

Representing memory as a directed labeled graph to support relational reasoning

Mem0g extends Mem0 with graph structure, modeling memory as a directed labeled graph 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

ElementRoleExample
Node VEntityAlice, San_Francisco
Edge ERelationlives_in
Label LSemantic typeAlice: Person, San_Francisco: City
Each entity node contains:
  • Type classification: Person, Location, Event, etc.
  • Embedding vector e_v: Semantic representation
  • Metadata: Creation timestamp t_v
Relations are represented as triples: (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

Natural language input
   ↓
[Entity Extractor] → Identifies entities and types
   ↓
[Relation Generator] → Determines semantic relations between entities
   ↓
Structured triples
  • 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.
ChannelSuitable QueriesMechanism
Entity-centricQuestions about a person/placeFind anchor node, expand incoming/outgoing edges to build subgraph
Semantic tripleBroad conceptual questionsMatch query vector against text encoding of all triples via similarity

Implementation Choices

ComponentTechnology Used
Graph databaseNeo4j
Extraction / update modelGPT-4o-mini (with function calling)
EmbeddingsDense 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)
However, compared to Zep graph memory which often reaches 600k tokens, Mem0g still maintains an order-of-magnitude advantage.
See specific scores and comparisons: Benchmark Results; for latency/cost details: Latency & Cost.