iT邦幫忙

2026 iThome 鐵人賽

DAY 9
0
AI Engineering

從 LLM 到 AI Agent:30 天打造 vLLM × RAG × LangChain 智慧推薦系統系列 第 15

Day 15: Building a Personalized Recommendation Workflow with LangGraph

  • 分享至 

  • xImage
  •  

In Day 14, we built a content-based recommedation system using Amazon Reviews' 23, ntenceTransformer embeddings, and FAISS. Our system could retrieve products based on a user’s written preferences, but it still required the user to describe what they wanted. Today, we will take the next step by using user review and rating history to build a personalized recommendation workflow with LangGraph. Instead of starting with a manually written query, we will identify products a user previously liked, use them to build a user profile, and retrieve similar products that the user has not interacted with. By connecting these steps through LangGraph’s shared state and nodes, we will turn our Day 14 recommender into a workflow that can support more personalized recommendations.

Today’s goal: Given a user ID, generate Top-K product recommendations using the user’s interaction history, product embeddings, FAISS, and LangGraph.

In Day 15, we will replace that manually written preference with a profile derived from the user's previous reviews and ratings.

  1. Workflow:

              START
                |
                v
       Input Amazon User ID
                |
                v
       Load User History
                |
                v
        Build User Profile
                |
                v
      Generate User Embedding
                |
                v
     Retrieve Candidates (FAISS)
                |
                v
      Filter Previously Seen
                |
                v
      Top-K Recommendations
                |
                v
               END
    
  2. The LangGraph Structure

         Node	                  Responsibility
    load_user_history           Find the selected user's reviews 
    build_user_profile           Identify highly rated products
    create_user_embedding        Generate a vector representing
    retrieve_candidates           Search the FAISS product index
    filter_seen_items          Remove previously reviewed products
    

Step 1. Define the shared state

from typing import TypedDict


class RecommendationState(TypedDict):
    user_id: str
    user_history: list[dict]
    liked_products: list[dict]
    user_embedding: list[float]
    candidates: list[dict]
    recommendations: list[dict]

For Day 15, I would keep the experiment focused on generating a user embedding from review history and using LangGraph to organize the recommendation workflow. That gives readers a complete implementation while leaving conditional routing, cold-start handling, and eventually Qwen-based reranking for the following days.

To be continue......

Reference:
1.LangGraph Graph API
2.LangGraph StateGraph API
3.Amazon Reviews'23 Dataset
4.Amazon Reviews'23 Data Loading Guide
5.Sentence Transformers Documentation
6.FAISS: Metric Types and Distances


上一篇
Day 14-Building a Content-Based Recommendation System with Embeddings and FAISS
系列文
從 LLM 到 AI Agent:30 天打造 vLLM × RAG × LangChain 智慧推薦系統15
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言