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

RAG on Databricks: The Pieces the Exam Actually Tests

RAG on Databricks featured image: ship the chain, measure the funnel, with a practice card showing that a reranker cannot fix low recall

Most people study RAG on Databricks as a list of products: a vector index here, an embedding model there, a model endpoint at the end. Then the Generative AI Engineer Associate exam hands them a chain that already works and asks what’s missing, or a retrieval score that looks great next to answers that are wrong, and the product list doesn’t help. The exam doesn’t test whether you can name the pieces. It tests the wiring between them, how the chain ships, and how you prove it answers well. That’s what this post is about.

If you’re starting from zero, my Databricks Generative AI Engineer Associate study guide has the full exam map. Here I’m zooming into the build itself: the part where the index, the chunks and the model finally become one application.

Why RAG on Databricks shows up in four exam sections

On the official exam page, Databricks lists six sections. The RAG build touches four of them: Design Applications (14%), Data Preparation (14%), Application Development (30%) and Assembling and Deploying Apps (22%). That’s most of the paper, from one topic.

The objectives behind this post sound like separate chores when you read them in the exam guide:

  • Translate business goals into the inputs and outputs of the pipeline.
  • Select chain components for a desired input and output.
  • Select LangChain or similar tools for an application.
  • Code a simple chain, then code one inside a pyfunc model with pre- and post-processing.
  • Choose the basic elements needed to create a RAG application.
  • Use tools and metrics to evaluate retrieval, and explain the role of re-ranking.

In my book I collapse them into two pictures, because two pictures are easier to carry into the exam room than eight objectives. The first is an assembly line: how the pieces connect and ship. The second is a retrieval funnel: how you prove the retrieval part actually works. Everything below hangs on one of those two.

Picture one: the chain is an assembly line

Think of a chain as an assembly line. Each component is a station that takes one shape of input and turns out the next shape. You don’t design the line from the first machine forward. You design it backward, from the product it has to ship.

Start with the shape, not the tool

Here’s the first trap. A scenario gives you a business goal, something like “summarize each support ticket and route it to the right team,” and asks what to do first. The tempting answers name a tool: set up a LangChain pipeline, pick a bigger model. The right first move is boring: write down what goes in, what comes out, and every shape that passes between stages.

Do that with the ticket example and it stops being one task. It’s two transformations with a handoff: ticket text becomes a summary, and the summary becomes a routing label. That handoff is a shape you either specify or a failure you ship. When the exam asks what comes first with a requirement, the answer is the spec, never a product.

Read the pair, name the station

Once you have shapes, picking components becomes a lookup instead of a guess, because each kind of component does exactly one transformation:

  • A question in, ranked passages out: that’s a retriever.
  • A prompt in, text out: that’s the model.
  • Raw model text in, a structured record out: that’s an output parser.

So when a question gives you a desired input and output and asks which component belongs between them, read the pair. Notice what’s not on that list: “use LangChain.” A framework hosts stations, but it performs no transformation of its own. An answer that names the framework fits every question equally, which means it answers none of them.

LangChain is the conveyor belt, not a station

That doesn’t make LangChain a wrong answer. It means you judge it by fit. What a framework like LangChain really buys you is composition (connecting stations) and integrations (ready-made connectors to retrievers, models and tools). It earns its place by the number of handoffs it spans.

A pipeline with several stations and real integrations wants the belt. A single model call has nothing to convey, and a plain call to a Foundation Model API is simpler and clearer. The exam sets this trap in both directions: wrapping one call in a framework, and refusing a framework for a real multi-station chain. Count the stations, not the ideology.

The chain is the machines; the pyfunc envelope is what ships

A chain that runs in your notebook is just the machines. What Databricks logs, registers and serves is the chain wrapped in an envelope. For custom Python, that envelope is an MLflow pyfunc model, and it adds two stations of its own: preprocessing at the front, which validates the input before any machine sees it, and postprocessing at the back, which enforces the shape of what goes out.

This is where one of my favorite traps lives. An answer says “tell the model in the prompt to always return JSON.” That narrows the odds, but it guarantees nothing, because a model can ignore a request. The guarantee lives after the model, in postprocessing code that parses the output and either coerces it into the promised structure or rejects it. Anything you only ask for in the prompt is a probability. Anything you check in code after the model is a certainty.

The RAG bill of materials: six parts, six failures

This is the objective I see people underestimate most. A retrieval chain that answers in a notebook and one that registers and serves are separated by a short list of declarations. I call it the bill of materials, because like a shipping manifest, it names every part the crate must contain, and a crate missing a part either gets turned back or fails in the field.

