Skip to main content

Harnessing Real-Time Data and AI for Retail Innovation

Summary

  • Real-time retail innovation: Build end-to-end applications combining real-time data pipelines, streaming analytics, and generative AI to revolutionize retail operations on the Databricks Data and AI platform.
  • Intelligent customer experiences: Use streaming customer data and AI to power real-time personalization, recommendation engines, and dynamic pricing strategies that drive retail growth.
  • Scalable data foundation: Delta Live Tables and the Databricks Data and AI platform enable declarative, production-grade pipelines for retail data processing at any scale.

Harnessing Real-Time Data and AI for Retail Innovation

Watch: Harnessing Real-Time Data and AI for Retail Innovation
Talk by Lorenz Verzosa, Senior Specialist Solutions Architect, Databricks ; Tristen Wentling, Lead Solutions Architect, Databricks
This talk explores using advanced data processing and generative AI techniques to revolutionize the retail industry. Using Databricks, we will discuss how cutting-edge technologies enable real-time data analysis and machine learning applications, creating a powerful ecosystem for large-scale, data-driven retail solutions. Attendees will gain insights into architecting scalable data pipelines for retail operations and implementing advanced analytics on streaming customer data. Discover how these integrated technologies drive innovation in retail, enhancing customer experiences, streamlining operations and enabling data-driven decision-making. Learn how retailers can leverage these tools to gain a competitive edge in the rapidly evolving digital marketplace, ultimately driving growth and adaptability in the face of changing consumer behaviors and market dynamics.
Here’s more to explore:
Production ready data pipelines for analytics and AI: https://www.databricks.com/solutions/data-engineering
The Big Book of Data Engineering: https://www.databricks.com/resources/ebook/big-book-data-engineering-2nd-edition
See all the product announcements from Data + AI Summit: https://www.databricks.com/events/dataaisummit-2025-announcements

Chapters

FAQs

What are common retail use cases for AI?

Real-time recommendations, dynamic pricing, inventory optimization, customer churn prediction, and personalized marketing—all powered by streaming data on the Databricks Data and AI platform.

How do we handle real-time customer data?

Combine streaming ingestion with Delta Live Tables for declarative pipeline management, enabling rapid analysis and AI-powered decision-making on fresh customer data.

How does the Databricks Data and AI platform handle large-scale retail data processing?

The Databricks Data and AI platform processes retail data at scale using Apache Spark's distributed computing capabilities combined with Delta Live Tables for declarative pipeline orchestration. This architecture enables retailers to ingest streaming customer behavior data, apply AI functions like sentiment analysis and personalization directly within SQL queries, and execute complex workflows on massive datasets in real time. The integrated approach eliminates manual pipeline management and delivers fresh insights that drive dynamic pricing, inventory optimization, and personalized recommendations.

What advantages does a lakehouse architecture provide for retail data workflows?

A lakehouse architecture like Databricks combines the performance of data warehouses with the flexibility of data lakes, enabling retailers to manage structured transactions alongside raw customer data in a single repository. This unified approach eliminates data silos and the complexity of maintaining separate systems, allowing retail teams to run both analytical workloads and real-time operational queries on the same data foundation. Built-in generative AI tools, Delta Lake's ACID guarantees, and declarative pipeline orchestration make it practical to build end-to-end retail solutions that span customer profiling, recommendations, and inventory management.

Full transcript

0:00 Introduction and vision

