What you will be able to do
- Tell keyed (structured) memory lookups apart from relevance-ranked (search) memory recall, using the query's shape
- Pick a structured query tool (memory list, Unity Catalog function, SQL or Genie MCP) when the agent already knows the fields and values to look up
- Pick AI Search, or Lakebase Search inside Postgres, for natural-language or fuzzy recall, and choose vector, keyword or hybrid mode based on the query's wording
- Explain why an AI Search index cannot read a Lakebase Postgres table directly, and what the sources say about bridging the two
Key concept
Retrieval follows the shape of the query — If the agent knows exactly which memory it wants (whose it is, which session, which path or ID), use a structured lookup that filters on those fields. If it only knows what the memory is about, in words that may not match how the memory was stored, use a ranked search such as BM25, vector or hybrid.
1.Two ways to read a memory back
Once an agent has stored memories in Lakebase, it needs a way to get them back. Databricks keeps two kinds of agent state there. Session state is the transcript of a single interaction, and the agent loads it by the session's ID. Memory is the set of durable facts that should still matter in a later conversation that has nothing to do with this one. Sessions are a keyed read: the agent "reads it at the start of a turn and appends to it as the interaction runs." Nothing gets ranked, because the thread ID already identifies the right state. Memory is different. The agent "recalls them whenever they are relevant, regardless of which conversation surfaced them." Here the agent knows the topic, but not where the fact was stored.
Managed agent memory, which Databricks stores in Lakebase, offers both styles of retrieval. Each memory entry has an actor_id (whose memory it is), an optional session_id (where it was captured), and a required filesystem-style path such as /preferences/response-style.md. Together those three fields uniquely identify the entry. On top of this, the store exposes two read operations: list, which filters on the known fields, and search, which takes a natural-language query.
The two operations answer different questions. List returns the entries for an actor, optionally narrowed by session_id or a path prefix, and the docs suggest using it "to browse or render an index of what an agent knows." It is a structured query: the fields to filter on are part of the request. Search returns entries ranked by relevance to free text, scored with BM25. That fact matters later in this lesson. A memory search ranks by the words it shares with the stored text and description, not by embedding distance. This is why each entry's description is described as improving retrieval: the description adds words the query can match.
def make_memory_tools(memory_store, actor_id: str):
@function_tool
def search_memory(query: str) -> str:
"""Search long-term memory for relevant facts about the user."""
results = memory_store.search(actor_id=actor_id, query=query, limit=10)
return "\n\n".join(f"{r.memory.path}: {r.memory.content}" for r in results) or "No memory found."Look at what this code fixes and what it leaves open. actor_id is passed in when the tools are built, and the model never chooses it. The docs say to set it "in trusted application code from the verified end-user identity." This is the pattern used even when the retrieval is a search: the structured part (whose memory) is set by the application, and only the open-ended part (what about) goes to relevance ranking.
Checkpoint 1 of 9· Check yourself
A support app's settings screen needs to show every memory saved for user-123 under /preferences/. Which managed memory operation fits?
The screen needs every entry under a known actor and path, which is a structured filter. Search returns only the top-ranked matches, so entries could be cut off by the limit, and the results would be ordered by relevance rather than path.
“Use this to browse or render an index of what an agent knows.”Source: docs.databricks.com
2.Structured query retrieval: when the agent already knows the key
The managed memory API is one case of a general rule. Some memories are records with typed columns: an account's tier, a decision tied to a ticket ID, the last order a user placed. Questions about them are lookups, filters or aggregates, so SQL answers them exactly. A Lakebase database can be registered in Unity Catalog "for unified governance and cross-source queries", and Databricks provides several tools that let agents query Unity Catalog tables.
| Tool | Who writes the query | Fits when |
|---|---|---|
| Unity Catalog SQL function (e.g. lookup_customer_info) | You, ahead of time; the agent supplies only parameter values | The question is always the same lookup, such as "get this customer's email and ID" |
| Databricks SQL MCP server (/api/2.0/mcp/sql) | The model generates SQL that runs on a SQL warehouse | Ad-hoc filters and aggregates over tables, with access governed by Unity Catalog permissions |
| Genie Agent via managed MCP (/api/2.0/mcp/genie/{genie_space_id}) | Genie turns a natural-language question into a query | Natural-language questions about up to 25 Unity Catalog tables |
The most deterministic option is a Unity Catalog function. The docs say to use one "when the query is known ahead of time and the agent provides the parameters." The function below takes a single input, filters a table with an equality WHERE clause, and returns at most one row. No ranking or embedding is involved: the agent gets the exact record or nothing.
CREATE OR REPLACE FUNCTION main.default.lookup_customer_info(
customer_name_input STRING COMMENT 'Name of the customer whose info to look up'
)
RETURNS STRING
COMMENT 'Returns metadata about a particular customer, given the customer''s name, including the customer''s email and ID. The
customer ID can be used for other queries.'
RETURN SELECT CONCAT(
'Customer ID: ', customer_id, ', ',
'Customer Email: ', customer_email
)
FROM main.default.customer_data
WHERE customer_name = customer_name_input
LIMIT 1;Note that "natural language" does not mean "use AI Search". Genie accepts plain-English questions, but it answers them by querying tables, so it is still structured retrieval. Questions like "What were the top 10 customers by revenue last quarter?" need the query to be computed (sort, aggregate, filter by date). Returning text that sounds similar would not answer them. So the deciding question is not whether the user typed English. It is whether the answer is a precise selection from records.
Checkpoint 2 of 9· Check yourself
An agent saves each user's subscription tier in a Lakebase table keyed by user ID. On every turn, it must fetch the tier for the current verified user. Which retrieval mechanism fits best?
The query is known ahead of time and the only variable is the user ID, which matches the documented use for a UC function tool. Search would rank candidates when the agent needs one exact row.
“when the query is known ahead of time and the agent provides the parameters”Source: docs.databricks.com
Checkpoint 3 of 9· Exam question
An agent's long-term memories are stored as rows in a Lakebase Postgres table, each tagged with a `user_id` column. At the start of every turn, the agent needs to load the single memory row belonging to the current signed-in user, identified by an exact `user_id` match, with no ranking or similarity involved. Which retrieval mechanism is most appropriate for this lookup?
Correct answer: A — A structured query against the Lakebase table filtering on `user_id`
- A. Correct. An exact-match lookup on a known column value is a classic structured (SQL/OLTP) query pattern — Lakebase's Postgres engine handles this with a simple indexed `WHERE user_id = ...` filter, with no need for ranking or embeddings.
- B. Incorrect. Vector similarity search ranks memories by semantic closeness to a query embedding; it is unnecessary overhead and imprecision for retrieving one row by an exact identifier that is already known.
- C. Incorrect. Hybrid search still returns a ranked list based on relevance scoring, which is the wrong retrieval shape for a deterministic single-row lookup by exact key.
- D. Incorrect. Routing a deterministic key lookup through a Genie natural-language interface adds unnecessary translation overhead and non-determinism where a direct filtered query is simpler and more reliable.
3.Databricks AI Search: when the agent only knows what the memory is about
Structured retrieval fails when the agent cannot name the key. Suppose a user says "remember how I wanted those reports formatted?" The stored memory might say "prefers bullet summaries, no tables". The agent has no ID or path, and the two phrasings share almost no words. This is the problem Databricks AI Search (formerly Vector Search) addresses: it returns relevant rows "by finding the embeddings most similar to a query." Embeddings capture the meaning of text, so a paraphrase can still be retrieved.
AI Search supports more than one query mode, and the right one depends on how the query is worded. Pure similarity search handles paraphrase but can miss exact tokens. The docs recommend hybrid search for source data that contains "unique keywords such as SKUs or identifiers that are not well suited to pure similarity search." Hybrid search combines the vector results and the BM25 keyword results with Reciprocal Rank Fusion. For queries that are purely exact terms, full-text (BM25) search needs no embeddings at all. AI Search also supports filtering, so a search can be limited to structured attributes, for example one user's rows, before ranking.
| Mode | How it ranks | Memory query it fits |
|---|---|---|
| Similarity (vector) search | Nearest embeddings by L2 distance, using HNSW approximate nearest neighbour search | Paraphrased recall: "what did we decide about the report layout?" |
| Hybrid keyword-similarity search | Vector and BM25 results merged with Reciprocal Rank Fusion | Intent plus an exact token: "notes on the issue with SKU 4471" |
| Full-text keyword search (Beta) | Okapi BM25 over text columns; no embeddings needed | Exact terms or identifiers in stored text |
Checkpoint 4 of 9· Match them up
Match each memory query to the retrieval mechanism that fits it
Tap a term, then the definition that fits it.
Pure meaning goes to vector search. Meaning mixed with an exact token goes to hybrid search. A known key goes to a structured filter, whether that is SQL or a list with a path prefix.
“unique keywords such as SKUs or identifiers that are not well suited to pure similarity search”Source: docs.databricks.com
Checkpoint 5 of 9· Exam question
A support agent stores a running log of past customer interactions as memory entries persisted in Lakebase. When a new ticket arrives, the agent wants to surface prior interactions that are conceptually related to the new issue, even if they use different wording and share no exact keywords with the new ticket. Which mechanism should retrieve these memories?
Correct answer: A — Databricks AI Search vector similarity search over embedded memory entries
- A. Correct. Finding conceptually related content that shares no exact keywords requires comparing embeddings for semantic closeness, which is exactly what Databricks AI Search's vector similarity search provides.
- B. Incorrect. An exact-match category filter only returns rows that share the same discrete label; it cannot surface conceptually related memories that fall outside that category or use different wording.
- C. Incorrect. Sorting by recency retrieves memories based on time, not on conceptual relevance to the new ticket's content.
- D. Incorrect. A join against a fixed lookup table resolves known relationships between records; it does not measure semantic similarity between free-text memory content and a new query.
Sources5
4.Memories live in Postgres, AI Search indexes read lakehouse tables
There is a practical limit here that exam scenarios can test. An AI Search index is built from a source table, which must be "a Delta Lake table, streaming table, or managed table using Iceberg v3 or above." A Lakebase Postgres table is none of these. If memories are written to Lakebase and the agent needs semantic recall over them, there are two documented options.
Option 1: search inside Lakebase. Lakebase Search "adds hybrid vector and keyword search to Lakebase projects" through Postgres extensions. lakebase_vector adds an approximate nearest-neighbour index type (lakebase_ann) that is compatible with pgvector. lakebase_text adds BM25 indexes (lakebase_bm25). The same decision rule applies: use vector search for natural-language questions, keyword search for "names, codes, and exact-term lookups where wording matters", and hybrid search when a query mixes the two. A benefit of this option is that the memory row, its structured columns and its search index all live in one database. One detail to note: BM25 builds corpus statistics when the index is created, "not incrementally".
-- Vector similarity search
SELECT id, title
FROM documents
ORDER BY embedding <=> '[0.1, 0.2, 0.3]'
LIMIT 5;
-- BM25 keyword search (lower score = more relevant)
SELECT id, title,
body_tsv <@> to_bm25query(to_tsvector('english', 'database'), 'documents_body_bm25') AS score
FROM documents
ORDER BY score
LIMIT 5;Checkpoint 6 of 9· Fill the gap
Which index type gives this Lakebase column approximate nearest-neighbour (vector) search?
-- Create a vector search index
CREATE INDEX documents_embedding_idx ON documents
USING ? (embedding vector_cosine_ops);lakebase_ann is the ANN index type from lakebase_vector. lakebase_bm25 indexes tsvector columns for keyword search, and lakebase_tokenizer is a tokenization extension, not an index type.
Source: docs.databricks.comOption 2: move the data to the lakehouse first. Lakebase Change Data Feed captures every insert, update and delete, and each change is "stored as a new row in a Unity Catalog managed Delta table, batched and flushed every ~15 seconds." These Delta tables hold change history, with one row per change, not the current state of each memory. The sources provided here do not describe an end-to-end pipeline from Lakebase memory to an AI Search index. Treat that bridge as something you would design yourself, not as a documented pattern.
Checkpoint 7 of 9· Check yourself
A team stores long-term agent memories in a Lakebase Postgres table and wants semantic recall over them without running a separate pipeline. What is the most direct option?
AI Search indexes need a Delta, streaming or Iceberg source, so they cannot read the Postgres table directly. Lakebase Search adds vector search inside the same project. Equality SQL and Genie are structured retrieval and do not match on meaning.
“Lakebase Search adds hybrid vector and keyword search to Lakebase projects.”Source: docs.databricks.com
Checkpoint 8 of 9· Exam question
A personal-assistant agent has accumulated thousands of free-text memory notes in Lakebase over many months. Given a new user request, the agent wants to find the handful of notes that are most topically similar in meaning to the request, without knowing any exact identifiers, categories, or dates to filter on in advance. Which mechanism is the appropriate choice?
Correct answer: A — Databricks AI Search similarity search over embeddings of the memory notes
- A. Correct. Without any known exact keys to filter on, retrieving the most topically similar notes from a large free-text collection is the semantic-similarity use case that Databricks AI Search's vector search is designed for.
- B. Incorrect. An equality filter requires already knowing the exact category value to match, which the scenario states is not available; it also cannot express degrees of topical similarity.
- C. Incorrect. A date-range filter only narrows by time and does not measure how closely a note's meaning matches the new request.
- D. Incorrect. Joining to a profile table resolves structured relationships between records; it does not find notes that are semantically similar to unstructured request text.
5.Deciding from the query type
On the exam, a scenario usually gives you a memory store and one specific question the agent must answer. Work through it in order. First, can the agent name the record by actor, session, path, ID or another typed column? If so, use a structured query. Second, does the answer require computation over records (counts, ranges, latest, top-N)? That is also a structured query, through SQL or Genie, even if the question is phrased in English. Third, does the agent know only the topic? Then use ranked search, and choose vector search for paraphrase, keyword search for exact tokens, or hybrid for a mix. Fourth, where does the data live? Lakebase Search ranks rows inside Postgres, while AI Search indexes lakehouse tables. Many real requests combine these. The usual pattern is to fix the structured part (whose memory) in application code and run the search only over that subset.
Checkpoint 9 of 9· Check yourself
An agent must recall "what we noted about error code E404 when logins were slow" from memories in a Lakebase Postgres table with Lakebase Search enabled. The agent has no ID or path. Which mode fits the wording?
The agent knows only the topic, so ranked search applies, not a keyed lookup. The query combines meaning (slow logins) with an exact token (E404), which is what hybrid search is for.
“Use it when queries mix intent with specific terms, the most common case in real-world search.”Source: docs.databricks.com
Whose memory it is (the verified user, set as actor_id in application code) is structured, and so is "last month" if timestamps are stored as columns. "A fix for my billing export" is the part that needs search, because the stored memory may describe it in other words. Filter first on the known fields, then rank: semantic or hybrid search if you need paraphrase matching, or managed memory's BM25 search if the shared vocabulary is likely to be enough.
Exam traps
Each one states something that sounds right. Open it to see what is actually true.
1.Managed agent memory's search operation finds entries by embedding (vector) similarity.Why is that wrong?
Managed memory search ranks entries by a full-text BM25 relevance score. It matches on shared words, which is why the description on each entry improves retrieval.
Covered in Two ways to read a memory back
2.If the user asks in natural language, the agent should retrieve with AI Search.Why is that wrong?
Genie answers natural-language questions by querying Unity Catalog tables, which is structured retrieval. What decides the mechanism is whether the answer is an exact selection or computation over records, not whether the input is English.
Covered in Structured query retrieval: when the agent already knows the key
3.Pure vector similarity search is the best choice for memories identified by SKUs, error codes or other identifiers.Why is that wrong?
Exact identifiers are poorly served by similarity alone. Use hybrid or full-text search, or a structured lookup if the identifier is a key column.
Covered in Databricks AI Search: when the agent only knows what the memory is about
4.An AI Search index can use a Lakebase Postgres memory table as its source.Why is that wrong?
AI Search index sources are lakehouse tables (Delta, streaming or Iceberg v3+). For semantic search directly over Postgres rows, use Lakebase Search.
Covered in Memories live in Postgres, AI Search indexes read lakehouse tables
Sources
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“The agent recalls them whenever they are relevant, regardless of which conversation surfaced them.”
↩︎ Two ways to read a memory back“The agent reads it at the start of a turn and appends to it as the interaction runs.”
↩︎ Two ways to read a memory back - 2.
“An entry is uniquely identified by the combination of actor_id, session_id, and path.”
↩︎ Two ways to read a memory back“Set the actor_id in trusted application code from the verified end-user identity.”
↩︎ Two ways to read a memory back“Never let the model choose whose memory to read or write.”
↩︎ Deciding from the query type“List entries for an actor, optionally filtered by session_id or a path prefix.”
↩︎ Key concept“Search returns the most relevant entries ranked by a full-text (BM25) relevance score.”
↩︎ Exam trap 1“Search returns the most relevant entries ranked by a full-text (BM25) relevance score.”
↩︎ Prediction“Use this to browse or render an index of what an agent knows.”
↩︎ Checkpoint - 3.
“when the query is known ahead of time and the agent provides the parameters”
↩︎ Structured query retrieval: when the agent already knows the key“The server exposes SQL execution as a tool, and access is governed by Unity Catalog permissions.”
↩︎ Structured query retrieval: when the agent already knows the key“If your agent needs to query data in Unity Catalog tables, Databricks recommends using Genie Agents.”
↩︎ Exam trap 2 - 4.
“Register your Lakebase database in Unity Catalog for unified governance and cross-source queries.”
↩︎ Structured query retrieval: when the agent already knows the key - 5.
“by finding the embeddings most similar to a query”
↩︎ Databricks AI Search: when the agent only knows what the memory is about“The similarity search and keyword search results are combined using the Reciprocal Rank Fusion (RRF) function.”
↩︎ Databricks AI Search: when the agent only knows what the memory is about“This is useful for searching exact terms, identifiers, or keywords in text data.”
↩︎ Databricks AI Search: when the agent only knows what the memory is about“a Delta Lake table, streaming table, or managed table using Iceberg v3 or above”
↩︎ Memories live in Postgres, AI Search indexes read lakehouse tables“unique keywords such as SKUs or identifiers that are not well suited to pure similarity search”
↩︎ Exam trap 3“a Delta Lake table, streaming table, or managed table using Iceberg v3 or above”
↩︎ Exam trap 4“unique keywords such as SKUs or identifiers that are not well suited to pure similarity search”
↩︎ Checkpoint - 6.
“Use it for names, codes, and exact-term lookups where wording matters.”
↩︎ Memories live in Postgres, AI Search indexes read lakehouse tables“Use it when queries mix intent with specific terms, the most common case in real-world search.”
↩︎ Deciding from the query type“Lakebase Search adds hybrid vector and keyword search to Lakebase projects.”
↩︎ Checkpoint - 7.
“stored as a new row in a Unity Catalog managed Delta table, batched and flushed every ~15 seconds.”
↩︎ Memories live in Postgres, AI Search indexes read lakehouse tables