The exam names six elements. Memorize them with the failure attached, because the questions almost never say “list the six.” They describe a symptom and ask which part is missing.

  • Model flavor. Tells MLflow how to save, load and call the artifact: the LangChain flavor for a LangChain chain, pyfunc for custom Python. Wrong flavor: the artifact doesn’t reconstruct into something Model Serving can call.
  • Embedding model. Turns the incoming question into a vector. It must be the same model that embedded the documents when the index was built. Mismatch: no error at all, just confidently retrieved passages that mean nothing. That’s the silent one.
  • Retriever. Carries the query vector to the index and brings passages back. Declared as a resource, together with the embedding endpoint, so the served model can authenticate. Undeclared: the model logs and registers fine, then fails in production with an authentication error.
  • Dependencies. The libraries the serving container installs. Pin the full mlflow package, not mlflow-skinny, the trimmed package that ships with Databricks Runtime ML. Get this wrong and the container doesn’t build, so the model never deploys.
  • Input example. One sample request. MLflow runs it through the model to infer the signature.
  • Model signature. The schema of what goes in and what comes out. Unity Catalog requires it, so without one, registration is refused outright.

The authentication part is worth a sentence of its own. In the notebook, your own credentials ride along with every call, which is why everything just works. A served model runs with no person signed in. Databricks calls the fix automatic authentication passthrough: you declare every resource the chain touches when you log it, and at deployment Databricks provisions short-lived credentials for exactly those resources. A deployed model can only open the doors its manifest listed.

In practice the six collapse into one logging call. Here’s a sketch of what that looks like (names and the version are placeholders):

import mlflow
from mlflow.models.resources import (
    DatabricksServingEndpoint,
    DatabricksVectorSearchIndex,
)

mlflow.set_registry_uri("databricks-uc")

with mlflow.start_run():
    mlflow.langchain.log_model(                  # 1. flavor: which log_model you call
        lc_model="rag_chain.py",                 # the chain, logged from code
        name="rag_chain",
        input_example={"messages": [             # 5. example, used to infer 6. the signature
            {"role": "user", "content": "What is the return window?"}
        ]},
        pip_requirements=[                       # 4. dependencies: full mlflow, pinned
            "mlflow==<your version>",
            "databricks-langchain",
        ],
        resources=[                              # 2 and 3. what the chain calls when served
            DatabricksServingEndpoint(endpoint_name="databricks-bge-large-en"),
            DatabricksVectorSearchIndex(index_name="main.support.docs_index"),
        ],
        registered_model_name="main.support.rag_chain",
    )

Every element is one argument. The flavor is which log_model you call. The embedding model and the retriever are the two resources. The dependencies are pip_requirements. The input example is input_example, and the signature is the one element you don’t see, because MLflow infers it from the example. A good habit before registering anything: load the logged model back and call it on your input example, so the whole manifest gets exercised once while a mistake is still cheap.

If you want to drill these symptom-to-part matches with practice questions written in the exam’s style, that’s exactly what my free Generative AI Engineer Associate course is built for. No dumps, just the traps explained.

Picture two: retrieval is a funnel

Now the chain registers and serves. The next question is the one the exam really cares about: is it any good? And you can’t answer that by reading a few answers and deciding they look fine.

I picture retrieval as a funnel with two stages. The first stage casts wide and cheap, catching every passage that might matter. The second stage judges narrow and expensive, lifting the best of those to the top. Most retrieval failures are one stage missing or weak, which turns every bad answer into a question with two suspects: was the right passage never caught, or caught and buried?

The metrics, and what each one catches

You measure the funnel against an evaluation set: questions paired with the passages that should come back. Then four metrics do different jobs:

  • Recall at k is completeness. Of all the relevant passages that exist, how many made it into your top k? It catches what you missed.
  • Precision at k is purity. Of the k passages you returned, how many are relevant? It catches the noise you let in.
  • NDCG scores the whole ranking, rewarding relevant passages more the higher they sit.
  • MRR (mean reciprocal rank) scores how high the first relevant passage lands.

Recall and precision use the same top-k set with different denominators, so they catch opposite failures. “We can’t find it” is a recall problem. “Too much junk in the context” is a precision problem. And MRR is the wrong instrument when an answer needs more than one passage, because it only cares about the first hit.

The trap: a retrieval score never scores the answer

This is the one that ships confidently wrong systems. Every metric above certifies what came back, not whether the model did right by it. High recall sitting next to wrong answers is not a paradox. It’s a retrieval score being asked to vouch for a stage it never measured. Whether the answer is faithful and correct is generation evaluation, a separate set of tools. Watch out for groundedness in particular: it sounds like a retrieval measure, but it judges the answer, not the retrieval.

Re-ranking: it sorts the catch, it can’t fill the net

Re-ranking is the funnel’s second stage, and the exam tests it as a cost-benefit decision more than a feature.

The first stage runs on a bi-encoder: the embedding model embeds the query and each document separately. Because documents are embedded on their own, they can be embedded once, ahead of time, which is what lets search scale to millions of passages. The second stage runs on a cross-encoder, which reads the query and one document together and scores how well that document answers that query. Reading the pair together makes it more accurate. It also means nothing can be computed ahead of time, so it only ever runs on a shortlist. They’re not the same model used twice; they’re two machines built for opposite jobs.