All right. Who's ready to get started? Want to have some fun? Cool. Yeah, I am. It's always a mystery. There's no telling what words are going to pop out of my mouth. But thank you guys and welcome. This is our talk, harnessing real-time data and AI for retail innovation. And that was really like the best title I could possibly come up with for this because we're just merging together so many different things. So just to kind of capture the whole idea in essence of what we're doing is we want to capture something that looks like an end to-end application.
How do you actually stitch together a lot of these different technologies that we talk about all the time? So hopefully that's the main thing you guys take away today. Um just lean into it. I know some of you know me. I see my customers made it. I know we were all questioning last night whether any of us would make it to this session. Um, but we're all glad to be here now. Uh, I'm a lead solutions architect here at Data Brick.
I data Bricks. I work across the retail and consumer package goods industries. Uh, my favorite customer at the moment is Unilver. Thank you guys for coming out and supporting me. Uh, no, just I work with those guys all the time. I love working with them every day. Uh, it's truly a joy. Um, as well as working with all the other customers across the whole vertical that I get chance to interact with. Um I'm one of the streaming uh SMMES here at Data Bricks.
I'm also an embedded product lead for Delta like uh Delta Live Tables DT whichever of the five names that you remember over the past few years. Uh we will be featuring it a bit today. And plot twist, the name is going to change again in two days. So enjoy that. Remember that little tidbit, too. But uh I want to introduce a good friend of mine, Lorenz. Yes. uh Lorenzosa, senior specialist solutions architect also in the retail space and I all my customers are my favorite customers.
So I want you to know that and yeah been working with for a very long time and kind of glad to kind of present this with for you guys. Awesome. So let's get started. And when Lenin says a long time like we've actually worked together here at Data Bricks for almost six years uh is when we first got assigned together I think. So that's right. It's been a a wild ride, a lot to say and a lot of change. And uh this actually kind of embodies how I approach a lot of what I do every day.
Like I like to live in the future and build what seems interesting. And for anybody who doesn't know what is, he's the starter of Y Cominator, starter of Hacker News. He's really been an influential figure in the tech space. And really thinking about like what you can do down the road is what drives everything we do. We think about our road maps. We think about our project initiatives. We think about budgets. Everything we have to come up with and report on and plan for is always thinking about the future.
So it's always good to keep an eye on that too. Now what I want to talk about today is how is from our perspective especially on like kind of a little more on like the data engineering side, the practical application side, how is genai like actually impacting the way we approach the way we solve problems, right? This is changing the face of the way we actually want to jump on top of challenges. Different kinds of tools we can bring to bat as we go to build new solutions.
We can start integrating things into our data pipelines if we have the right tooling. And that's kind of where this is going to lead up to. But I mean just seeing the reports from some of our like leading SI partners in the country, these thought leaders about how important it is to embrace these technologies and bring them into everything that we're doing as we build out our solutions. like this is something we cannot ignore and leave behind.
We have to bring these to bear or we're going to get left behind. We're going to be stuck tending to the legacy technologies while other people are getting promotions and rewards and everything else. So, we don't want that to happen to us. We want to stay on the front edge, the bleeding edge. We want to keep adopting the new technologies and make sure we're getting everything in our tech stack that we need to, but skipping a lot of the stuff that we don't.
So, what does it take to kind of get to the next level there? Well, we need tools that enable us to do some of these new things that are becoming hyper critical but possible to do at scale. Things like social listening. We want to be able to measure sentiment, do sentiment analysis, which you'll see during this presentation today. We need tools that we can use to help generate uh personalized customer content in a highly scalable efficient way.
We need tools that enable us to do things more effectively and efficiently. We need assistance. We need coding assistance. We need question and answer bots. We need all these things plugged in. And we want it all in one place, right? We don't want to have five different workspaces open just to access all of our different tools if we don't need to, right? We we'd rather have all that available to us through one single lens as much as possible.
And so that's really kind of like why and a different shift from what I'm normally talking about with open source stuff. like this is really all about how we're tying a lot of this together inside of data bricks and the data intelligence platform and what makes it easy to do that. So we get these built-in generative AI tools, things that we can use inside of just simple SQL queries like AI query or AI sentiment or AI parse.
Like these let us just inside of a SQL query take and simply wrap a small function that lets us do things at massive scale on data bricks with the power of Apache Spark behind it. Right? We get the amazing scalability of distributed parallel compute applying these functions in bulk across a wide scale of data which lets us do things much more faster. effectively and efficiently. We can couple all that together with declarative pipelines that lets us seamlessly stitch things together and create nice neat endto-end workflows.
And we can orchestrate all that with jobs. We can use if else's conditional logic, all kinds of stuff to build complex workflows that match our business needs and our business cadence. If we don't have a daily SLA or an hourly SLA, we can run it weekly. If we need that down to a like a five minute increment interval, grout it. We'll just reset the schedule. We'll adapt it to meet our needs when we have the needs. So, all that said, all this stuff about getting all these tools into one place, I feel like we're actually starting to get to a place where we have a lot of that.
And that's really exciting to me as somebody who's been here for several years and seen the platform change and grow and evolve to have all the things we have now. I couldn't have even imagined half of it like six years ago. So, let's talk about what we're actually going to look at today. I I know it's been a little bit of a suspense leading up to it. I left out a lot of details in the abstract. I'll get let you guys in on secret.

