Introduction
Discovering the proper place to place an advert is a big problem, as conventional, keyword-based contextual content material placement typically falls quick, lacking nuance like sarcasm or non-obvious connections. This weblog exhibits how an AI Agent constructed on Databricks strikes past these limitations to attain extremely nuanced, deeply contextual content material placement.
We’ll discover how this may be accomplished within the context of film and tv scripts to grasp the precise scenes and moments the place content material can have probably the most affect. Whereas we concentrate on this particular instance, the idea might be generalized to a broader catalog of media information, together with TV scripts, audio scripts (e.g., podcasts), information articles, or blogs. Alternatively, we may reposition this for programmatic promoting, the place the enter information would come with the corpus of advert content material and its related metadata and placement, and the agent would generate the suitable tagging to make use of for optimized placement by way of direct programmatic or advert server primarily based placement.
Resolution Overview
This resolution leverages Databricks’ newest developments in AI Agent tooling, together with Agent Framework, Vector Search, Unity Catalog, and Agent Analysis with MLflow 3.0. The under diagram gives a high-level overview of the structure.

- Knowledge Sources: Film scripts or media content material saved in cloud storage or exterior methods
- Knowledge Preprocessing: Unstructured textual content is ingested, parsed, cleansed, and chunked. We then create embeddings from the processed textual content chunks and index them in a Databricks Vector Retailer for use as a retriever software.
- Agent Growth: Content material placement agent leverages vector search retriever software wrapped in a Unity Catalog Operate, LangGraph, MLflow, and LLM of alternative (on this instance we use a Claude mannequin)
- Agent Analysis: Agent high quality repeatedly improves by means of LLM judges, customized judges, human suggestions, and iterative growth loop
- Agent Deployment: Agent Framework deploys agent to a Databricks mannequin serving endpoint, ruled, secured, and monitored by means of AI Gateway
- App Utilization: Exposes Agent to finish customers by means of Databricks Apps, a customized app, or conventional promoting tech stack; log all person suggestions and logs to Databricks for steady high quality enchancment
From a sensible standpoint, this resolution permits advert sellers to ask in pure language the most effective place inside a content material corpus to fit commercial content material primarily based on an outline. So on this instance, given our dataset comprises a big quantity of film transcripts, if we have been to ask the agent, “The place can I place an commercial for pet meals? The advert is a picture of a beagle consuming from a bowl”, we might anticipate our agent to return particular scenes from well-known canine motion pictures, for instance Air Bud or Marley & Me.
Under is an actual instance from our agent:

Now that now we have a high-level understanding of the answer, let’s dive into how we put together the information to construct the agent.
Knowledge Preprocessing
Preprocessing Film Knowledge for Contextual Placement
When including a retrieval software to an agent – a way known as Retrieval Augmented Era (RAG) – the information processing pipeline is a vital step to attaining top quality. On this instance, we comply with finest practices for constructing a sturdy unstructured information pipeline, which usually contains 4 steps:
- Parsing
- Chunking
- Embedding
- Indexing
The dataset we use for this resolution contains 1200 full film scripts, which we retailer as particular person textual content information. To fit advert content material in probably the most contextually related means, our preprocessing technique is to advocate the precise scene in a film, as an alternative of the film itself.
Customized Scene Parsing
First, we carry out parsing on the uncooked transcripts to separate every script file into particular person scenes, utilizing customary screenplay writing format as our scene delimiters (e.g., “INT”, “EXT”, and many others.). By doing so, we are able to extract related metadata to counterpoint the dataset and retailer it alongside the uncooked transcript in a Delta desk (e.g., title, scene quantity, scene location).
Scene-Conscious Mounted-Size Chunking Technique
Subsequent, we implement a fixed-length chunking technique to our cleansed scene information whereas filtering out shorter-length scenes, as retrieving these wouldn’t present a lot worth on this use case.
Notice: Whereas we initially thought-about fixed-length chunks (which might have doubtless been higher than full scripts), splitting at scene delimiters supplied a major enhance within the relevance of our responses.
Creating the Vector Search Retriever
Subsequent, we load the scene-level information right into a Vector Search Index, benefiting from the built-in Delta-Sync and Databricks-managed embeddings for ease of deployment and use. Which means that if our script database updates, our corresponding Vector Search index updates as effectively to accommodate the information refresh. The picture under demonstrates an instance of a single film (10 Issues I Hate About You) damaged up by scenes. Utilizing vector search permits our agent to search out scenes which can be semantically just like the advert content material’s description, even when there are not any actual key phrase matches.