On Databricks, the reranker is built in, and you turn it on in the query itself, as the query documentation shows. Set num_results to the final number you want back; the number of candidates the reranker scores is separate from it:

from databricks.ai_search.reranker import DatabricksReranker

results = index.similarity_search(
    query_text="Can a damaged item be returned after 30 days?",
    columns=["id", "text", "doc_uri"],
    query_type="hybrid",          # stage one: vector + keyword, fused
    num_results=10,               # the shortlist the model finally sees
    reranker=DatabricksReranker(  # stage two: the built-in cross-encoder reranker
        columns_to_rerank=["text"]
    ),
)

Quick naming note: Databricks now brands Vector Search as AI Search, so newer docs use that name. The mechanics are the same, and I covered the endpoint, index and sync side in Databricks Vector Search explained.

When re-ranking earns its latency

The retrieval quality guide is refreshingly direct about the trade. The built-in reranker suits RAG agents, where latency is already dominated by the model’s generation, and quality-first apps at low to moderate traffic (about 5 queries per second out of the box). It’s not suited to high-throughput apps or real-time search bars that need answers in under 100 milliseconds, since reranking 50 results takes up to a second (under 1 second in typical workloads, per the guide).

So on the exam: if the scenario stresses quality and the answer is generated by an LLM anyway, re-ranking is worth it. If it stresses a live search box or hundreds of queries a second, leave it off.

The ambush: buried versus missing

Here’s the differentiator. A reranker only reorders what the first stage retrieved. It never sees a passage that wasn’t caught. So it fixes exactly one failure: the right passage is in the candidate set but ranked too low. In the metrics, that looks like recall that’s poor at the top and healthy deeper down (low at 10, high at 50).

If recall stays low even at a deep cutoff, the right passage isn’t in the candidates at all, and a reranker just reshuffles wrong answers. That’s a first-stage problem, and the fix lives there: hybrid search (vector plus keyword), metadata filtering, a stronger embedding model, or a better chunking. Databricks lays these out as a ladder: improve the net first, then add the reranker on top. Before you improve a stage, prove it’s the stage that’s failing.

Closing the loop: let evaluation choose your chunking

One last connection, because it ties the whole build together. In my post on chunking strategies for Databricks RAG, I explained how document structure and the embedding model’s limits narrow down where to cut. What they can’t tell you is which of the remaining options wins. That’s settled by the same instruments from this post: index the chunking candidates, score each one on the same evaluation set, and keep the winner.

The exam objective literally says “based on model and retrieval evaluation.” An answer that reasons its way to a chunk size without running an eval has solved a different problem. Design proposes the chunking; evaluation picks it.

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

This is a lot of surface, so I’d split it across a few short sessions instead of one long one:

  • Day 1: The assembly line. Take three business goals and write their input and output shapes before naming any component. Then name the station between each pair.
  • Day 2: The bill of materials. Write the six elements from memory, each with its failure. Then do it backward: from a symptom (auth error, container won’t build, registration refused, meaningless passages) to the missing part.
  • Day 3: The funnel. Define recall, precision, NDCG and MRR in one sentence each, and practice reading a pair of recall numbers (at 10 and at 50) to decide between “re-rank” and “fix the first stage.”

If you’re planning your whole prep, my post on how to pass the Databricks Generative AI Engineer Associate exam covers the full routine.

FAQ

What does the exam mean by the “basic elements” of a RAG application?

Six things you declare when logging the chain: the model flavor, the embedding model, the retriever, the dependencies, an input example, and the model signature. Each one has its own failure when it’s missing, and that’s how the exam asks about them.

Why does my RAG chain fail with an authentication error only after deployment?

Most likely the vector index or the embedding endpoint wasn’t declared in the resources list when the model was logged. In the notebook your own credentials are used; a served model can only reach the resources it declared.

Do I need LangChain to build RAG on Databricks?

No. LangChain helps when you’re composing several stations with integrations. For a single model call, a plain Foundation Model API call is simpler. The exam rewards matching the tool to the number of handoffs, not loyalty to a framework.

Does re-ranking always improve retrieval?

Only when the right passage was retrieved but ranked too low. If it was never retrieved, re-ranking can’t help, and the fix belongs in the first stage. It also adds latency, so it’s a poor fit for high-throughput or sub-100-millisecond search.

Is a high recall score proof that my RAG app gives good answers?

No. Recall measures what the retriever returned, not what the model did with it. Answer quality is measured separately with generation evaluation.

Keep going

RAG on Databricks gets easier the moment you stop seeing it as a pile of products and start seeing two pictures: an assembly line that has to ship, and a funnel you have to measure. Learn the traps in each, and most of these questions answer themselves.

If you want to practice exactly these traps with scenario questions and clear explanations, take my free Databricks Generative AI Engineer Associate course. It’s free, it’s built around the ambush idea, and it fits in 30-60 minutes a day.

Comments

Leave a Reply

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