Courses · The Ambush Method

Pick your exam.

Every guide follows the same method: short daily sessions, the traps each topic sets, and exam-style questions with an explanation for every option.

  • 100% free · no paywalls, subscriptions or ads
  • 30–60 min a day
  • Exam-style questions
  • Taught in English

Agent Memory on Databricks: Context Window vs Vector Index vs Lakebase

Agent memory on Databricks study card: context window vs vector index vs Lakebase persistent store, with a practice card about an agent that forgets an asset number

Picture an IT helpdesk agent. On the first turn the employee says, “My laptop is asset LT-0931 and the VPN keeps dropping.” The agent asks a couple of questions, checks a known-issues page, suggests a fix. Three turns later the employee says, “Okay, that didn’t work, please open a ticket.” And the agent replies: “Sure! What’s your asset number?”

Nothing crashed. No error in the logs. The agent simply didn’t have the number anymore. That small, annoying moment is what agent memory on Databricks is about, and it maps to an exam objective that reads almost like a riddle: “Configure a persistent datastore to store and retrieve intermediate memory or structured information.” In my book this is the section where the agent finally remembers across turns, and here I’ll walk you through it the way I’d explain it to a friend studying 30-60 minutes a day.

If you are new to the exam, start with my Databricks Generative AI Engineer Associate study guide. This post also builds on two earlier ones: Databricks Agent Framework and MLflow Tracing (what makes something an agent) and AI agent tools on Databricks (how the agent gets its verbs). Tools let it act. Memory lets it keep track of what it already did.

Why this objective is a trap, not a definition

When an exam scenario says “the agent forgets something from earlier in the conversation,” the answers usually offer you three places to put the missing fact:

  • A model with a bigger context window, so more of the conversation fits.
  • The vector index the agent already searches for documents.
  • A persistent datastore the agent writes to and reads back every turn.

Two of those feel right and are wrong, and each one catches a different kind of reader. If you are new to LLMs, “memory” sounds like “context window,” so a forgetful agent needs a bigger one. If you have spent weeks building RAG, you reach for the index, because storing things and getting them back is literally what it does. Both instincts put the fact somewhere that can’t hold it the way the task needs.

The ambush idea I use everywhere on this site applies perfectly here: don’t memorize “the answer is Lakebase.” Learn the one question that sorts every option, and the scenario can change costumes as much as it likes.

Agent memory on Databricks: three places a fact can live

I explain this with three pieces of furniture, because they make the differences hard to forget.

The desk: the context window

The context window is the desk the model works on during one call. Whatever is on it is in view for exactly that call. Then the desk is wiped, and the next call starts on a bare surface. If an agent ever seemed to “remember” something, it’s because your code put it back on the desk by re-sending it.

A bigger desk holds more paper at once. It does not hold anything longer. Wiping is what a desk does, so a scenario about forgetting across turns is never solved by adding room. I covered context windows from the model selection side in how to choose an LLM on Databricks; here the point is simpler: size is not persistence.

The library: the vector index

The vector index is a library. You walk in with a question, search by meaning, and walk out with the passages that match. That is retrieval, and it is exactly right when the agent needs to look something up in a large body of shared documents, like the known-issues pages in my helpdesk example. If that part feels shaky, my posts on Databricks Vector Search (now branded AI Search) and RAG on Databricks cover it.

But you don’t go to a library to write down what one employee told you three minutes ago. The index answers “what do our documents say about VPN drops,” not “what asset number did this person just give me.” Pushing per-conversation facts into it is asking a reference library to also be your diary, and it mixes private, short-lived scraps into a store meant for stable, shared knowledge.

The notebook: a persistent datastore

The third place is a notebook the agent keeps next to the desk. It isn’t wiped between calls, because it lives outside the call entirely, in a database. And it isn’t a corpus you search across; it holds this conversation’s state, and this user’s facts, under their own names. The asset number goes in the notebook on turn one. On turn four, the agent reads the notebook and the number is simply there.

