<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Samira Naghiloo on Medium]]></title>
        <description><![CDATA[Stories by Samira Naghiloo on Medium]]></description>
        <link>https://medium.com/@samira.naghiloo_87074?source=rss-b7424e9f1a99------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*j6faMK0lbuc4KJ5U</url>
            <title>Stories by Samira Naghiloo on Medium</title>
            <link>https://medium.com/@samira.naghiloo_87074?source=rss-b7424e9f1a99------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 17:43:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@samira.naghiloo_87074/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Predicting Customer Journey Phases in Real Time Using Contextual Bandits on Vertex AI]]></title>
            <link>https://medium.com/flat-pack-tech/predicting-customer-journey-phases-in-real-time-using-contextual-bandits-on-vertex-ai-e8eba4a67714?source=rss-b7424e9f1a99------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8eba4a67714</guid>
            <dc:creator><![CDATA[Samira Naghiloo]]></dc:creator>
            <pubDate>Fri, 02 May 2025 09:09:10 GMT</pubDate>
            <atom:updated>2025-05-02T09:09:10.148Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://medium.com/u/b7424e9f1a99">Samira Naghiloo</a>, <a href="https://medium.com/u/75eafc8fd9b6">Nirmal Rajendran</a></p><p>Delivering real-time personalized customer experiences at scale is a key challenge in large digital ecosystems. To solve this, we focused on predicting customer journey steps, such as which content or action to display using a real-time online learning system powered by contextual bandits. We implemented this system with <strong>Vowpal Wabbit </strong>framework, Google Cloud <strong>Vertex AI </strong>and C<strong>loud Run</strong>, and a feedback loop that continuously refines the recommendations with each user interaction.</p><p><strong>Why does this matter?</strong><br> In digital environments where user attention is fleeting and journeys are non-linear, timing and relevance are everything. Predicting the right step in the user journey, and selecting content that aligns with it, enables a meaningful, engaging, and useful experiences. This approach applies broadly to any real-time content recommendation challenge, not just customer journey mapping.</p><p>In this blog post, we’ll walk through the technical design of our system, including:</p><ul><li>Feature creation and real-time serving</li><li>Model training and deployment</li><li>Inference and feedback collection</li><li>Continuous learning and system evolution</li></ul><p>We won’t focus on use case-specific results or business metrics here. Instead, this post highlights the <strong>technical design</strong>, <strong>online learning pipeline</strong>, and the <strong>robust infrastructure</strong> we built for scalable personalization.</p><h3>Why Contextual Bandits?</h3><p>In fast-changing digital environments, traditional recommender systems can struggle to adapt quickly to new data or user behavior. Contextual bandits offer a powerful approach for <strong>online learning</strong>, striking a balance between:</p><ul><li><strong>Exploration</strong>: trying out different actions to gather user feedback</li><li><strong>Exploitation: </strong>using known successful content to maximize engagement</li></ul><p>Unlike classic multi-armed bandits that ignore context, contextual bandits use side information (user features such as interaction with page content or products, traffic channel, time spent, recency of activity,… ) to make smarter decisions. Compared to full reinforcement learning (which models how actions influence both immediate rewards and future states), contextual bandits simplify the setup by assuming that an action only affects the <strong>immediate reward</strong>, not the next state.</p><p>In our case:<br>Every time a user visits the page, the model gets context (features), makes a prediction (which action/content to show), and receives feedback later (e.g., click or no click). This feedback is used to update the model continuously. It’s like A/B testing on steroids, but smarter and adaptive.</p><ul><li><strong>Environment</strong>: IKEA website</li><li><strong>Actions</strong>: Predefined combinations of customer journey and phase (e.g., exploring kitchen idea, committing to a wardrobe purchase, etc.)</li><li><strong>Reward</strong>: User clicking on personalized content</li><li><strong>Context</strong>: User’s web behavior features</li></ul><p>The goal? Predict the most relevant journey-phase combination (action) and display the corresponding UX element (image and link) to maximize engagement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*wKUSuCgw9btTJBtn1VFJrA.png" /><figcaption>General functionality of contextual bandit model</figcaption></figure><h3>🧠 Overview of the System</h3><p>We break our solution into three main components:</p><h4>1. Feature Creation and Ingestion Pipeline</h4><p>Feature engineering is foundational in ML systems, and ours is no exception.</p><ul><li>We collect user interaction data (e.g., time spent, product area views, device type, active sessions, etc.) and write it to BigQuery.</li><li>Data is cleaned, aggregated, and transformed into user features.</li><li>Features are then pushed to <strong>Vertex AI Feature Store, </strong>which acts as a centralized and versioned source for real-time and batch access.</li></ul><p>This pipeline is triggered via <strong>Pub/Sub</strong>, ensuring fresh and relevant features are always available.</p><blockquote><em>🛠️ This pipeline is fault-tolerant and </em><strong><em>idempotent</em></strong><em> — meaning it can safely retry operations without data duplication or corruption.</em></blockquote><h4>2. Real-Time Inference and Feedback Loop (Prediction in ~40ms)</h4><p>When a user lands on a page and gives consent, the following happens:</p><ol><li>A /Predict API call is made (served via <strong>Cloud Run</strong> using <strong>FastAPI</strong>).</li><li>The system retrieves latest user features from Vertex AI Feature Store.</li><li>Features transform and pass to the <strong>Vowpal Wabbit</strong> model.</li><li>The model returns the best action (content/journey-phase).</li><li>The system logs the prediction and metadata in <strong>Firestore</strong>, setting a default reward (e.g., not clicked).</li></ol><p>If the user clicks the recommended content, a /Feedback API is triggered:</p><ul><li>The system updates the previously logged event with a <strong>positive reward</strong>.</li><li>This feedback is stored in Firestore and used for model training.</li></ul><p>The prediction response is returned in under <strong>40 milliseconds</strong>.</p><p>This design enables the model to <strong>continuously learn</strong> from fresh interaction data, adapting quickly to trends or behavior shifts.</p><h4>3. Training Pipeline: Continuous Learning with Vertex AI</h4><p>Our <strong>training pipeline</strong> is scheduled hourly and built on <strong>Vertex AI Pipelines</strong>, orchestrated via <strong>Vertex AI Scheduler</strong>.</p><p>Steps include:</p><ul><li><strong>Reward Extraction</strong>: Pull reward/cost records from Firestore. In our setup, we use a <strong>cost-based </strong>formulation, if a user clicks the recommended content, the cost is 0 (desired outcome); if not, the default cost is 1. This setup aligns with Vowpal Wabbit’s --cb_type ips approach for learning from user feedback.</li><li><strong>Feature Enrichment</strong>: Retrieve corresponding user features for those interactions.</li><li><strong>Training</strong>: Update the existing contextual bandit model using <strong>Vowpal Wabbit </strong>in a cost-sensitive, online learning mode.</li><li><strong>Evaluation</strong>: Perform <strong>progressive validation</strong> using off-policy evaluation (OPE) with inverse propensity scoring (IPS) to compare the candidate policy’s average cost against the current production policy.</li><li><strong>Auto-Deployment</strong>: If the new model performs better, it is deployed automatically to Cloud Run.</li></ul><p>Everything from feature extraction to deployment happens in a single unified pipeline.<br> The pipeline is centralized for training but <strong>multi-region</strong> in terms of feature retrieval and traffic handling, ensuring fast response and fault tolerance globally.</p><h3>🔍 How Vowpal Wabbit Fits In</h3><p><a href="https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/tutorials/python_Contextual_bandits_and_Vowpal_Wabbit.html#working-with-contextual-bandits-in-vowpal-wabbit">Vowpal Wabbit</a> (VW) is designed for large-scale, online machine learning system. It supports contextual bandits efficiently using linear models and feature hashing for fast updates and large-scale data.</p><p>We use VW’s --cb_explore_adf mode with --cb_type ips to support action-dependent features and unbiased reward estimation. We use <strong>epsilon-greedy</strong> exploration (--epsilon 0.2) and <strong>inverse propensity scoring (IPS)</strong> for learning from logged feedback. To let the model capture interactions between user and action features, we include -q UA, which enables feature cross-products between the User and Action namespaces.</p><p>Here’s an example of the VW command used in our training pipeline:<br><em>vw — cb_explore_adf — epsilon 0.2 — cb_type ips — quiet -q UA -d train_data.dat -i model.vw</em></p><h4>📦 Example Vowpal Wabbit Input Format</h4><p>A common barrier when working with Vowpal Wabbit is understanding its input format. Below is a simple example for both <strong>prediction</strong> and <strong>training</strong> using the action-dependent format (ADF).</p><p><strong>Prediction (no feedback yet):<br> </strong><em>shared |User featureName1={featureValue1} featureName2={featreValue2} …<br>|Action action=action1<br>|Action action=action2<br>|Action action=action3</em></p><p><strong>Training (with feedback):<br></strong><em>shared |User featureName1={featureValue1} featureName2={featreValue2} …<br>|Action action=action1<br>|Action action=action2<br>0:0.0:0.25 |Action action=action3</em></p><p>shared contains user context; <br>Each|Action is a candidate.<br>The line 0:0.0:0.25 (index:cost:probability), marks that <strong>action 3</strong> was chosen, index field is ignored and set to 0 since line order identify action index, had <strong>cost 0.0</strong>, and was selected with <strong>probability 0.25</strong>.</p><h3>🧊 Handling Featureless Users in Vowpal Wabbit</h3><p>Not all users have detailed features — especially anonymous or new users. But Vowpal Wabbit can still learn even from these sessions.</p><ul><li><strong>Reward Learning</strong>: When a user without features clicks a recommendation, Vowpal Wabbit learns that the action was effective.</li><li><strong>Relative Preference Modeling</strong>: Vowpal Wabbit adjusts future probabilities based on which actions led to positive outcomes.</li><li><strong>Exploration</strong>: Interactions from featureless users support the model’s exploration-exploitation balance.</li></ul><p><strong>It can create valid predictions based on instances where more feature data is available.</strong></p><blockquote><em>🔧 For missing features, use placeholders like </em><em>&quot;&quot; for strings or </em><em>0 for integers to keep input formats valid.</em></blockquote><h3>🧩 System Architecture Overview</h3><p>All components come together as follows:</p><ul><li><strong>Client Side</strong>: Sends /Predict and /Feedback calls upon user consent and interactions</li><li><strong>Cloud Run</strong>: Hosts the FastAPI app that performs prediction and logs meta data</li><li><strong>Vertex AI Feature Store</strong>: Provides contextual features for prediction and training</li><li><strong>Firestore</strong>: Stores recommendation metadata and feedback for training</li><li><strong>Vertex AI Pipelines</strong>: Trains and evaluates model hourly</li><li><strong>YAML in GCS</strong>: Configures available actions and UX assets</li><li><strong>Pub/Sub</strong>: Triggers feature pipeline updates</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QGb7OoilXJs6u-Qr6-9Yww.png" /><figcaption><em>System Architecture Diagram</em></figcaption></figure><h3>✨ Final Thoughts</h3><p>This project shows how contextual bandits can be applied in real-world production environments. By combining <strong>Vowpal Wabbit</strong>, <strong>Vertex AI</strong>, <strong>Cloud Run</strong>, and a real-time feedback loop, we’ve built a system that is:</p><ul><li>Scalable</li><li>Adaptive over time</li><li>Fast and responsive</li><li>Easy to configure and extend</li></ul><p>Whether you’re building a recommender system, optimizing user journeys, or exploring contextual learning, we hope this post gives you a helpful behind-the-scenes look into how to architect such a solution.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8eba4a67714" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flat-pack-tech/predicting-customer-journey-phases-in-real-time-using-contextual-bandits-on-vertex-ai-e8eba4a67714">Predicting Customer Journey Phases in Real Time Using Contextual Bandits on Vertex AI</a> was originally published in <a href="https://medium.com/flat-pack-tech">Flat Pack Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>