6:25 Solution overview

We wrote the abstract, got it accepted, and said, "Okay, now we got to go build it." So, let's go do that. That's why I have a help. Um couldn't have done it without, hands down. Uh but this is something that I've actually thought about a little bit and this is actually based on several different customer conversations that I've had across multiple countries. I've been up to Canada talking to me people about some of the uh conversations that we have in here today.
So the idea is that this doesn't have to be AWS. Choose your cloud provider as you wish. We have live data that exists in our in systems whether it's purchasing portals or uh direct to consumer websites or uh just transaction feeds from actual retail locations. We're getting live data all the time. Now it may come in batches. It might be real-time streams. Whatever format that takes, we want to bring that in. And so that's actually why I left it a little bit of a white box.
Choose your stream provider. You might be using autoloader to pick up CSV files. You might be reading off of CFKA or Pulsar streams. Whatever flavor that looks like, we need to be thinking about incremental processing there. And we're going to use DT to do a lot of that. Now, we also get like live review feeds from some of these providers and sites and stuff, right? That information can be really vital and that's actually going to be key to a lot of what we do here today because what we're looking at this is a little bit different approach.
You know, a lot of people think about recommendations. And actually, does anybody know what the canonical example for Apache Spark is for recommendations? Movies. If you go look at the documentation, say Spark recommendations. I guarantee you if you Google it, you're going to see the movies reference. That was so frustrating to me when I was like, okay, how do I apply movies to retail? Like I could do different products, I guess, but how do I even compare that?
There's so many products. Like with movies, yeah, there's thousands of movies out there. With retail products, we have hundreds of thousands and millions of different SKs that we have to consider. So it it becomes a scalability problem, too, when we start to think about it that way. So how about we compare and look for similar users? So I went and I did a little bit of research and I was looking at user user recommendation systems.
I'm like, okay, cool. Well, how do we marry this up together? Well, let's think about what that means. If I find similar users, then they have a lot of things in common. It might be a geographical, it might be uh frequency of purchase history, things like that. Uh but I can actually take that information, I can match those users up, and then I can say, hey, what did user B buy that user A hasn't bought yet? And that's where this gets really interesting, right?
Because now what what's some of the biggest problems we see with recommendation systems? I just bought that, right? I get those emails every day. I bought something and then they recommend, hey, maybe you'd like to buy another patio set. Why would I need another patio set? I don't think I do. Uh, so filtering those down, looking for those products that are unpurchased from people that buy things similar to you with similar types of like uh purchasing bands, right?
If you're a high spender and then you're going to get matched up more likely with other high spenders. If you're a budget buyer, those feature variables in there are going to say, "Yeah, these people go together." You pull in all those unpurchased items, you already have really great alignment, right? We're not just helping our business, we're helping people get the things they actually want to buy. So, it really winds up driving a lot of great positive change in the way we do recommendations.
Now, there's a whole additional step to this. This is purely optional. kind of depends on your application. You could do this in more of a real-time application where user purchases something and then you want to splash something up right there on that thank you screen, right? And then you could suggest, hey, here's a couple products in which case you may want to premputee some of that just so it's live and ready to go.
Another approach that we've seen taking shape a lot is hyper segmented uh hyperpersonalization, right? we we get down to these like fine grain different uh segmentation groups and we want to create like personalized content for each of them. You can pair all this stuff together. In fact, I've presented on this at NRF with uh one of these partners on this list. I won't say which one. We like all of our partners equally.
Um but we can take all of this campaign data. You can get fine grained with it and you can kind of programmatically mix and match your Genai generated content with your extremely personalized product recommendations and create a very specific email for every single customer that speaks to them that understands them and is recommending things they want which makes it more favorable again on both sides of the transaction.
So that's kind of the overview of what we wanted to look at here today. What's really key in this process here? We want to process and orchestrate data. We have jobs. We have DT. We have great open source technologies that are driving everything under the hood here to give us fast, efficient, scalable power for calculating large amounts of data or small amounts. If we have a 100 customers or 100 million customers, we want to be able to do the same things.

