Let’s Get Certified
Module 10 / 15 · Assembling and deploying applications

Package and register a reproducible RAG application

Log the executable chain, environment, interface and resource dependencies.

Package and register a reproducible RAG application

Work through the decision

A chain runs in a shared notebook but fails in a clean serving environment because its retriever client came from an earlier cell. Which artifacts would have prevented the surprise?

Check your reasoning

Make model initialization explicit. With an MLflow pyfunc model, initialize reusable dependencies in the supported load path and validate each batch in prediction. Record code, dependency versions, signature, input example, output form and the governed resource references. Load and invoke the logged artifact in a clean environment before registration.

Watch the source lesson at 1:16:13

Compare the choices

Pyfunc wrapper
Package custom pre- and postprocessing with a predictable prediction interface and explicit initialization. Avoid reliance on notebook state.
Signature and input example
Describe and exercise the expected input and output types. Validate a representative request in a clean environment.
Resource authorization
Grant the effective serving identity only the downstream privileges needed by the application. Check the separate endpoint invocation permission.
Unity Catalog model registration
Register a tested model as a versioned governed object under a catalog and schema. Grant access at the appropriate boundary and record the serving version.

Test the decision

Register the validated version in Unity Catalog and preserve the mapping from model version to prompt, embedding space and index. Check endpoint invocation and downstream resource privileges independently. A user’s ability to query an endpoint does not imply access to every index.

Package and reload a two-row smoke test

Use a notebook with MLflow 3, pandas and a writable experiment. This small PythonModel wraps a deterministic manual lookup so the input, retrieval and output behavior can be tested before connecting a remote retriever or model endpoint.

Databricks · serve custom Python code with MLflow

Round-trip an MLflow PythonModel

import mlflow
import pandas as pd

class ManualLookup(mlflow.pyfunc.PythonModel):
    def predict(self, context, model_input, params=None):
        evidence = {"P-82": ("manual-8#4", "Use filter F-12.")}
        answers = []
        for raw in model_input["asset_id"]:
            key = str(raw).strip().upper()
            source, answer = evidence.get(key, ("", "Ask for an approved manual."))
            answers.append({"source": source, "answer": answer})
        return pd.DataFrame(answers)

sample = pd.DataFrame({"asset_id": [" p-82 ", "UNKNOWN"]})
with mlflow.start_run():
    logged = mlflow.pyfunc.log_model(
        name="manual_lookup", python_model=ManualLookup(), input_example=sample
    )
result = mlflow.pyfunc.load_model(logged.model_uri).predict(sample)
print(list(result["source"]))
Check the result

The expected source list is ["manual-8#4", ""]. Preprocessing normalizes the identifier. Postprocessing keeps the passage ID or returns a clarification. For a live chain replace the fixture with authorized retrieval, add grounded generation and repeat the same known-evidence and missing-evidence cases on the logged artifact.

Practice the guide skills

  1. A custom pyfunc model receives a tabular input with question and product fields. Watch 1:16:13 · Continue at 1:16:30
    Check your answer

    Validate input columns and types in preprocessing, run the defined chain and return the documented output structure. Package dependencies and test in a clean environment.

  2. The serving endpoint can be queried but its retriever is denied access. Watch 1:28:30 · Continue at 1:28:51
    Check your answer

    Distinguish the caller’s endpoint permission from the application’s access to the index and its data sources. Grant narrow privileges to the effective identity and validate in the serving context.

  3. Build a minimal request-to-answer path. Watch 1:16:53 · Continue at 1:17:05
    Check your answer

    Validate the question, retrieve authorized passages, format a prompt with source IDs, call the chosen model, and verify response shape and cited IDs. Define behavior for zero retrieved evidence.

  4. What belongs in the logged RAG artifact? Watch 1:18:00 · Continue at 1:18:28
    Check your answer

    Record the model flavor or application packaging, retriever configuration, embedding and generation references, dependencies, representative input and output signature. Test loading it outside the author’s notebook.

  5. Publish a validated model version to Unity Catalog. Watch 1:19:32
    Check your answer

    Log the model in MLflow, register it under a qualified catalog and schema with suitable permissions, and track the specific version used by each deployment. Preserve provenance for rollback.

Official objectives for this lesson

Related lesson · Version control and CI/CD

Knowledge check

Package and register a reproducible RAG application quiz

Answer 3 questions. Check each answer for an explanation.

Worked example · Package and register a reproducible RAG application