That is what the objective means by “a persistent datastore for intermediate memory or structured information”: a store that outlives the turn and holds the running state, the extracted fields, the decisions so far, whatever the conversation needs to stay coherent.

The two-question sort

Whenever a scenario asks where a fact should go, ask two questions, in this order.

  • Does it need to outlive this call? If not, it stays on the desk, in the prompt, and you’re done.
  • If it does, is it a shared document to search by meaning, or this conversation’s (or this user’s) own state? Documents go to the index. State goes to the persistent store.

Most agent memory mistakes, on the exam and in real projects, are a fact filed by habit instead of by those two questions. Conversation state ends up in the index because retrieval was the tool already wired in.

Short-term vs long-term memory: read the names slowly

Databricks splits the notebook into two kinds of page, and the names are a trap if you read them fast. The thing to lock in first: both are persistent. Both outlive the call. Neither one is the context window.

  • Short-term memory is the state of one conversation. It’s kept under a conversation identifier (a thread or session id) and reloaded at the start of every turn, so a single chat stays coherent from the first message to the last. “Short-term” refers to its scope, one conversation, not to how long it lasts.
  • Long-term memory spans conversations. A user’s standing preference, a past decision, an ongoing project: anything that should still be true the next time they come back.

So the axis between them is scope, not permanence. If an answer option calls the context window “short-term memory,” it has confused the desk with a page of the notebook. That’s your tell.

Lakebase: the notebook has a name on Databricks

On Databricks, the notebook is Lakebase, a fully managed Postgres database built into the platform. The fact that it’s Postgres matters. Agent memory is many small, fast reads and writes: every turn, load this conversation’s state, write the update, move on. That is transactional (OLTP) work, which is what Postgres is built for, and not what the analytical stores you’ve used so far are built for.

When I wrote the book, the main pattern was self-managed: you point a framework’s checkpointer (LangGraph’s Postgres checkpointer, for example) at your own Lakebase instance and pass the same thread id on every turn. That still works, but the current Databricks docs label self-managed memory as a legacy approach and recommend, for new agents, the managed agent sessions and agent memory stores, which Databricks runs on Lakebase for you. At the time I’m writing this they are in Beta, so details can change.

The managed version lines up neatly with the two kinds of page:

  • Agent sessions hold one conversation: the ordered messages, tool calls and results the agent replays to continue it. That’s short-term memory.
  • Agent memory holds durable facts and preferences that the agent recalls in later, separate conversations. That’s long-term memory.

Here is a small sketch adapted from the patterns in the Databricks docs, using the AgentKit SDK. Read it for the shape, not the syntax:

from databricks.sdk import WorkspaceClient
from databricks_agentkit import AgentKitClient

agentkit = AgentKitClient(WorkspaceClient())

# Short-term: one conversation, read back in order every turn.
sessions = agentkit.session_stores.create("helpdesk-agent-sessions")
session = sessions.add(actor_id="user-123", session_id="ticket-77")
session.append_items([{"type": "message", "role": "user",
                       "content": "My laptop is asset LT-0931 and the VPN keeps dropping."}])
history = [i.data for i in session.list_items(order_by="create_time asc")]

# Long-term: a durable fact this user will still care about next month.
memory = agentkit.memory_stores.create("helpdesk-agent-memory")
memory.put(actor_id="user-123", path="/preferences/contact.md",
           content="Prefers updates by email, not phone.",
           description="Contact preference")
memory.search(actor_id="user-123", query="how does this user want to be contacted")

Two details in there are worth knowing for the exam and for real life. First, the session is read back in order, by its id, to rebuild context each turn. That’s the “same id, same conversation” mechanism. Second, every memory call is scoped to an actor_id. The docs are explicit that you should set it in trusted code from the verified user identity, never let the model or the end user choose it, and use separate stores when tenants need strict isolation, because the actor id separates data but isn’t access control on its own.