11:26 Key technology stack

So, highly adaptable fits all of our use cases. We need to build different kinds of models, not just recommendation models. We got forecasting. We want to do category forecasting, demand forecasting, right? We've got purchasing demands. We need to fill all kinds of different models. And for all of that, we have to build, we have to deploy, we have to monitor, we need to track, we need to iterate and improve upon each of those models over time.
Lots of work there. You need a tool like MLflow to help you keep track of all that experimentation and bring all those tools together to make allow you to do it in one place. And then one of the key steps there, I didn't really dig into it very much, but all those partner relationships, all those are based around delta sharing. We don't need to send like FTP requests back and forth with all of our partners anymore, right?
We can openly share data without building additional copies of that data neatly and efficiently. We just say, "Hey, here's this table that I updated. Go ahead and build a campaign off of that." And that makes it really easy, simple, and cheap to be able to do all this. So, with that, little preview where we're going to go with everything, but I'm actually going to hand it off to, who is my DT master for this application, and uh let him talk about DT for a few minutes.
Sure. Thank you. So when we're looking at kind of putting things together, all we really care about is the transformation logic. But the thing is though, there's a lot of things you have to keep in mind. Not only is it the type of data we're trying to pull in, all of that stuff as well. You have to look at the infrastructure. You have to look at putting it all together. And you don't really care about all that. All you want to do is get this ready, get this into production, get this going, get get some value there.

13:12 Declarative pipelines with DLT

So how are we going to solve that with and this kind of what I just explained here of course but we're going to solve that with DT and the reason we're doing this case or declarative pipelines um we're doing it in this case because it simplifies authoring it makes it much easier to just go through you just declare either a streaming table your materialized views uh we're going to have lots of sessions on that I'm not going to go too much detail into that part but what I want to show with you guys is really what that looks like end to end when that comes into implementation and yes so we're simplifying the authoring here all you're really caring about is what does it take to put the data into these tables what does it take to kind of go through and another thing I want to add on top of this as well and it's not in any of this or anything I'm going to show as well is this code that I'm going to show later on it is both batch and streaming so you don't have to think of it in terms of like okay I'm just going to have to do one type of pipeline here for batch another type of pipeline here for streaming.
You write it all once, you test it in batch, and then when it comes time to deploy it and you want it to be streaming, you can set it to stream. Let's say, you know, you you run it, you're getting some data, but you know what? It's a little bit too expensive. You can change it to batch. So, you don't have to be strictly tied to a certain way based off your code. So, your code and the way you execute are separated. And that's going to be that's a very powerful part.
And so one thing that is here as well is the fact that um what I'm calling out with this particular slide right here is everything is done at scale. um everything. So everything from putting together your expectations, so putting together, you know, data cleansing, uh putting together uh you know, scalability, is your data bursting? I mean, that's stuff you don't have to worry about. It's all at scale and it'll all be deployed in and fully tested and deployed and put into production.
And these are all just leveraging all of your, you know, your models and your um and your uh and everything that you're putting together. And this is just a little this slide, you know, I put it in here just so you can kind of get an idea of kind of like the two different sides here. Certainly, there's no wrong way to do it. Um, the old way though with Spark is you had to really think about, okay, I'm creating these streaming these streaming pipelines.

15:41 GenAI and model serving

