Sub topic 1
The Mosaic AI platform and how its pieces fit together
Prerequisites
This chapter assumes you have:
- Basic Python, including functions and decorators.
- Familiarity with large language models, prompts, and chat messages.
- Working knowledge of Databricks notebooks and Delta tables.
- Basic familiarity with REST APIs.
No code needs to run in this chapter. It gives you the map that the later chapters fill in.
What Mosaic AI is
Mosaic AI is the set of Databricks components for building, evaluating, deploying, and monitoring generative AI applications. The components share one workspace, one governance layer, and one tracking system. You can build an application without moving data or models between separate vendors' tools.
The components and their roles
| Component | Role in an application |
|---|---|
| Foundation Model APIs and model serving endpoints | Host models and expose them over a REST interface |
| Mosaic AI Vector Search | Index text from Delta tables so you can find passages by meaning |
| MLflow Tracing | Record each step of a request for debugging |
| Agent Framework and evaluation | Build agents, then measure their quality with datasets, scorers, and judges |
| Unity Catalog | Govern data, models, and indexes with shared permissions |
| AI Gateway | Apply rate limits, guardrails, and usage tracking to endpoints |
Two ideas connect these parts.
- Everything is an endpoint or a governed asset. Models and agents are served at endpoints. Tables, indexes, and registered models live in Unity Catalog under a three-level name such as
main.genai.docs_index. - Everything can be observed. Tracing during development and monitoring in production use the same MLflow records.
How a request flows
A typical retrieval-augmented generation (RAG) application handles a question like this. The application receives the question. It searches a Vector Search index for relevant chunks. It sends those chunks and the question to a chat model. It returns the answer. MLflow Tracing records every step.
From idea to production
The remaining chapters follow the order in which you would build an application.
- Call a served model with a chat completions client.
- Chunk documents and build a Vector Search index.
- Combine retrieval and generation into a RAG function.
- Add tracing so you can inspect each step.
- Add tools and build an agent.
- Evaluate quality with a curated dataset.
- Register the agent in Unity Catalog and deploy it.
- Protect the endpoint with AI Gateway and monitor it.
Here is the smallest useful piece of code, which shows the shape of the platform. The Databricks SDK gives you an OpenAI-compatible client that is already authenticated for your workspace.
from databricks.sdk import WorkspaceClient
# Name of a chat model serving endpoint in your workspace
ENDPOINT_NAME = "<your-chat-endpoint-name>"
w = WorkspaceClient()
client = w.serving_endpoints.get_open_ai_client()
response = client.chat.completions.create(
model=ENDPOINT_NAME,
messages=[
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Explain what a vector index is in two sentences."},
],
max_tokens=200,
)
print(response.choices[0].message.content)The model argument is the name of a serving endpoint, not a model family. This is a common source of errors. The same pattern works for a Databricks-hosted foundation model, an external model, or your own deployed agent.
Common mistakes
- Treating the components as separate products. Permissions, names, and traces connect them. Plan the Unity Catalog catalog and schema for your tables, indexes, and models before you start.
- Skipping evaluation until deployment. Evaluation sits before deployment in the workflow because it is cheaper to fix quality problems early.
- Confusing the model with the endpoint. Your code calls endpoints. Swapping the model behind an endpoint should not require changing application code.
Exercise
A teammate says, "Our RAG app needs a model, a search index, and a way to see what happened on each request." Which Mosaic AI component covers each need?
Show answer
The model is hosted on a Foundation Model API or model serving endpoint. The search index is a Mosaic AI Vector Search index over a Delta table. Seeing what happened on each request is done with MLflow Tracing.
Exercise
In the code above, what value do you pass as model, and why is this useful?
Show answer
You pass the name of a serving endpoint. Because the application depends on the endpoint and not on a specific model, you can change the model behind the endpoint without editing the application code.