Bottom line: Below roughly 5,000 memory writes per month, SaaS Memory is usually cheaper all-in. Above ~10k writes/month or when you need private deployment, self-hosted Redis + Postgres (or TencentDB in China) typically wins. For engines: Redis for session/hot memory, Postgres (pgvector) for semantic recall, TencentDB when you need managed compliance domestically.
Last updated August 7, 2026. Price bands come from 2026 public cloud and Mem0/Zep-style SaaS pages; your invoice will vary by region, discounts, and usage.
Why “database rent” misleads Agent Memory budgets
Teams often treat Agent Memory as “one more database.” In practice you pay for at least three different things:
- Write cost—summaries after each turn, embeddings, cross-session merges—driving LLM and vector compute bills.
- Storage cost—hot data in Redis, warm rows in Postgres, cold archives in object storage; a single tier is usually the most expensive mistake.
- Recall cost—how many lookups per user message, reranking, and whether latency must stay under 100ms; high QPS can make Redis cost more than Postgres.
Monthly Memory total = writes (model + embedding) + storage (DB + backup) + recall (QPS × latency tier) + ops labor
SaaS vendors (Mem0, Zep, LangMem Cloud) bundle the last three into seats or MAU pricing. Self-hosted means you own every line item—SaaS saves ops at small scale; self-hosted saves marginal cost at scale.
How to classify Agent Memory (What)
Before comparing Redis, Postgres, and TencentDB, align on memory layers—or you will store session IDs in a vector index or run full-text search on Redis.
| Layer | Typical content | Lifetime | Best store |
|---|---|---|---|
| L1 working | Current session context, tool state, short preferences | Minutes–hours | Redis / in-process cache |
| L2 episodic | Conversation summaries, task history, preference tags | Days–months | Postgres JSONB / document store |
| L3 semantic | Embedded knowledge, RAG chunks, shared facts | Long-term | Postgres pgvector / vector DB |
Asymmetric takeaway: For most coding agents and support bots, L2 episodic memory is the cost center because writes include LLM summarization—not because the vector database is inherently expensive.
Core compare: self-hosted vs SaaS Memory (2026 monthly anchors)
Three bands: side project, small-team beta, ~10k MAU production. Technical layer only (no model API), includes basic monitoring and backup. USD bands; TencentDB row for RMB teams in China.
| Approach | Side project | Small team | ~10k MAU | Ops load |
|---|---|---|---|---|
| Mem0 / Zep SaaS | $0–29 | $49–99 | $199–499+ | Low (vendor SLA) |
| Self-hosted Redis + Postgres (VM) | $25–45 | $60–120 | $150–280 | Medium (patching, backups) |
| TencentDB Redis + PostgreSQL | ¥300–600 | ¥800–1,500 | ¥2,000–4,500 | Low–medium (managed, domestic) |
| Redis only (all-in) | $15–30 | $40–80 | RAM explodes—avoid prod all-in | Medium |
Rule of thumb: <5k writes/month with no dedicated SRE → SaaS wins on total cost. >30k writes/month or strict data residency → self-hosted or TencentDB.
Redis vs Postgres vs TencentDB for AI Memory
| Engine | Strength | Typical AI Memory use | Main risk |
|---|---|---|---|
| Redis | Sub-ms KV, TTL, pub/sub | L1 session state, rate limits, hot profile cache | RAM cost; durability misconfig loses memory |
| Postgres + pgvector | ACID, rich queries, vectors + relations | L2 tables + L3 vectors in one DB; audit, multi-tenant | Needs HNSW tuning at large vector scale |
| TencentDB | Managed domestic compliance, backups, alerts | Mainland-facing agents instead of DIY VM databases | 15–30% premium vs DIY VM; cross-border latency |
- Redis (L1) + Postgres pgvector (L2+L3)—most examples for Claude Code / LangChain stacks.
- TencentDB Redis + PostgreSQL—same app pattern for China production and filing/compliance needs.
- SaaS Memory only—two-week demos with zero DB ops; plan export to Postgres later.
How to choose (decision matrix)
| If you are… | Pick | Why |
|---|---|---|
| Solo dev proving an agent | SaaS free tier → migrate later | Zero ops, fast write/recall validation |
| Domestic B2B agent, data stays in China | TencentDB + your app layer | Managed compliance without 24/7 DBA |
| High-frequency coding agent | Redis L1 + Postgres L2 | Hot state in Redis, auditable summaries in SQL |
| Knowledge RAG agent | Postgres pgvector or dedicated vector DB | At 1M+ vectors tune Postgres or add Qdrant |
| 10+ person team with SRE | Redis + Postgres on K8s | Lowest marginal cost, unified observability |
Recommended stacks
Stack A — fastest MVP (2 weeks)
- Mem0 or Zep Cloud for episodic + semantic memory
- App calls SaaS API; session state on Upstash Redis free tier
- Monthly tech anchor: $0–49
Stack B — portable self-hosted (most teams)
- Redis: session + 24h hot memory with TTL
- Postgres: users, summaries, pgvector embeddings
- Nightly jobs compress L2 → L3 to control embedding spend
- Monthly tech anchor: $60–150 (small team)
Stack C — China production
- TencentDB Redis 2GB + TencentDB PostgreSQL standard
- COS object storage for cold conversation archives
- App in same-region VPC to avoid cross-zone egress
- Monthly tech anchor: ¥1,200–2,500
Common pitfalls
- Embedding everything—L2 summaries often need no vector; embeddings are a silent budget killer.
- Redis as permanent memory—eviction or restart feels like amnesia to users.
- Ignoring recall QPS—ten vector queries per message hurts more than storing 100k rows.
- One API key for whole team on SaaS—audit and rate limits break; compliance risk rises.
- Postgres without pooling—parallel tool calls exhaust connections; memory “randomly fails.”
- Overseas SaaS for mainland users—latency plus residency; TencentDB is often simpler.
Action plan (7 steps)
- Map three layers—what lives in L1/L2/L3, TTL, and access rules.
- Estimate monthly writes—conversations × summaries/embeddings per turn.
- Pick the crossover—<5k writes start SaaS; >30k or private deploy → self-hosted/TencentDB.
- Choose storage combo—default Redis + Postgres; swap to TencentDB in China prod.
- Cap recall budget—max DB/vector queries per user message as a code constant.
- Run a 14-day soak test—real dialogs; watch storage growth and P95 latency.
- Define export format—even on SaaS, keep JSON/Parquet export path to Postgres.
FAQ
What is the minimum budget for self-hosted Agent Memory?
Technical layer can hit $25–40/month on a small VM plus managed Redis/Postgres tiers. Add 2–4 hours/week ops and SaaS at $29 may be cheaper for tiny teams.
Can Redis alone power AI Memory?
Only for L1 working memory and caches. Long episodic and semantic recall need Postgres or a vector store.
How far does Postgres pgvector scale?
For sub-million vectors at 1536 dims with tuned HNSW, most agent products are fine. 90% of teams never outgrow it.
How much more is TencentDB vs DIY Postgres on a VM?
Typically 15–30% higher list price but includes backup, monitoring, patches, and HA—often lower total cost without a DBA.
Can SaaS Memory migrate to self-hosted?
Most vendors export users and memory blocks via API. Pipeline: export → Postgres L2 tables → re-embed semantic chunks into pgvector.
Conclusion
Whether self-hosted or SaaS Agent Memory is cheaper depends on monthly writes, recall frequency, and ops time—not list prices of Redis vs Postgres. A pragmatic 2026 path: SaaS for MVP, Redis + Postgres self-hosted after validation, TencentDB for compliant China production.
Before launch ask: if memory writes double next month, which line item breaks first? Embedding, Redis RAM, or SaaS seats—that answer tells you whether to stay on SaaS or migrate.
Worked example: one coding agent, 30 active users
Assume 30 developers use a Claude Code–style agent daily, 40 turns per user per month, and 30% of turns trigger an episodic summary (L2) plus embedding (L3). That is roughly 360 summary writes and ~500k embedding tokens per month.
- SaaS path: Mem0 Pro–class tier ~$49 + embedding API ~$8–15 → ~$60–70/mo with near-zero ops.
- Self-hosted path: Small VM $24 + managed Redis $10 + Postgres $25 + embedding ~$12 + ~3h ops → ~$75–90/mo cash, higher if you bill engineering time.
At this scale SaaS still wins on total cost of ownership. Crossover appears when the same pattern hits 300+ daily active agent users or 10k+ monthly memory writes—then Postgres storage and SaaS seat pricing compound faster than a single DBA-hour-efficient stack.
What to monitor after you ship Memory
Regardless of Redis, Postgres, or TencentDB, attach metrics before users complain about “forgetful” agents:
- write_latency_p95—summary + embed pipeline; spikes predict bill surprises.
- recall_qps_per_session—if this climbs without product changes, fix retrieval loops in agent code.
- memory_bytes_per_user—unbounded L2 JSON grows faster than vector tables.
- saas_export_age_days—if on SaaS, test restore to Postgres quarterly.
Teams running agents on remote Mac build nodes often co-locate a small Redis on the same VPC as the agent gateway to keep L1 recall under 5ms while Postgres stays regional.
Further reading
安定した Cloud Mac ノードでエージェント開発
Agent Memory をローカル検証する際、M4 のユニファイドメモリは embedding・ベクトル検索・Xcode を並行しやすいです。専用ノードは月額で、試行錯誤のためのハード購入を避けられます。