I had to put it through I have to think about like, okay, what about this part right here, this watermark? I have to think about other things. With DT, you don't have to think about that. It is nice to think about that. You can get a lot of performance out of that, but you don't really have to think about that with the DT side. And that's really the key part of it. It really is about just getting what you want to do, get it out there quickly, and then iterating on it while it's up there in production.
So, that's really the real value with it. All right, all right, now we can get into the really fun stuff. I'm going to need some water for that. Hold on. What is generative AI? Have we heard this like a million times in the past two years? Probably, but just to make sure everybody's on the same page, right? Generative AI, we're really just talking about the class of large language, image, uh, video, audio, linear model objects that come out of this deep learning space, right?
There it's just kind of an extension of things we've already been familiar with. Everybody's seen TensorFlow for years. There's no surprise when it comes to like the deep learning area even if we're not familiar. But generative AI in its own it's it's advanced a little bit. We we got a little bit better at doing some of the things we were trying to do which is amazing. But it still just fits into the larger AI space.
So we need to think of these things as models. We're going to apply the models to things as they live in data pipelines. We're going to put governance and controls around everything. It's really just a model just happens to be big and hard to store and serialize and everything else. That's the AI engineers problem. Now we also get these functions like I mentioned this before. We have this AI query function. AI query lets us take and plug any model of our choosing.
So I'm not sure what portion of you have models deployed in data bricks or if you're using foundation models. If you have your own custom fine-tune models you trained on another platform and imported into the platform or if you even fine-tune a model with your own examples based off of one of those foundation models, it doesn't matter what flavor it is. If you're hosting that through data model serving, you can just use AI query as a front end and still access it in your SQL code, which is super cool, right?
No matter how advanced that model is, as long as it's got the support it needs to be able to use, you can use it inside of a SQL function or inside of a DT SQL function. Uh so it becomes part of your data pipeline. But all this is based on AI model serving. You get everything backed by Kubernetes. Everything that we love about hypers scalability of model serving platforms available with a quick command, which is really helpful if we want to enable other users, right?
Maybe they're not professional AI engineers. Maybe they're not building feature engineering pipelines. Maybe they just want to be able to do sentiment analysis in a bunch of like call center data, right? Having the ability to wrap all that in one little query and pack that away and hide it from your end users can be highly valuable. But that said, like any flavor of model that supports that, like we have to make cho choices and evaluation.
So you get into a whole bunch of stuff about evaluation frameworks. We're not going to dig into all that today. uh but all that is available but so are several other functions right AI query is very generic we need to provide some kind of prompting analyzing sentiment stuff like that's much more straightforward right it it's a function application of a model and so we kind of have a programmatic way of thinking about that well we can embody that in code so all of these functions also exist to kind of serve more specific functions inside of that they're all really similar to AI query though they function the same way under the hood But what's this really mean?
Well, then we get into batch inference pipelines. So, it's simple to say yes, you can take this query and you can do inference on one line of text, but that starts to get much more complicated when we're talking about doing this on thousands or millions of records, right? So, now we need tools that are better equipped to do it. So maybe we can send these instead of line by line and face serialization problems, we can actually send them down a bit deeper and do these as like microbatches.
Kind of the same way we think about streaming, right? We want to send batches of data to get clumped together so we can do things more efficiently and effectively. So that's what's kind of going along with batch inference here under the hood. We get to bring all that in. And so what when we do that with the foundation model, this is like our initial data pipeline and we rapidly iterate. We can do all of our sentiment analysis.
We can do our inferences, but then we collect all that data, too. We see how well it does. We evaluate it over time. We bring that back in. And then we can use all of those examples to fine-tune a model and get even better on this. So, it becomes like a feedback loop there. Uh, really critical that process. So, batch inference pipelines, fine-tune models, all of it kind of works together. You wind up deploying that model back.
You you now have a new AI query function with your fine-tuned model. You continue collecting examples. You iterate over time. So now you're not just doing MLOps, you're doing AI ops on all of your data engineering functions that it winds up becoming a whole lot to keep track of, but something you can do very quickly, efficiently, and easily just by clicking in a few tools, right? This is where you start getting that value of everything being in one place, right?
You go into Unity catalog and you have your models served up in there and you can control your access and permissions to that. Who has access to use those models? If I have big expensive models and little cheap models, keeping track of all that can be really cumbersome, but maybe all of your users don't need to see that. Maybe they just need access to a few things. So all that feeds in together. We we wind up getting these data flows, right?
We're going to do batch inference. We're going to do AI analyze sentiment on a million records or a billion records, but it's going to flow through. We're going to do our LLM analysis and we're going to get sentiment scores. That's great. Now we can get some feedback from our data and how that looks. But how do we use that to make meaningful recommendations? Well, this is where it starts to get hard, right? Data segmentation.