You’ll notice long-term memory is recalled with a natural-language search. Doesn’t that make it a vector index after all? No, and this is a nice nuance. The search runs over one actor’s own memory entries, not over your shared document corpus. The library is still for documents everyone shares. The notebook is still this user’s, even if it has a good index of its own pages.

Where Delta fits (and where it doesn’t)

A Delta table is persistent too, so it shows up as a distractor. You could write conversation state to one, but Delta is the analytical store: built for big scans and batch history, not for a fast read-modify-write on every turn. Its place is downstream. The live state sits in Lakebase while the conversation runs, and Delta is where that history can land afterward for analysis and audit.

Four jobs, cleanly split:

  • Live, per-turn conversation state: the persistent operational store (Lakebase, via sessions).
  • Durable facts about a user across conversations: long-term memory (Lakebase, via memory).
  • Shared documents searched by meaning: the vector index.
  • The after-the-fact analytical record: Delta.

The two traps, in one line each

Trap 1: the bigger context window. It holds more in one call and still forgets between calls. When something is forgotten over time, ask whether the fix adds room or adds permanence. A cross-turn scenario is always about permanence.

Trap 2: the vector index as memory. The index retrieves shared documents by similarity. Conversation state is read back exactly, for one conversation. You don’t want the agent to search for an asset number by meaning and hope the nearest neighbor is the right one.

A third, quieter trap: an option that picks a persistent store but the wrong timing, like writing state only when the conversation ends. A fact needed on turn four doesn’t help anyone if it’s saved after turn ten.

How I’d study this in 30-60 minutes a day

  • Day one, 30 minutes: draw the desk, the library and the notebook. Under each, write what it’s for and what it forgets. If you can’t explain why a bigger desk doesn’t help, reread that part.
  • Day two, 45 minutes: read the Databricks page on agent memory and sessions, and note which store holds one conversation and which holds facts across conversations.
  • Day three, 30 minutes: take ten facts from an imaginary agent (an order id, a user’s language, a policy document, yesterday’s decision) and sort each one with the two questions.
  • Day four, 30 minutes: go through scenario questions and, whenever an agent “forgets,” ask first “room or permanence?” before you read the options.

That’s the ambush approach in practice. If you want these traps laid out domain by domain, in the order the exam guide covers them, my free Databricks Generative AI Engineer Associate course does exactly that.

FAQ

What is agent memory on Databricks?

It’s a persistent store, outside the model call, where an agent keeps conversation state and durable facts so it can use them on later turns or in later conversations. On Databricks this is backed by Lakebase, a managed Postgres database, through agent sessions (one conversation) and agent memory (across conversations).

Is short-term memory the same as the context window?

No. Short-term memory is persistent and scoped to one conversation, reloaded each turn by its thread or session id. The context window is wiped after every call. Short-term vs long-term is about scope, not about how long the data survives.

Why not just use a model with a bigger context window?

A bigger window holds more within a single call but retains nothing between calls. It changes capacity, not persistence, so it can’t fix an agent that forgets across turns.

Can I store agent memory in my Vector Search index?

You shouldn’t. The index is for shared documents searched by meaning. Conversation state needs to be read back exactly for one conversation, and putting per-user facts in the index pollutes a store meant for shared knowledge.

When should I use Lakebase vs a Delta table for agent state?

Lakebase for the live state an agent reads and writes every turn, because that’s fast transactional work. Delta for the after-the-fact analytical and audit record of that state.

Learn it properly, for free

Agent memory is a perfect example of why dumps fail you. Memorize “the answer is Lakebase” and a question where the fact only needs to live for one call, or where the thing to store is a document, catches you anyway. Learn the desk, the library and the notebook, plus the two questions, and every version of the scenario sorts itself.

If you want a structured path through every domain, with traps like these mapped out, take my free Databricks Generative AI Engineer Associate course. Thirty to sixty minutes a day is enough. See you there.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *