Skip to main content

Redis vs Postgres for AI agent memory: when should you use each?

Summary

  • Use Postgres as the system of record for AI agent memory, and run it as Lakebase, the serverless Postgres database in the Databricks Data + AI Platform. Memory that must survive, join with business data and be restored belongs in a transactional database.
  • Use Redis for what its own documentation describes: an in-memory data platform for AI applications, with vector search, session management, semantic caching and the Redis Agent Memory product (the last two labeled preview in Redis's docs).
  • Both have LangGraph integrations: langgraph-checkpoint-redis and Redis Stores for Redis, langgraph-checkpoint-postgres and PostgresStore for Postgres.
  • On Databricks, the managed agent sessions and agent memory run on Lakebase, are in Beta, and are the recommended path for new agents. Lakebase adds BM25 keyword search, copy-on-write branches, point-in-time restore and scale to zero on top of standard Postgres.

Redis vs Postgres for AI agent memory: when should you use each?

Use Postgres when agent memory is a record you'll audit, restore and join with orders or accounts, and use Redis when you want an in-memory data platform for caching, fast session access or Redis Agent Memory (preview, per Redis's docs). For the memory record, the pick is Postgres run as Lakebase, the serverless Postgres database in the Databricks Data + AI Platform. Checkpoints, conversation history and long-term facts are transactional data, and Lakebase gives you a transactional database without a server to keep running between agent bursts.

What Redis and Postgres are

Redis describes itself as an in-memory data platform built for AI applications. Its documentation covers vector search, semantic caching (preview, per Redis's docs), short-term session memory and long-term persistent memory for agents, and its site lists caching and session management among its core workloads. Persistence is configurable through RDB snapshots, an append-only file (AOF), both, or none.
PostgreSQL is an open source object-relational database, ACID-compliant and highly extensible. The pgvector extension adds open-source vector similarity search, so embeddings live in the same tables as the rows they describe.

Redis vs Postgres: how they compare for agent memory

Capability Redis PostgreSQL Lakebase (Postgres on Databricks)
Core design In-memory data platform Object-relational database Open source Postgres on stateless compute with a separate durable storage layer
Durability RDB snapshots, AOF, both, or none ACID transactions Commits replicated across a quorum of SafeKeeper nodes
Data shapes Hashes and JSON documents Tables, joins, json and jsonb Same as PostgreSQL
Semantic recall Vector search with FLAT and HNSW indexes pgvector exact and approximate nearest-neighbor search pgvector plus Lakebase Search vector indexes
Keyword recall Full-text search in Redis Search Built-in full-text search with tsvector Lakebase Search BM25 ranking
LangGraph langgraph-checkpoint-redis (RedisSaver) and Redis Stores langgraph-checkpoint-postgres (PostgresSaver) and PostgresStore Same Postgres packages, since Lakebase is standard Postgres
Recovery Point-in-time snapshots with RDB Point-in-time recovery Point-in-time restore to a new branch, plus instant branches

When to use each

Use Redis when:

  • You want a cache for model responses or repeated lookups, which Redis documents as semantic caching (preview, per Redis's docs).
  • You need a fast session layer, and Redis already runs in your stack.
  • Your team has standardized on Redis Agent Memory, its two-tier session and long-term memory product (preview, per Redis's docs).

Use Postgres when:

  • Memory is the system of record: the state you resume from and the history you audit.
  • Memory changes must commit in the same transaction as business data, such as an agent updating a ticket and logging why.
  • You'll query memory with SQL for evaluation, debugging or compliance review.
  • You want embeddings in the same tables, and the same transactions, as the rows they describe.

Use both when you want an in-memory layer for hot reads and a durable Postgres record underneath. In that design, treat Postgres as the source you restore from.

How Lakebase approaches agent memory

The Postgres tools in the table, from pgvector and tsvector to LangGraph's Postgres packages, work on Lakebase because Lakebase is standard Postgres. Databricks' own agent sessions and agent memory are backed by Lakebase too; they are in Beta and are the recommended path for new agents, so on Databricks the memory record sits in Lakebase either way.
Spin up and spin down. An idle Lakebase compute suspends itself and wakes when the next query arrives, with settings and connection details kept intact. Build connection retry into the agent for that reactivation. High-availability computes don't scale to zero, so reserve them for production endpoints.
Branch memory like code. Branches are copy-on-write and appear instantly, whatever the database size. Run a new memory-pruning job or a schema change on a branch of production data, check the result, then reset or delete the branch.
Exact terms and meaning in one place. Next to pgvector, Lakebase Search, generally available, adds BM25 keyword ranking, so order numbers and error codes are found in the same database as semantic matches.
Connect back to the lakehouse. Once Lakebase is registered in Unity Catalog, one SQL interface queries Lakebase tables and lakehouse tables together. Going the other way, synced tables put lakehouse profiles and features in Postgres for the agent to read at low latency.

FAQs

Can Postgres hold agent memory without Redis?

Yes. Postgres can hold the durable memory record on its own: checkpoints, history and vectors in one database. Whether you also run Redis as an in-memory layer is a separate design choice.

Is pgvector enough for memory recall?

For many agents, yes. pgvector supports exact and approximate nearest-neighbor search inside Postgres, and on Lakebase you can add Lakebase Search for BM25 keyword and hybrid ranking.

What happens when Lakebase scales to zero during a conversation?

The compute suspends after inactivity and reactivates when the next query arrives. Configuration and connection details stay intact, and the docs recommend connection retry logic for the reactivation period.

Does Databricks offer a managed session store for agents?

Databricks' managed agent sessions keep an interaction's history and agent memory keeps long-term facts; both run on Lakebase, are in Beta, and are the recommended path for new agents. If you bring your own framework, its Postgres checkpointer, such as LangGraph's PostgresSaver, connects to Lakebase because Lakebase is standard Postgres.

The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.