21:40 Customer profiling and data

Uh, how do I segment my customers? That's a great question. This is why you still need professional data scientists on your staff like no matter what level of tooling you're able to bring into your environment because sometimes there are just decisions that need to be made. Now we may not always have the biggest staff. It might be just a few analysts or it might be an extensive like research arm in your organization.
But somewhere somebody's making these decisions on how to do different kinds of distribution analyses to look am I breaking apart my customer segmentations correctly. Everybody that thinks marketers actually don't do anything like they actually do quite a bit. They have to make these decisions a lot. They use tools to help them a lot. But this is a really critical piece of your entire journey. And it also helps you solve some scalability challenges.
How you segment your customers may determine how you distribute your data and how you actually compute things like similarity scores. Because when you take uh like 10,000 customers and you have to do a cross join to do like a similarity score across those, that's no longer just 10,000 records, is it? That's like a billion records. Like it massively multiplies the scale of your problem just when you get into like five digits.
Now to keep amplifying that out, think about like national customer databases. Like this is a a very large problem to try and solve, especially when you start getting into the nitty-gritty details. So breaking down your segmentation smartly can actually assist this quite a bit. Now there are different ways to approach this. I mentioned similarity matching. I'm a big fan of cosine similarity. It's very easy and straightforward algorithm to write.

23:35 Recommendation strategies

You do that and then you can go into alternating these squares methods and you can try and identify those similar users. That's great. This is really costly and expensive to run. So maybe sometimes there's an alternative approach that's actually more efficient. So I actually want to credit with this one right here. He was just like, "Hey, why don't we just use a vector search? If I just want to find a similar record and I have all my customer information in there with all the same feature variables and everything, I can just look for the most similar customers using a vector search."
And it was highly effective and much faster. Um, so sometimes just thinking about the tools that you have available in your toolkit can help you do things more efficiently, too. And then we already kind of talked about our segmentation. We're going to go through our segmentation. We're going to identify the most similar customers and we're going to go back to that idea that we said we're going to find those unpurchased products.
We're going to pull them back in and that's what we're going to like take our top five, three, whichever number and recommend to our uh customer in question. And then we're going to open this up. We're going to use our delta sharing. We're going to share this with our marketing uh partners, whichever way we're creating campaigns, whether we're generating new content on top of it. We're going to put all that together.
We're going to ship it out and we're going to start turning those recommendations into sales and revenue. So, that's really kind of the whole idea in to end. So, I'm actually going to hand it. Yes. And let's make sure. And you can actually see what this thing looks like in code. Oh, I need to sign in. Never signed in. I feel like I walk away or look at the ceiling for 30 seconds and I'm no longer signed in. So, this is I believe this is the part that you're looking for.

25:13 Implementation walkthrough

