CLAUDE LABJP
FORK — Claude Code 2.1.212 changes what /fork does: it copies your conversation into a new background session with its own row in claude agents, so you can keep working. The old in-session subagent is now /subtaskLIMITS — WebSearch calls are now capped at 200 per session by default, and subagent spawns get the same 200 ceiling, so a runaway search or delegation loop stops on its ownMCPBG — MCP tool calls running past two minutes now move to the background automatically, keeping the session usable. Tune the threshold with CLAUDE_CODE_MCP_AUTO_BACKGROUND_MSPLANFIX — Fixed plan mode auto-running file-modifying Bash commands such as touch and rm without a permission prompt or an SDK canUseTool callbackSONNET5 — Claude Sonnet 5 is running on introductory pricing of $2 per million input tokens and $10 per million output. After August 31 it moves to $3 and $15IPO — Bankers are reportedly lining up investor meetings for Anthropic ahead of a possible public listing as soon as OctoberFORK — Claude Code 2.1.212 changes what /fork does: it copies your conversation into a new background session with its own row in claude agents, so you can keep working. The old in-session subagent is now /subtaskLIMITS — WebSearch calls are now capped at 200 per session by default, and subagent spawns get the same 200 ceiling, so a runaway search or delegation loop stops on its ownMCPBG — MCP tool calls running past two minutes now move to the background automatically, keeping the session usable. Tune the threshold with CLAUDE_CODE_MCP_AUTO_BACKGROUND_MSPLANFIX — Fixed plan mode auto-running file-modifying Bash commands such as touch and rm without a permission prompt or an SDK canUseTool callbackSONNET5 — Claude Sonnet 5 is running on introductory pricing of $2 per million input tokens and $10 per million output. After August 31 it moves to $3 and $15IPO — Bankers are reportedly lining up investor meetings for Anthropic ahead of a possible public listing as soon as October
Articles/API & SDK
API & SDK/2026-04-06Advanced

Building a Persistent Memory Agent with Claude API, pgvector, and Redis: A Complete

A complete guide to building production-ready persistent memory for Claude API agents using PostgreSQL + pgvector + Redis. Learn vector search, layered memory architecture, session management, and GDPR-compliant data handling.

Claude API115pgvector2PostgreSQL2Redismemory7agent13vector search2RAG4

Premium Article

Why Your AI Agent Needs Memory

If you've built chatbots or agents with the Claude API, you've likely run into this frustration: users have to re-explain themselves every session. Preferences, past decisions, ongoing projects—gone the moment a conversation ends.

The Claude API is stateless by design. Each request stands alone, and any prior context must be explicitly included in the messages array. This makes the API clean and composable, but it means you are responsible for building a memory system if you want your agent to feel intelligent over time.

This guide walks you through building a production-grade persistent memory system using:

  • PostgreSQL + pgvector — long-term memory with semantic vector search
  • Redis — short-term session memory with fast in-memory access
  • Claude API — reasoning engine that autonomously invokes memory tools

By the end, you'll have an agent that remembers user preferences, references past conversations, and continuously improves its responses the more it interacts with each person.


Architecture Overview: A Three-Layer Memory System

Human memory isn't monolithic. We have working memory that lasts seconds, episodic memory that captures experiences, and long-term semantic memory that persists for years. Your AI agent's memory can follow the same layered model.

Layer 1 — Short-Term Memory (Redis)

Stores the current session's message history. Expires via TTL (time to live) once the session is inactive, keeping Redis lean and cost-efficient. Redis is the right tool here because access speed is the priority—agents frequently look back at the last few messages.

Layer 2 — Long-Term Memory (PostgreSQL + pgvector)

Stores important information extracted from conversations: user preferences, key facts, learned skills, notable events. Each memory is embedded as a vector, so retrieval uses cosine similarity rather than exact keyword matching. This means queries like "does this user like concise answers?" return the right memories even if those exact words were never used.

Layer 3 — Episodic Memory (PostgreSQL)

Stores session summaries with timestamps. This enables recalling "what we discussed last month" at a coarser granularity, without storing every individual message forever.

Together, these three layers balance speed, precision, and storage cost for a realistic production system.


Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
The measured recall vs. p95 latency trade-off when tuning HNSW ef_search from 40 to 100
Cutting embedding API calls by roughly 60% with a Redis cache keyed on the query hash
Importance-score decay and 0.95-similarity dedup patterns that keep the memory table from bloating in production
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

API & SDK2026-07-09
When the RAG Started Being Confidently Wrong — Field Notes on Measuring Retrieval Misses With Groundedness
In a Claude API RAG, the answers stay fluent while the facts drift. Often the cause is a silent recall decay on the retrieval side, missing the document that holds the answer. Field notes on measuring groundedness and retrieval hit rate and walking the system back, with working code and real numbers.
API & SDK2026-06-19
Grounding Claude on Your Own Knowledge Base with search_result Blocks
How to stop your own RAG setup from losing track of which article it cited, using Claude's search_result content block and structured citations — with real numbers from running it across four sites.
API & SDK2026-05-05
Building an Internal Document Search Agent with Claude API — Hybrid RAG, Role-Based Access Control, and Audit Logging in Production
Build a production-grade internal document search agent using Claude API and Python. Covers hybrid RAG (pgvector + BM25), department-level RBAC via PostgreSQL RLS, and compliance-ready audit logging — with working code for each component.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →