Decorative background gradient
Back to Blog
Ai Agent MemoryVector Database RagLong Term Memory Llm

AI Agent Memory Systems — Short-Term, Long-Term, and Vector vs File-Based

How AI agent memory actually works — working context, session summaries, vector-based long-term memory, and when a file-based store is simpler.

AI Agent Memory Systems — Short-Term, Long-Term, and Vector vs File-Based

"Agent memory" gets used loosely to mean several different things — the current context window, a running summary, and persistent facts across sessions are all different problems with different correct solutions. Conflating them is what causes agents that either forget things they should remember or waste tokens re-loading things they don't need.

Working Memory: The Context Window Itself

Working memory is just whatever is currently in the model's context — inherently short-lived and hard-bounded by the context window size.

python

The important design decision isn't how to build working memory — it's what happens when it fills up. An agent with no overflow strategy either crashes or silently truncates from the front, losing whatever was there first (often the original task description).

Session Memory: A Running Summary of the Current Task

Session memory bridges the gap when a task spans more turns than comfortably fit in context — instead of re-sending the full turn-by-turn history, older turns get compacted into a summary.

python

Using a smaller, cheaper model for the summarization call itself keeps this compaction step from adding meaningful cost, since it happens repeatedly over a long session.

Long-Term Memory: Storage Is the Easy Part, Retrieval Is the Hard Part

Persisting data across sessions is trivial — write it to a database. The actual design problem is how the agent finds the right piece of stored information later, out of everything it's ever stored.

Vector-Based Retrieval for Fuzzy, Semantic Recall

python

This is the right tool for "what have we discussed related to this topic" — fuzzy, semantic recall where the exact wording of the original information isn't known in advance.

File-Based or Structured Retrieval for Exact Facts

python

For facts that must be retrieved reliably every time — a user's subscription tier, a project's configured settings — a direct key lookup is simpler, faster, and doesn't carry the failure mode of semantic search silently missing the right result because it was phrased unusually.

Why Relying on Vector Search Alone Causes Silent Failures

Semantic similarity search returns the most similar items to a query, not necessarily the correct or complete set. A structurally important fact that happens to be phrased in dissimilar language to the current query can simply not appear in the top results — with no error, no exception, just an agent that behaves as if it never learned that fact.

python

Combining both — guaranteed retrieval for facts that must always surface, best-effort semantic search for everything else — avoids the failure mode of either approach used alone.

Choosing a Design for a Given Agent

A customer support agent that needs to recall "what did we discuss with this user before" benefits from vector-based memory. The same agent needing to know "is this user on the Pro plan" should never rely on semantic search for that — it's a direct lookup. Most production agents need both layers, matched to the shape of what they're trying to remember.

Key Takeaways

Working memory, session memory, and long-term memory are three different problems — bounding context, compacting a running session, and persisting facts across sessions — that need different solutions, and long-term memory specifically needs both guaranteed structured lookup for facts that must always surface and vector-based semantic search for fuzzy recall, since relying on vector search alone causes silent, hard-to-detect recall failures.

Frequently Asked Questions

Do I need a vector database for AI agent memory?

Only if you need semantic similarity search over unstructured text — "find things related to this topic" rather than "look up this exact fact." For structured facts (user preferences, project metadata, settings) a plain file or database lookup by key is simpler, faster, and more reliable than embedding and searching for them.

What's the difference between session memory and long-term memory?

Session memory is scoped to the current task or conversation — a running summary that keeps a long agent run coherent without re-sending every prior turn. Long-term memory persists across separate sessions entirely, storing facts, preferences, or past decisions that should be available the next time the agent is invoked, even in an unrelated conversation.

Why does relying only on vector search for agent memory sometimes fail silently?

Semantic similarity search returns the most similar stored items, not necessarily the correct or complete ones — a fact phrased differently than the query, or a fact that's structurally important but semantically dissimilar to the current context, can simply not surface in the top results, with no error to indicate anything was missed.

How much conversation history should an agent keep verbatim versus summarized?

Keep the most recent several turns verbatim since they're most likely to be directly relevant to the next action, and summarize everything older than that threshold into a compact running summary. The exact cutoff depends on the task, but a fixed token budget (e.g. summarize anything pushing total context past 50,000 tokens) is simpler to reason about than a fixed turn count.

Working on something similar? Take a look at my services and case studies, or book a free call to talk about your idea.

Related Articles

Caching Strategies and Cache Invalidation — The Complete Guide
CachingSystem DesignPerformance

Caching Strategies and Cache Invalidation — The Complete Guide

A practical guide to caching strategies (cache-aside, write-through, write-behind) and the cache invalidation techniques that keep them from serving stale data.

September 8, 2026Read more →
Database Indexing and Read Replicas — A Practical Guide
DatabasePostgreSQLSystem Design

Database Indexing and Read Replicas — A Practical Guide

How to choose the right database indexes, avoid the ones that quietly hurt write performance, and scale reads with replicas without introducing replication lag bugs.

September 8, 2026Read more →
Load Balancing and Stateless Service Design — A Practical Guide
System DesignLoad BalancingScalability

Load Balancing and Stateless Service Design — A Practical Guide

How load balancers distribute traffic, why stateless services are what actually makes horizontal scaling work, and how to fix the sticky-session traps that quietly reintroduce state.

September 8, 2026Read more →
Session Stores and Database Connection Pooling Explained
BackendRedisDatabase

Session Stores and Database Connection Pooling Explained

Why in-memory sessions break horizontally scaled apps, how to move session state to Redis correctly, and how connection pooling keeps your database from falling over under concurrent load.

September 8, 2026Read more →
Vertical vs Horizontal Scaling: How to Choose and Implement Each
System DesignScalabilityArchitecture

Vertical vs Horizontal Scaling: How to Choose and Implement Each

A practical comparison of vertical and horizontal scaling — what each actually fixes, where each breaks down, and the architecture changes horizontal scaling requires that most guides skip.

September 8, 2026Read more →
AI Agent Guardrails and Safety — Preventing Prompt Injection and Runaway Actions
Ai Agent SafetyPrompt Injection DefenseAgent Guardrails

AI Agent Guardrails and Safety — Preventing Prompt Injection and Runaway Actions

Build practical guardrails for AI agents — prompt injection defenses, destructive-action confirmation, iteration caps, and permission scoping.

September 7, 2026Read more →

Trending Topics