Creating the extremely out there and ruled Vector Search index is straightforward, requiring only some traces of code to outline the endpoint, supply desk, embedding mannequin, and Unity Catalog location. See the code under for the creation of the index on this instance.
Now that our information is so as, we are able to progress to constructing out our content material placement agent.
Agent Growth
A core precept of Agentic AI at Databricks is equipping an LLM with the requisite instruments to successfully cause on enterprise information, unlocking information intelligence. Quite than asking the LLM to carry out a whole end-to-end course of, we offload sure duties to instruments and capabilities, making the LLM an clever course of orchestrator. This permits us to make use of it completely for its strengths: understanding person semantic intent and reasoning about remedy an issue.
For our utility, we use a vector search index as a way to effectively seek for related scenes primarily based on a person request. Whereas an LLM’s personal data base may theoretically be used to retrieve related scenes, utilizing the Vector Search index method is extra sensible, environment friendly, and safe as a result of it ensures retrieval from our ruled enterprise information in Unity Catalog.
Notice that the Agent makes use of the feedback within the operate definition to determine when and name the operate on person inquiries. The code under demonstrates wrap a Vector Search index into a normal Unity Catalog SQL operate, making it an accessible software for the agent’s reasoning course of.
Now that now we have an agent outlined, what’s subsequent?
Agent Analysis: Measuring Agent High quality with MLflow
One of many largest obstacles that forestalls groups from getting agentic functions into manufacturing is the power to measure the standard and effectiveness of the agent. Subjective ‘vibes’ primarily based evaluations aren’t acceptable in a manufacturing deployment. Groups want a quantitative means to make sure their utility is performing as anticipated and to information iterative enhancements. All these questions will maintain product and growth groups up at evening. Enter Agent Analysis with MLflow 3.0 from Databricks. MLflow 3.0 gives a sturdy suite of instruments together with mannequin tracing, analysis, monitoring, and a immediate registry to handle the end-to-end agent growth lifecycle.
LLM Judges on Databricks Overview
The analysis performance permits us to leverage built-in LLM-judges to measure high quality towards pre-defined metrics. Nonetheless, for specialised eventualities like ours, personalized analysis is usually required. Databricks helps varied ranges of customization, from defining pure language “pointers”, the place a person gives decide standards in pure language and Databricks manages the decide infrastructure, Immediate-based judges the place the person gives a immediate and a customized analysis standards, or customized scorers which can be easy heuristics or LLM judges fully outlined by the person.
On this use case, we use each a customized guideline for response format and a prompt-based customized decide to evaluate scene relevance, providing a robust stability of management and scalability.
Artificial Knowledge Era
One other widespread problem in Agent Analysis shouldn’t be having a floor fact of person requests to judge towards when constructing your agent. In our case, we should not have a sturdy set of attainable buyer requests, so we additionally wanted to generate artificial information to measure the effectiveness of the agent we constructed. We leverage the built-in `generate_evals_df` operate to carry out this activity, giving directions to generate examples that we anticipate will match our buyer requests. We use this synthetically generated information because the enter for an analysis job to bootstrap a dataset and allow a transparent quantitative understanding of our agent efficiency previous to delivering to clients.
MLflow Consider
With the dataset in place, we are able to run an analysis job to find out the standard of our agent in quantitative phrases. On this case, we use a mixture of built-in judges (Relevance and Security), a customized guideline that evaluates whether or not the agent returned information in the proper format, and a prompt-based customized decide that evaluates the standard of the scene returned relative to the person question on a 1-5 scale. Fortunate for us our agent appears to carry out nice primarily based on our LLM decide suggestions!

Inside MLflow 3, we are able to additionally dive deeper into the traces to grasp how our mannequin is performing and perceive the decide’s rationale behind each response. These observation-level particulars are extraordinarily helpful for digging into edge instances, making corresponding modifications to the agent definition, and seeing how these modifications affect efficiency. This speedy iteration and growth loop is extraordinarily highly effective for constructing high-quality brokers. We not are flying blind, and we now have a transparent quantitative view into the efficiency of our utility.
Databricks Assessment App
Whereas LLMs-as-Judges are extraordinarily helpful and infrequently obligatory for scalability, typically subject-matter knowledgeable suggestions is required to really feel assured to maneuver to manufacturing, in addition to to enhance the general efficiency of the agent. Material consultants are sometimes not the AI engineers growing the agentic course of, so we’d like a approach to collect suggestions and combine it again into our product and judges.
The Assessment App that comes with deployed brokers by way of the Agent Framework gives this performance out of the field. Topic Matter Consultants can both work together in free-form with the agent, or engineers can create customized labeling periods that ask subject material consultants to judge particular examples. This may be extraordinarily helpful for observing how the agent performs on difficult instances, and even as “unit-testing” on a collection of check instances that is perhaps extremely consultant of end-user requests. This suggestions – optimistic or adverse – is straight built-in into the analysis dataset, making a “gold-standard” that can be utilized for downstream fine-tuning, in addition to bettering automated judges.
Agentic analysis is actually difficult and might be time-consuming, requiring coordination and funding throughout companion groups, together with subject material knowledgeable time, which can be perceived as exterior the scope of regular function necessities. At Databricks, we view evaluations as the muse of agentic utility constructing, and it’s vital that organizations acknowledge the significance of analysis as a core element of the agentic growth course of.
Deploying the Agent with Databricks Mannequin Serving and MCP
Constructing brokers on Databricks gives versatile choices for deployment in each batch and real-time use instances. On this situation, We leverage Databricks Mannequin Serving to generate a scalable, safe, real-time endpoint that integrates downstream by way of the REST API. As a easy instance, we expose this by way of a Databricks app that additionally capabilities as a customized Mannequin Context Protocol (MCP) server, which permits us to leverage this agent exterior of Databricks as a software.
As an extension to the core performance, we are able to combine image-to-text capabilities into the Databricks app. Under is an instance the place an LLM parses the inbound picture, generates a textual content caption, and submits a customized request to the content material placement agent together with a desired target market. On this case, we leverage a multi-agent structure to personalize an advert picture utilizing the Pet Advert Picture Generator, and requested for a placement:

By wrapping this agent in a customized MCP server, it extends the mixing choices for advertisers, publishers, and media planners into the prevailing adtech ecosystem.
Conclusion
By offering a scalable, real-time, and deeply contextual placement engine, this AI Agent strikes past easy key phrases to ship considerably larger advert relevance, straight bettering marketing campaign efficiency and decreasing advert waste for advertisers and publishers alike.
Study Extra About AI Brokers on Databricks: Discover our devoted sources on constructing and deploying Giant Language Fashions and AI Brokers on the Databricks Lakehouse Platform.
Discuss to an Skilled: Prepared to use this to what you are promoting? Contact our workforce to debate how Databricks can assist you construct and scale your next-generation promoting resolution.
