---
title: "Agent Memory vs. memory middleware | Comparisons | SurrealDB"
description: "How Agent Memory compares to Mem0, Zep, Letta and other memory middleware, and why memory state belongs in one database with its history."
url: https://surrealdb.com/why/vs-memory-middleware
---

# Agent Memory vs. memory middleware

[Explore Agent Memory](https://surrealdb.com/agent-memory) [Start in Studio](https://studio.surrealdb.com/current/contexts)

**Middleware.** Mem0, Zep and Letta sit between the agent and its storage.

**The cost.** Separate stores add a service to run and a consistency gap.

**Agent Memory.** Memory on SurrealDB, with facts and their history written in one transaction.

1. ![Babcock](https://surrealdb.com/assets/static/babcock.lo4rnVg1.svg)
2. ![ING](https://surrealdb.com/assets/static/ing.X3I6S3_V.svg)
3. ![British Airways](https://surrealdb.com/assets/static/british-airways.KEsZiwV-.svg)
4. ![Nvidia](https://surrealdb.com/assets/static/nvidia.DaIEuMil.svg)
5. ![Apple](https://surrealdb.com/assets/static/apple.D5pq4flY.svg)
6. ![SpaceX](https://surrealdb.com/assets/static/spacex.CQJEk-IL.svg)
7. ![Samsung](https://surrealdb.com/assets/static/samsung.CH-vQgnb.svg)
8. ![adidas](https://surrealdb.com/assets/static/adidas.DdTC5qhk.svg)
9. ![Tencent](https://surrealdb.com/assets/static/tencent.paQmLxyy.svg)
10. ![Alibaba](https://surrealdb.com/assets/static/alibaba.B16idgfM.svg)
11. ![PolyAI](https://surrealdb.com/assets/static/poly-ai.c3w_fAg6.svg)
12. ![Later](https://surrealdb.com/assets/static/later.Ds736jFO.svg)
13. ![Verizon](https://surrealdb.com/assets/static/verizon.BI7CajdX.svg)
14. ![Liberty Mutual](https://surrealdb.com/assets/static/liberty-mutual.B7qOU1pd.svg)
15. ![Walmart](https://surrealdb.com/assets/static/walmart.BjDg_Sr8.svg)
16. ![Carrier](https://surrealdb.com/assets/static/carrier.D21gC6NX.svg)
17. ![Saks Fifth Avenue](https://surrealdb.com/assets/static/saks-fifth-avenue.COIDpLSb.svg)
18. ![San Francisco Compute Company](https://surrealdb.com/assets/static/sfcc.B7jlImq4.svg)
19. ![Shield AI](https://surrealdb.com/assets/static/shield-ai.pINZ0KJr.svg)
20. ![Wix](https://surrealdb.com/assets/static/wix.DvHhmoBi.svg)

THE LANDSCAPE

## A category with one shared limit

### Mem0

LLM-driven extraction and consolidation, with optional graph storage. Strong developer experience over a set of separate stores.

### Zep

Long-term memory with temporal knowledge graphs and entity extraction. The structure arrives as a separate service with its own consistency model.

### Letta (MemGPT)

A self-editing memory framework where the agent manages its own context window. Memory sits outside the transactional boundary.

THE COMPARISON

## A layer between the agent and its data. What the middleware adds, and what Agent Memory keeps in the database.

Agent Memory

Memory middleware

Consistency

Agent Memory

Memory middleware

Atomicity

One transaction Facts, documents, graph relationships, vectors and their history are written in one transaction.

Two systems Memory commits in the middleware, state in the database, separately.

Where state lives

In the database The application tier is stateless: every fact, vector and trace lives in SurrealDB.

In the service's stores Every memory operation goes through the service, then its own set of separate stores.

Operations

Stores to run

One database One SurrealDB instance holds graph, vector, document, relational and geospatial state.

Several stores A vector store, a document store and a graph engine that stay separate, behind a memory service.

Permissions

Deny by default Contexts isolate tenants and Scopes grant per verb, and a key can only narrow its grants.

Two models One permission model for memory, another for the data it refers to.

THE ALTERNATIVE

## Memory on the database

Transactions

### [ACID memory](https://surrealdb.com/docs/surrealql/transactions)

Facts, documents, graph relationships, vectors and their history are written in one transaction, so they cannot diverge.

How transactions work

Permissions

### [Deny-by-default permissions](https://surrealdb.com/docs/surrealdb/security)

Contexts isolate tenants, and Scopes grant per verb, so a key can only narrow what it may do.

Explore permissions

History

### [Memory with a history](https://surrealdb.com/agent-memory)

A new value closes the validity of the old one instead of overwriting it, so what the agent believed on a given date is one query.

Explore Agent Memory

HOW IT WORKS

## Recall and remember in one transaction. In SurrealDB, an agent's memory and the data it concerns are read and written together.

Copy

```
1BEGIN TRANSACTION;23-- Recall what the agent knows about this user4LET $context = SELECT fact, valid_from FROM memory5    WHERE agent = agent:support AND user = user:jaime6    ORDER BY valid_from DESC LIMIT 5;78-- Remember the outcome, beside the data it concerns9CREATE memory SET10    agent = agent:support,11    user = user:jaime,12    fact = "Moved to the Memory+ plan",13    source = conversation:4471,14    valid_from = time::now();1516COMMIT TRANSACTION;
```

TRUSTED BY

## Enterprise teams building on SurrealDB

[See more case studies](https://surrealdb.com/casestudies)

### [Three data stores collapsed into one](https://surrealdb.com/customer/samsung)

![Samsung](https://surrealdb.com/assets/static/4c58b81e7b3c9466.C_Hv0eml.svg)

### [An AI assistant for 10,000 technicians](https://surrealdb.com/customer/verizon)

![Verizon](https://surrealdb.com/assets/static/18b99996c689000f.B5PQ-nI9.svg)

### [Nine backend tools consolidated into one](https://surrealdb.com/customer/tencent)

![Tencent](https://surrealdb.com/assets/static/401d8346058682c8.DqM87mst.svg)

### [Low-latency RAG, under the customer's control](https://surrealdb.com/customer/polyai)

![PolyAI](https://surrealdb.com/assets/static/c5fa07c66cd05131.BnC7wHcc.svg)

### [45 million recommendation queries a month](https://surrealdb.com/customer/saks)

![Saks Fifth Avenue](https://surrealdb.com/assets/static/saks-fifth-avenue-white.pDJ9HGmf.svg)

## Memory middleware, answered

How does Agent Memory differ from Mem0 or Zep?

Mem0 and Zep are middleware layers between the agent and its storage, abstracting over a vector store, a document store and a graph engine that stay separate. Agent Memory is the stateless application tier on SurrealDB, so facts, documents, graph relationships, vectors and their history are written in one transaction.

Can I use LangChain or CrewAI with SurrealDB instead of their built-in memory?

Where does Agent Memory keep its state?

THE PLATFORM

## Everything an application and its agents know. Five surfaces, one engine.

Database

Document, graph, vector, time-series and relational in one engine.

![Five data models as dotted tiles: documents, graph, vector, time-series and relational](https://surrealdb.com/assets/static/platform-database.DUdumYDz.avif)

Read more

[Database](https://surrealdb.com/surrealdb)

Agent Memory

What an agent learns, with its source and its time, in the same engine.

![A timeline of remembered facts, each with its source](https://surrealdb.com/assets/static/platform-agent-memory.Cvv8D5Wl.avif)

Read more

[Agent Memory](https://surrealdb.com/agent-memory)

Cloud

Managed clusters in the regions you choose, scaled on demand.

![Clusters in three regions on a world map, each running or scaling](https://surrealdb.com/assets/static/platform-cloud.--QZnaVi.avif)

Read more

[Cloud](https://surrealdb.com/cloud)

Studio

Query, explore and design the schema from the browser.

![A SurrealQL query in Studio and the schema graph under it](https://surrealdb.com/assets/static/platform-studio.7ykBFNLq.avif)

Read more

[Studio](https://surrealdb.com/studio)

MCP

Every model that speaks MCP reaches the database and the memory directly.

![Three models connected through MCP to the database and Agent Memory](https://surrealdb.com/assets/static/platform-mcp.D_oH0_wm.avif)

Read more

[MCP](https://surrealdb.com/mcp)

IN PRODUCTION

## Trusted at scale. Samsung, Nvidia, Verizon, Tencent, and Walmart run on SurrealDB.

14,000+

Developers building on SurrealDB Cloud

4M+

Developers building on SurrealDB worldwide

FROM THE TEAMS

> SurrealDB gives us a foundation where we can unify semantic search, knowledge graphs, and AI-driven decision making without stitching together multiple systems. Collapsing responsibility into SurrealDB has become our default engineering posture.

*Justin Foley*

VP of Engineering, Later

GET STARTED

## Memory on the database. Agent Memory writes facts, vectors and their history in one SurrealDB transaction, with every answer traceable to its source.

[Explore Agent Memory](https://surrealdb.com/agent-memory) [Start in Studio](https://studio.surrealdb.com/current/contexts)

![ISO 27001](https://surrealdb.com/assets/static/iso.BzQy4FFy.svg)

![AICPA SOC 2 Type 2](https://surrealdb.com/assets/static/aicpa-soc.CE_YjqhK.svg)

![Cyber Essentials](https://surrealdb.com/assets/static/cyber-essentials.CtbmbYfL.svg)

![GDPR](https://surrealdb.com/assets/static/gdpr.IadR7loS.svg)

![Cyber Essentials Plus](https://surrealdb.com/assets/static/cyber-essentials-plus.Cl5P05xe.svg)

```json
{"@context":"https://schema.org","@type":"Organization","@id":"https://surrealdb.com/#organization","name":"SurrealDB","url":"https://surrealdb.com","logo":"https://surrealdb.com/assets/static/logo.BG7_TG2b.svg","description":"SurrealDB is the context and memory layer for AI agents. A multi-model database for documents, graphs, vectors, and time-series.","foundingDate":"2022","legalName":"SurrealDB Ltd","identifier":{"@type":"PropertyValue","propertyID":"GB-COH","value":"13615201"},"address":{"@type":"PostalAddress","streetAddress":"3rd Floor, 1 Ashley Road","addressLocality":"Altrincham","addressRegion":"Cheshire","postalCode":"WA14 2DT","addressCountry":"GB"},"contactPoint":[{"@type":"ContactPoint","contactType":"customer support","email":"support@surrealdb.com","url":"https://surrealdb.com/contact","availableLanguage":"English"},{"@type":"ContactPoint","contactType":"sales","email":"info@surrealdb.com","url":"https://surrealdb.com/contact","availableLanguage":"English"},{"@type":"ContactPoint","contactType":"security","email":"security@surrealdb.com","url":"https://surrealdb.com/.well-known/security.txt","availableLanguage":"English"},{"@type":"ContactPoint","contactType":"legal","email":"legal@surrealdb.com","url":"https://surrealdb.com/legal","availableLanguage":"English"}],"hasCertification":[{"@type":"Certification","name":"SOC 2 Type 2"},{"@type":"Certification","name":"GDPR"},{"@type":"Certification","name":"Cyber Essentials Plus"},{"@type":"Certification","name":"ISO 27001"}],"owns":[{"@type":"SoftwareApplication","name":"SurrealDB","url":"https://surrealdb.com/surrealdb"},{"@type":"SoftwareApplication","name":"Agent Memory","url":"https://surrealdb.com/agent-memory"}],"knowsAbout":["multi-model databases","document databases","graph databases","vector search","time-series databases","SurrealQL","Agent Memory","real-time databases","embedded databases","context layer","graph ontology","distributed database","knowledge graphs","distributed transaction protocols","highly-scalable databases"],"sameAs":["https://www.wikidata.org/wiki/Q124316308","https://github.com/surrealdb/surrealdb","https://twitter.com/surrealdb","https://www.youtube.com/@surrealdb","https://www.linkedin.com/company/surrealdb","https://discord.gg/surrealdb","https://www.reddit.com/r/surrealdb","https://www.instagram.com/surrealdb","https://medium.com/surrealdb","https://dev.to/surrealdb"]}
```

```json
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://surrealdb.com"},{"@type":"ListItem","position":2,"name":"Vs memory middleware","item":"https://surrealdb.com/why/vs-memory-middleware"}]}
```

```json
{"@context":"https://schema.org","@type":"FAQPage","mainEntity":[{"@type":"Question","name":"How does Agent Memory differ from Mem0 or Zep?","acceptedAnswer":{"@type":"Answer","text":"Mem0 and Zep are middleware layers between the agent and its storage, abstracting over a vector store, a document store and a graph engine that stay separate. Agent Memory is the stateless application tier on SurrealDB, so facts, documents, graph relationships, vectors and their history are written in one transaction."}},{"@type":"Question","name":"Can I use LangChain or CrewAI with SurrealDB instead of their built-in memory?","acceptedAnswer":{"@type":"Answer","text":"Yes. Agent Memory has adapters for LangChain, OpenAI Agents, the Vercel AI SDK, Claude Code and n8n, and any other MCP-compatible client can use its seven MCP tools or its REST API."}},{"@type":"Question","name":"Where does Agent Memory keep its state?","acceptedAnswer":{"@type":"Answer","text":"In SurrealDB. Agent Memory is the stateless application tier on top, and the database holds the graph, vector, document, relational and geospatial state, so there is no separate memory store to keep in step."}}]}
```
