What you will be able to do
- Say whether a retrieval design is pre-inference or just-in-time by asking who decides to retrieve and when the content was prepared
- Explain why an embedding index suits a large, slow-changing document corpus with free-form questions
- Explain what embedding-based retrieval and up-front loading mean, and why together they make up the usual pre-inference design
- Choose between Genie, the Databricks SQL MCP and Unity Catalog function tools when an agent has to query Delta tables at run time
- Choose the retrieval strategy for a use case based on how predictable the information need is
Key concept
Pre-inference vs just-in-time agentic retrieval — Pre-inference retrieval prepares content ahead of time, usually as an embedding index. The system then looks it up and places it in the prompt before the model runs, and the model never decides whether to retrieve. Just-in-time agentic retrieval leaves that decision to the model, which calls a tool (a retriever, Genie, a SQL function) during its reasoning loop when it finds it needs data.
1.Two ways context reaches the model
An agent can only use what is in its context window, so every retrieval design answers two questions: who decides that data is needed, and when was that data prepared. In pre-inference retrieval the system decides. Content is loaded or indexed ahead of time, and a fixed pipeline fetches the relevant part and puts it in the prompt before the model generates anything. In just-in-time agentic retrieval the model decides. It reads the request, works out that it is missing something, and calls a tool to fetch it. That tool might run a similarity search, ask Genie a question or execute a SQL function against a Delta table.
The two strategies match two of Databricks' agent design patterns. A deterministic chain carries out pre-inference retrieval: the developer specifies which tools run, in what order and with which parameters, and every request follows the same path. A single-agent system carries out just-in-time retrieval: the LLM chooses which tools to call, whether to call any at all, and when to stop.
Three misconceptions are worth clearing up early. Pre-inference retrieval does not mean a live SQL query fires whenever a question arrives. Its defining step is the preparation done beforehand. It also needs no tool call inside the model's reasoning loop. And it is not limited to documents: RAG can retrieve from a vector store, keyword search or a SQL database, over either unstructured content such as PDFs and wikis or structured content such as customer records and transaction tables.
Pre-inference retrieval is usually embedding-based and relies on up-front loading, and the two terms name different things. Embedding-based describes how content is found: an embedding model turns each chunk into a vector, the question is turned into a vector by the same model, and the chunks nearest to it are returned. That suits free-form questions, where the wording of the question rarely matches the wording of the answer. Up-front loading describes when the work happens: the pipeline that pre-processes, chunks, embeds and indexes the content runs before any question exists, so the request path only has to look up and inject. A small, stable body of text, such as a few standing instructions, can skip the index and be loaded straight into the system prompt. The same index can also sit behind a tool the model chooses to call, which is just-in-time retrieval over embedding-based content.
Checkpoint 1 of 9· Check yourself
A support assistant's LLM has one tool: a retriever over an AI Search index of product manuals that was embedded last week. For some questions the model answers directly. For others it calls the retriever partway through its reasoning. Which retrieval strategy is this?
The index being prepared ahead of time, or retrieval using embeddings, does not decide the classification. The question is who decides to retrieve. Here the model can choose not to call the tool, so this is just-in-time agentic retrieval in a single-agent system.
“The LLM adaptively decides which tools to use, when to make more LLM calls, and when to stop.”Source: docs.databricks.com
Checkpoint 2 of 9· Exam question
Which statement correctly defines pre-inference retrieval as distinct from just-in-time agentic retrieval?
Correct answer: A — Pre-inference retrieval loads or indexes content, such as embeddings, ahead of time so it is ready to search before the user query arrives
- A. Correct. Pre-inference retrieval refers to embedding or otherwise indexing content up front, so the search structure already exists and is simply queried when a request comes in.
- B. Incorrect. Issuing a live query at request time describes just-in-time agentic retrieval, the opposite of preparing data ahead of time.
- C. Incorrect. Requiring a tool call during the reasoning loop is the hallmark of just-in-time agentic retrieval, not pre-inference retrieval.
- D. Incorrect. Pre-inference retrieval commonly applies to unstructured document collections indexed as embeddings; it is not limited to structured tables.
2.Pre-inference retrieval: index once, look up before generation
Pre-inference retrieval does its expensive work before any user arrives. A data pipeline parses and indexes the corpus. With Databricks AI Search you build an index from a Delta table, Databricks computes the embeddings with a model you choose, and you can configure the index to stay in sync as the source table changes. Embedding the corpus happens once per change to the source, not once per question.
At request time the work is small. The system embeds only the user's query, using the same model that embedded the chunks, finds the most similar chunks, adds them to the prompt and calls the LLM once. That fixed sequence is the RAG chain at request time. For this lesson, the important property is that the system does the fetching and the model has no say in it.
This design wins when the information need is predictable. Take a support assistant answering free-form questions about a 5,000-page product manual that changes once a quarter. Every question is answered from the same kind of evidence, which is passages that mean roughly what the question means. Similarity search is built for that, and SQL WHERE clauses are not. Because the corpus rarely changes, a synced index is almost never stale. Because no LLM call is spent deciding whether to retrieve, the chain keeps latency down and every run is easy to audit.
| Stage | When it runs | What it costs per user question |
|---|---|---|
| Embed the corpus and build the AI Search index | Ahead of time, then kept in sync when the source Delta table changes | Nothing: it does not rerun per question |
| Embed the query and run a similarity search | At request time, before the LLM runs | One query embedding and one index lookup |
| Augment the prompt and generate | At request time | One LLM call, with no extra calls spent on orchestration |
A chain is rigid, and that is its weakness. Because it runs the same steps for every request, it handles unusual requests poorly, and adding a new capability usually means changing code. A question the index cannot answer still gets the top-k chunks injected, whether or not they help.
Checkpoint 3 of 9· Put it in order
A support assistant answers questions about a product manual through a pre-inference RAG chain over a Databricks AI Search index. Put the work in the order it happens, starting before any user arrives and ending with the answer.
- 1.Build the AI Search index from the Delta table, with the corpus chunks embedded by the chosen model
- 2.Add the retrieved chunks to the prompt alongside the user's question
- 3.Call the LLM once to generate the answer
- 4.Run a similarity search and take the most similar chunks
- 5.Embed the user's query with the same model that embedded the chunks
The corpus is embedded during data preparation, before any question arrives, and runs again only when the source changes. For each question, the chain embeds the query, looks up similar chunks, augments the prompt and calls the LLM once. The model never decides whether to retrieve.
“the retrieval query is translated into an embedding using the same embedding model that was used to embed the document chunks during data preparation”Source: docs.databricks.com
Checkpoint 4 of 9· Exam question
A team is building a support assistant over a 5,000-page product manual corpus that is revised only once per quarter. Users ask free-form natural-language questions, and the team wants sub-second answers with minimal per-query compute overhead. Which retrieval strategy best fits this use case?
Correct answer: A — Pre-inference retrieval using an AI Search embedding index built from the Delta table holding the manual content
- A. Correct. The corpus is large, unstructured, and changes infrequently, so pre-computing embeddings once and querying the resulting AI Search index at inference time gives fast semantic matches without repeating expensive indexing work per query.
- B. Incorrect. Issuing a fresh SQL query per request suits structured, frequently changing data, not semantic search over free-form text; it also cannot perform similarity matching the way an embedding index can.
- C. Incorrect. Recomputing embeddings for the entire corpus on every inference call wastes compute and adds latency that a static quarterly-updated index avoids entirely.
- D. Incorrect. Genie spaces are designed for structured tabular question answering via generated SQL, not semantic retrieval over long-form unstructured manual text.
3.Just-in-time retrieval: the model calls a tool
Just-in-time retrieval turns retrieval into a tool. The same AI Search index can serve either strategy, and what changes is who triggers it. Wrapped as a retriever tool over an AI Search index, the index is searched only when the model emits a tool call. The model makes that choice from the tool's name and description, so the description works as an instruction for when to retrieve. A vague description leads the model to search on the wrong turns, or to skip searching when it should not.
vs_tool = VectorSearchRetrieverTool(
index_name="catalog.schema.my_databricks_docs_index",
tool_name="databricks_docs_retriever",
tool_description="Search Databricks documentation to answer product questions.",
)The benefit is adaptability. A help desk agent can answer "What is our returns policy?" directly and call lookup_order(customer_id, order_id) only when someone asks about an order. If the tool returns "invalid order number," the agent can retry or ask the user for the correct ID. The agent pulls in context only when the conversation calls for it, and it can loop until it has what it needs.
The costs come with the loop. Each decision is another LLM call, which adds latency. The agent may also call a tool repeatedly or with invalid arguments, and an unguarded loop can run indefinitely. Production agents therefore set iteration limits or timeouts. The OpenAI-client example in the Databricks docs stops after ten tool-calling rounds.
Checkpoint 5 of 9· Check yourself
After a team wraps its existing AI Search index as a retriever tool, the agent sometimes searches on turns where it doesn't need to and skips searching on product questions where it should. Which setting should the team revise first?
With a retriever tool, the index is searched only when the model emits a tool call, and the model makes that choice from the tool's name and description. A vague description causes searches on the wrong turns. Index freshness, embeddings and top-k affect what a search returns, not when the model decides to search.
“Create a retriever tool and give it a description that tells the agent when to search.”Source: docs.databricks.com
4.Dynamic queries against Delta and Unity Catalog tables
Some questions can only be answered by running a query. "Total bookings by region last week" needs a filter, a grouping and a sum computed over the rows as they stand when the question is asked. An embedding index returns nearest neighbours, not computed results. Workarounds that prepare content in advance are still pre-inference: embedding a summary of each table's schema, batch-loading pre-aggregated totals into an AI Search index, or caching last night's written summary. All of them produce context before the question exists, so they are stale or cannot answer the question asked. The just-in-time alternative is a tool that queries Delta data at run time.
Databricks offers several such tools, and the choice depends on who writes the query. With Genie, the agent asks in plain language. Genie writes and runs the SQL against a curated Genie Agent of up to 50 tables, views or metric views, and Unity Catalog permissions are enforced on each request. The Genie Agent MCP server is read-only. With the Databricks SQL MCP, the agent writes its own SQL. With Unity Catalog function tools, a person writes the query in advance and the agent supplies only the parameters.
| Your agent needs to | Use | Who writes the SQL |
|---|---|---|
| Answer business questions across the workspace | Genie One MCP | Genie, from the agent's natural-language question |
| Query one curated Genie Agent from Python | AI Bridge tools | Genie, scoped to that agent's tables |
| Write and run SQL | Databricks SQL MCP | The agent |
| Run a predefined query with parameters | Unity Catalog function tools | A developer, ahead of time; the agent supplies parameters |
A Unity Catalog function is the most constrained just-in-time option. The SQL is fixed, so the agent cannot write a bad join. The function and parameter COMMENTs tell the model what the function returns and when to call it. The comment below also points out that the returned customer ID can feed other queries.
CREATE FUNCTION my_catalog.my_schema.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 my_catalog.my_schema.customer_data
WHERE customer_name = customer_name_input
LIMIT 1;Checkpoint 6 of 9· Match them up
Match each structured retrieval tool to the job it does and who writes the SQL when an agent queries Delta data at run time.
Tap a term, then the definition that fits it.
The choice between these just-in-time tools depends on who writes the query. Genie writes it from plain language, either across the workspace or for one Genie Agent. The SQL MCP lets the agent write it. A Unity Catalog function fixes the SQL in advance, so the agent only passes parameters.
“Create a structured retrieval tool using Unity Catalog SQL functions when the query is known ahead of time and the agent provides the parameters.”Source: docs.databricks.com
Checkpoint 7 of 9· Fill the gap
In this Unity Catalog function the query is fixed and the agent passes in only a customer's name. Which token completes the WHERE clause so the agent's input decides which row comes back?
CREATE FUNCTION my_catalog.my_schema.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 my_catalog.my_schema.customer_data
WHERE customer_name = ?
LIMIT 1;The agent supplies only the declared parameter, customer_name_input, and the fixed query uses it to filter the table. The agent never writes SQL or passes its whole question, so it cannot produce a bad join.
Source: docs.databricks.comCheckpoint 8 of 9· Exam question
A context engineer is deciding how a sales analytics agent should answer ad hoc questions like "what were total bookings by region last week?" against a curated set of Unity Catalog tables. Which design reflects just-in-time agentic retrieval rather than pre-inference retrieval?
Correct answer: A — The agent is connected to a Genie space that generates and executes a SQL query against the tables when the question arrives
- A. Correct. Genie translates the question into a SQL query and executes it against the live Delta tables at the moment the question is asked, which is the defining trait of just-in-time agentic retrieval.
- B. Incorrect. Matching against pre-embedded schema summaries is a pre-inference, embedding-based lookup rather than a dynamic query executed against current data.
- C. Incorrect. Querying a batch-built AI Search index means the answer reflects whatever was pre-aggregated earlier, which is pre-inference retrieval, not a live query.
- D. Incorrect. Reading a cached summary written the prior evening returns pre-computed content rather than dynamically querying the underlying tables at request time.
5.Choosing a strategy for a use case
Start from how predictable the information need is. If every request needs the same kind of context from the same source, a pre-inference chain gives that context with the fewest LLM calls and the easiest audit. If requests vary, and some need customer records, some need a computed figure and some need nothing, the model has to decide, and only a tool-calling agent lets it.
| Signal in the use case | Strategy | Reason |
|---|---|---|
| Large document corpus, rarely revised, free-form questions | Pre-inference: AI Search index in a fixed chain | Embeddings are built ahead of time and the per-query work is one lookup |
| Ad hoc totals, filters or rankings over current Delta tables | Just-in-time: Genie or Databricks SQL MCP | The answer must be computed by a query at the time of the question |
| Known lookup, such as customer info by name | Just-in-time: Unity Catalog function tool | The SQL is fixed and the agent supplies only the parameters |
| Mixed requests, some needing no retrieval at all | Just-in-time: single agent with tools | The model chooses which tools to call, if any |
The two strategies often work together. In the call-center example, an agent handling "help me return my last order" queries the order database for this customer's order and also consults a return-policy document. The policy text is stable and fits an index. The order is specific to this customer and has to be queried when the request arrives.
If you are unsure, default to the simpler design. Databricks advises starting simple and adding agentic behaviour only when you need its flexibility or model-driven decisions. Moving from a chain to tool calls brings loop guards, more LLM calls and less predictable runs. Accept those costs only when the requests really do vary.
Checkpoint 9 of 9· Match them up
A platform team is planning four assistants. Pair each use case with the retrieval strategy it points to.
Tap a term, then the definition that fits it.
A predictable need over a stable corpus suits a pre-inference chain, the cheapest and easiest design to audit. Computed figures over current data need a query tool at question time. A known lookup fits a fixed-SQL function. Mixed requests need the model to decide whether to retrieve, which only a tool-calling agent allows.
“Deterministic chains offer predictable, rule-based flows for well-defined tasks. More agentic approaches offer greater flexibility and potential”Source: docs.databricks.com
Sources1
Sources
(7)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“The LLM does not make decisions about which tools to call or in what order.”
↩︎ Two ways context reaches the model“The LLM adaptively decides which tools to use, when to make more LLM calls, and when to stop.”
↩︎ Two ways context reaches the model“When you want to minimize latency by avoiding multiple LLM calls for orchestration decisions.”
↩︎ Pre-inference retrieval: index once, look up before generation“Limited flexibility for handling diverse or unexpected requests.”
↩︎ Pre-inference retrieval: index once, look up before generation“Infinite loops can occur in any tool-calling scenario, so set iteration limits or timeouts.”
↩︎ Just-in-time retrieval: the model calls a tool“The agent can adapt to new or unexpected queries by choosing which (if any) tools to call.”
↩︎ Just-in-time retrieval: the model calls a tool“start simple. Introduce more complex agentic behaviors when you truly need them for better flexibility or model-driven decisions.”
↩︎ Choosing a strategy for a use case“The agent queries the order database to retrieve the relevant order and references a policy document.”
↩︎ Choosing a strategy for a use case“For well-defined tasks with predictable workflows.”
↩︎ Choosing a strategy for a use case“The LLM adaptively decides which tools to use, when to make more LLM calls, and when to stop.”
↩︎ Key concept“The LLM does not make decisions about which tools to call or in what order.”
↩︎ Exam trap 1“start simple. Introduce more complex agentic behaviors when you truly need them for better flexibility or model-driven decisions.”
↩︎ Exam trap 4“Deterministic chains offer predictable, rule-based flows for well-defined tasks. More agentic approaches offer greater flexibility and potential”
↩︎ Checkpoint - 2.
“Data pipeline: Pre-process and index documents, tables, or other data for fast and accurate retrieval.”
↩︎ Two ways context reaches the model“RAG architecture can work with either unstructured or structured supporting data.”
↩︎ Two ways context reaches the model“RAG architecture can work with either unstructured or structured supporting data.”
↩︎ Exam trap 2 - 3.
“Vector search is a type of search optimized for retrieving embeddings.”
↩︎ Two ways context reaches the model“You can structure the index to automatically sync when the underlying source table is updated.”
↩︎ Pre-inference retrieval: index once, look up before generation“by finding the embeddings most similar to a query”
↩︎ Dynamic queries against Delta and Unity Catalog tables - 4.https://docs.databricks.com/aws/en/agents/tutorials/ai-cookbook/fundamentals-inference-chain-ragOfficial docs
“the retrieval query is translated into an embedding using the same embedding model that was used to embed the document chunks during data preparation”
↩︎ Pre-inference retrieval: index once, look up before generation - 5.
“Create a retriever tool and give it a description that tells the agent when to search.”
↩︎ Just-in-time retrieval: the model calls a tool - 6.
“The agent sends a plain-language question, and Genie writes and runs the SQL against that agent's tables and returns the result”
↩︎ Dynamic queries against Delta and Unity Catalog tables“A Genie Agent is a collection of up to 50 Unity Catalog tables, views, or metric views that Genie keeps in context”
↩︎ Dynamic queries against Delta and Unity Catalog tables“The agent sends a plain-language question, and Genie writes and runs the SQL against that agent's tables and returns the result”
↩︎ Exam trap 3 - 7.
“Use the Databricks SQL MCP when your agent needs to write and run SQL against your Unity Catalog tables.”
↩︎ Dynamic queries against Delta and Unity Catalog tables“Create a structured retrieval tool using Unity Catalog SQL functions when the query is known ahead of time and the agent provides the parameters.”
↩︎ Dynamic queries against Delta and Unity Catalog tables