So, we talked about all this stuff. We had these nice slides, but you know what? What you really care about is you want to see what this looks like. So, let me pull up hopefully. Here we go. So, let me just pull this over to the side here. So, yeah, and I kind of wish this uh was a better way to kind of view this all here, but this was all developed for developers, not necessarily for presentation. But, so what we have here is the overall graph of the DT or declarative pipeline.
Um, and there's going to be two parts of it. The first part of this is really getting the similar customers. So it's the pipeline from end to end of getting similar customers putting that into a vector index and then showing that and then kind of putting uh having an output of similar customers. The second part of that is taking reviews running those through an LLM to kind of come up with uh characteristics come up with sentiment and then getting out of that um some additional information some metadata that you can then apply to your similar customers.
And then you get your um and you get your unpurchased items and rank them. And that is really the core key end to end of how this works. So it's simple and it's conceptually simple. It's something that's been, you know, a little bit more difficult to implement in the past, but now with DT and with batch inference and vector search, it's actually a lot simpler to implement. So let me kind of step through each part of it.
So the first part here, I'm going to talk about the upper pipeline here. Um I'm read reading in data. Uh this is all just stored within Delta Lake, processing that. I'm going through that and then coming up with the similar customers. Um there's a a little bit of a jump. This little um piece here is misleading. That is actually doing the vector that is doing the vector search. It's a bit misleading. I put it I made it this way to make it very clear what's going on here, but you'll see once I kind of show that part.
The second part of this is is going to be on the bottom layer here is really just showing the reviews. I'm from here I'm reading I'm kind of at this point simulating what it's like if we had it through some sort of content management publishing system like maybe from you know traditional web services and just having that go through. So reading from Kafka parsing that processing so the processing part is it's a very boring name but that's the most interesting part for you guys.
That's where we apply the LLM and get some more additional information out of that and then interpreting the data out of the LLM and then we then kind of go and merge the two. So we get the similar customers, we get the ranked products, we get unpurchased items and that becomes our recommendation. So that is really the key end to end piece there. So first I'm going to show the top. So let me go through the source code here.
Customer similarity Let me go through here. So the kind of the key part is really you want to formulate your customer profile. And so step one of course want to do the aggregation here. So I'm just doing this all just all through declarative pipelines. I'm not going to go too much into it. Um certainly it's just standard um you know pi spark that's going on here. I'm using some panda stuff in here to kind of do that to kind of make make a little bit more efficient.
But at the end of the day, this is all normal pi spark. And you can see here I'm coming up with just some in information that we can use to determine what is a similar customer. And because of the way I'm doing this and I want to do it in a more efficient way, I'm using the we have applied changes here so that we'll do continual updates. And that is really kind of like the key of making it so that you know you get a consistent view of the data.
So using the applied changes, you know, we designed that around CDC, but it doesn't have to be for CDC. So that is, you know, just something to keep in mind. Um, the next part of that, I'm going to skip that. This is really just trying to collapse a lot of things, make them a little bit more denormalized. Um, right here is really now we want to formulate the profile. Now, this is the part I think is really going to be really important for you guys is really coming up with the profile.
Um, what I'm doing here is I'm doing something pretty basic. I'm just taking a JSON uh dump of this Python Python object. But what I would probably do and when it comes to actually doing this in production is I would actually instead of just having it as the dump of the Python object, you can have that there. But I would actually turn that and use you can apply your embedding model at this point. So once you apply your embedding model at this point you're going to save a lot of cost because every time you call a vector search you have to take the profile and you have to run it against the embedding model which is a cost and it adds a little latency.
What I would do is because you can do this is I would just premp compute your embeddings and then one thing that makes it really cool is that you can however you want to do them embeddings is however you want to do it and embedding is really just for the people who are not familiar it's really just a list or an array of floats or doubles or you know numeric types numeric yes thank you it's a it's an array of numerics that we use to do the cosine similarity um by just calculating it here that's one extra step and that actually improves the latency And so, but for this case, I'm just doing it this way.
It kind of demonstrates what's going on here. And then this forms, so all of this here, and once we get that profile out there, that forms the basis for putting together the uh vector index. So, let me just show that really fast. So, if we go here. Hey. Yes. Can you turn it back to light mode because dark mode is kind of difficult to see. I tr you turn it to light mode. I don't know when the last time I used light mode was Oh, Think if I go into settings appearance.
No. Preferences scene. Prefer light. You know, when you get back to work, you're going to be like, "Why is this bright?" All right. Yeah, I know, right? Yeah. Much better. Now you can figure out which Yeah, screen I can just reload it. That's why I have a list of links here. There we go. All right. So, I'm not going to go too much into it, but this is you could use all it is when you want to create a vector index. It's just one click.
And it is actually, oh, it's not there. That's all right. It's a oneclick way to create it. Um, you can all do it through through the catalog. And that's really how I created the vector index in this case. Um, ultimately Oh, because it's logged out. Um, ultimately I glanced at the ceiling. Oh, that's probably what happened. So, ultimately, and of course, I can't show the data because you're on your account, but that's all right.
Ultimately what comes out of it is you can see here we have a vector profile and that is really the embedding. So however you want to do the embedding is really how you do it. In this case I just haded it I had it right to a rightback table to kind of show what that looks like but you know it's up to you how you really want it to go. So that is really how you get to the similar customers. Now let's look at the next part which is well actually let me take that back.
We do have one more step with the similar customers and that is going to be I have to scroll down a little bit to get to that. Here we go. So this is the similar customer part here and this is really just a UDF that I have here and this is doing the vector search. So what I'm doing in this case is I want 10 customers but the reason I kind of put 11 here is because you know a similar customer could be yourself. So put 11, subtract one, that gives you uh 10.
And that is really kind of the key part of it here of getting that. So you don't have to do this crazy cross join. All you do is just go you you take the customer ID, you take your embeddings. In this case, I'm putting customer profile, but you can just put the embeddings and what comes out is a list of similar customers and they're ranked, so it's in order as well, which is pretty nice. And that comes with the similar customers.
So the second part of this and I'm going to have to go through this really fast is really then okay so what does it look like we have the similar customers now we need to get the reviews and figure out what what what can we get out of the reviews so to kind of cut it short we have the initial part here which is really just loading in from Kafka and then kind of parsing out the different parts of it we don't care about that this is the part that we care about uh is really then we want to apply those and we want to apply a model on this so I'm applying in this case I just chose a random model.
It was the cheap one. Obviously, you're going to want to do a little bit more work. Do a little bit more evaluation to find the uh model that's appropriate for you. Uh but I just chose this one because it was cheap. Um not not saying anything about the results of that model, by the way. And also just a simple prompt engineer here. Um just figuring out, okay, I want sentiment. I want uh I want to translate because we had Portuguese.
I want to translate in these into English. And I want you to figure out like what type of review this is. And so that goes through here. We use AI query here to get all that information out. And the output of that is and it's because I told it to do this is going to be JSON. So the next part of that then is to then kind of parse that and clean that. And that comes up with the JSON result. So we kind of put that all together.
And so once we have that, we have the reviews, we have product scores, we have similar customers, at that point then is we just pull it all together and that comes up with the recommendation. So the recommendation is taking a customer, taking uh similar customers, finding all the products that were bought by the customer that were ranked highly and then removing the customer the items that customer has bought. So that just leaves unpurchased items and that is really kind of it's not too expensive.
That part of the whole thing is really not that expensive. It's just a matter of just doing the joins getting everything in there and that comes up with the recommendations. So kind of the last part of that there is taking those is taking those uh products and then outputting that to Kafka coming up with the recommendations and cool. So two things I wanted to call out here. One is this is the application of using AI query to apply LLMs in your pipelines.

