CertSafari
    Databricks Certified Context Engineer Associate· Lessons

    Domain 3 · Lesson 18/45

    Pre-inference vs just-in-time agentic retrieval

    Distinguish between pre-inference retrieval (embedding-based, up-front loading) and just-in-time agentic retrieval (tool calls, dynamic Delta table queries) and select the appropriate strategy for a given use case.

    18 min read
    2.22% of exam
    7 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    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?

    Checkpoint 2 of 9· Exam question

    Which statement correctly defines pre-inference retrieval as distinct from just-in-time agentic retrieval?

    Sources123

    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.

    Where the work happens for a pre-inference embedding index
    StageWhen it runsWhat it costs per user question
    Embed the corpus and build the AI Search indexAhead of time, then kept in sync when the source Delta table changesNothing: it does not rerun per question
    Embed the query and run a similarity searchAt request time, before the LLM runsOne query embedding and one index lookup
    Augment the prompt and generateAt request timeOne 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. 1.Build the AI Search index from the Delta table, with the corpus chunks embedded by the chosen model
    2. 2.Add the retrieved chunks to the prompt alongside the user's question
    3. 3.Call the LLM once to generate the answer
    4. 4.Run a similarity search and take the most similar chunks
    5. 5.Embed the user's query with the same model that embedded the chunks

    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?

    Sources341

    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.

    A retriever tool. The model reads tool_name and tool_description to decide when to search.python
    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?

    Sources51

    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.

    Structured retrieval tools, by what the agent needs and who writes the query
    Your agent needs toUseWho writes the SQL
    Answer business questions across the workspaceGenie One MCPGenie, from the agent's natural-language question
    Query one curated Genie Agent from PythonAI Bridge toolsGenie, scoped to that agent's tables
    Write and run SQLDatabricks SQL MCPThe agent
    Run a predefined query with parametersUnity Catalog function toolsA 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.

    A Unity Catalog SQL function used as a structured retrieval tool: the query is fixed and the agent supplies the namesql
    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.

    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;

    Checkpoint 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?

    Sources673

    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.

    Use-case signals and the strategy each one points to
    Signal in the use caseStrategyReason
    Large document corpus, rarely revised, free-form questionsPre-inference: AI Search index in a fixed chainEmbeddings are built ahead of time and the per-query work is one lookup
    Ad hoc totals, filters or rankings over current Delta tablesJust-in-time: Genie or Databricks SQL MCPThe answer must be computed by a query at the time of the question
    Known lookup, such as customer info by nameJust-in-time: Unity Catalog function toolThe SQL is fixed and the agent supplies only the parameters
    Mixed requests, some needing no retrieval at allJust-in-time: single agent with toolsThe 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.

    Sources1

    Sources

    (7)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 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. 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. 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. 4.
      “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. 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. 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. 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

    Ready to test yourself?

    Practise Databricks Certified Context Engineer Associate in quiz mode.

    Spotted a mistake, or was something unclear? Tell us.