36:01 Conclusion and takeaways

Now you know you don't have to do it through DT but for your pipelines and to get things um through a pipeline and using it all through using DT this is the way to go and it's very very efficient to use and then of course the second part of this as well is a similarity. So this is how it looks in code and I wanted to call out here because this is really the second key part of it. Everything else is just really simple transformations and this is how it looks right here.
So that's how we come up with the similarity. All right. Awesome. Thanks. Yeah, no problem. I did feel like you left one little piece out there. So part of the idea behind incrementalizing this this process of looking at the review data getting that in real time into your system. This allows us to account for recency and relevancy of those products also. So this is actually working to help capture like market trends in products especially at large scale where even minor deviations in like rating scores can have a massive impact.
So this makes sure we're always recommending the best products to our customers. Oh yes and that you bring up a good point there. The way I constructed the pipeline is it's triggered by two things. One is the order. So as soon as an order is placed that triggers it. The second one as well as soon as a review is placed that triggers it. So it's always the most recent. So, that's something that as a takeaway here is you want your backing facts to always be either the orders or you want it to be the reviews, the most recent piece of information that you can use to really to make the recommendation rich.
Awesome. All right. And then one more thing, I just had to say it while I was up here. Uh, if you want to get started on some of this yourself, I think these are great next steps to start exploring the ideas that we've laid out here for you today. Um one is on sentiment analysis of taking and applying these uh at scale. The other is for batch inference a little more detailed information about that process uh and what makes it different from doing things you know like a record at a time how that actually works under the hood because the better you understand that the easier it is to sell to your boss of why you should you know take some time to implement it.
Um but other than that thank you guys so much for coming out today uh and listening to what we had put together for you. I hope you found it enjoyable, rewarding experience and uh look forward to seeing you all around the conference the rest of the week. Thank you.

Learn more about the Databricks Data and AI platform.

The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.