iT邦幫忙

2026 iThome 鐵人賽

DAY 9
0
AI Engineering

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

Day 13 — How Recommendation Systems Work: From User Preferences to Personalized Results

  • 分享至 

  • xImage
  •  

In Day 12, we introduced the idea of recommendation as a process of retrieving, ranking, and selecting relevant items. Today, we will take a closer look at how recommendation systems actually work. Instead of focusing only on similar items, a recommendation system tries to understand the relationship between users, items, and preferences. By using information such as user interests, interaction history, and item features, the system can estimate which items are most relevant to each user. In this article, we will introduce the basic ideas behind recommendation systems and explore how content-based, collaborative, and hybrid approaches create personalized results.

https://ithelp.ithome.com.tw/upload/images/20260921/20184040K4loLBC9KI.jpg

What Is a Recommendation System?

A recommendation system is an AI/ML algorithm that helps users discover items relevant to them. The core problem is: Given a user (and possibly a query) plus a large pool of items, which items should be shown to the user first? In other words, we want to produce a personalised Top‑N ranking of items for each user. This is different from, say, a search engine: rather than retrieving documents for a question, a recommender predicts what a specific user will like. It relies on data such as past purchases, clicks, ratings, search history, item attributes, demographics, etc., to gauge user interests. By analysing this data, recommender systems “understand” user preferences and item characteristics to make useful suggestions. In practice, a simple workflow is:

User Preferences / History
      ↓
Candidate Items (filtered or similar)
      ↓
Scoring / Ranking
      ↓
Top‑N Recommendations

Main Approaches:

  1. Content-Based Filtering:
    Recommend items similar to those a user has liked in the past, based on item attributes or features. If a user has watched or clicked items with certain keywords/tags or text content, the system finds other items that share those attributes. For example, if you liked the movie "Sleepless in Seattle" and "You've Got Mail", a content-based recommender would look at the genres, actors, or textual descriptions of those movies and then suggest another movie with similar features (e.g. also a romantic comedy with the same cast).

  2. Collaborative Filtering (CF)
    Recommend based on the behavior of similar users. The classic idea is: “users who agreed in the past will agree again.” There are two main subtypes:

    -User-based CF: Find users similar to the target user (e.g. who liked many of the same items), and recommend items those similar users liked.

    Item-based CF: Find items similar to ones the user likes (based on co-occurrence in users’ histories), and recommend those.
    Both rely only on the user–item interaction matrix, not on item content. For example, if User A and User B have both watched and rated X and Y highly, and User B also watched Z, then recommend Z to User A.

  3. Hybrid Models. Combine multiple signals to improve recommendations. For example, a hybrid system might use content-based scores, collaborative scores, item popularity, and contextual filters together. Netflix, Amazon, and other modern systems often blend content and collaborative signals. A hybrid might use a two-stage pipeline: first retrieve candidates by item-content or popularity, then rerank them with collaborative scores or an ML model. This can alleviate weaknesses of each approach: content helps cold-start items, CF brings community wisdom, etc. (There are many hybrid flavours; e.g. mixing explicit features with learned embeddings from CF models.)

Modern recommenders often use a multi-stage retrieve-then-rank pipeline to handle large item corpora (millions of items):

  1. Embedding Encoding: Convert the user profile (e.g. interests or interaction history) and each item into vector embeddings. User embeddings might be computed by averaging or an LLM encoding of the user’s interests, while item embeddings come from item text/descriptions or learned factors.

  2. Candidate Retrieval (FAISS): Use an approximate nearest-neighbor search (like FAISS) to quickly find the top K items whose embeddings are closest to the user embedding. This step filters billions of items down to a manageable set (e.g. hundreds of candidates) with high recall.

  3. Reranking: Take the candidates and use a more expensive model (e.g. a fine-tuned LLM or deep neural network) to score and rank them with more context (detailed user history, item attributes, etc.). For instance, we might prompt an LLM with the user’s profile and each candidate item to predict a relevance score. This step refines the ranking by leveraging rich signals.

A simple code sketch (Python) for the retrieval part might be:

    from sentence_transformers import SentenceTransformer
    import faiss
    
    # Example items and user interests
    items = [
        {"id":1, "description": "Job: AI Engineer developing LLM applications."},
        {"id":2, "description": "Job: Data Scientist for machine learning projects."},
        {"id":3, "description": "Job: Frontend Developer building web UI."}
    ]
    
    user_profile = "interested in machine learning and AI engineering"
    # Encode items and user into vectors
    model = SentenceTransformer('all-MiniLM-L6-v2')
    item_vecs = model.encode([item["description"] for item in items])
    user_vec = model.encode([user_profile])
    
    # Build FAISS index (using inner product/cosine)
    dim = item_vecs.shape[1]
    index = faiss.IndexFlatIP(dim)
    faiss.normalize_L2(item_vecs)
    faiss.normalize_L2(user_vec)
    index.add(item_vecs)
    
    # Retrieve top-2 candidates
    D, I = index.search(user_vec, k=2)
    print("Top candidate item IDs:", I)

Evaluation Metrics:

Precision@K: The fraction of the top-K recommended items that are actually relevant to the user. If a user would consider 10 specific items relevant, and among the top-10 recommendations our system shows 6 of them, then precision@10 = 0.6.

Recall@K: The fraction of relevant items that are included in the top-K recommendations. If there are 100 items the user likes in total and 30 are in the top-50 list, recall@50 = 0.30.

F1@K: The harmonic mean of precision@K and recall@K, useful if you want to balance both.

** Practical Considerations**
In building recommenders, several real-world challenges arise:

Cold Start. New users or items with no history are hard to recommend. Without past interactions, collaborative methods can’t work. Common solutions: use content-based methods (attributes or ask the user for preferences), use popularity-based fallbacks (e.g. “most popular items”), or hybrid strategies. For example, one might show trending items to new users until enough data accumulates. (The “cold start problem” refers to this exact issue.)

Finally, it’s useful to distinguish candidate retrieval from ranking stages. In candidate retrieval, the goal is high recall (get all potentially relevant items, say 100–1000 of them) with minimal latency. In ranking, the goal is precision at the top (order those candidates optimally). A brief comparison:

https://ithelp.ithome.com.tw/upload/images/20260921/20184040KX31j62Wkf.jpg

Reference:

  1. NVIDIA Blog — “What’s a Recommender System?”
  2. Google for Developers — “Recommendation systems overview”
  3. NVIDIA Technical Blog — “How to Build a Winning Recommendation System, Part 1”

上一篇
Day 12: Retrieve, Rerank, Recommend with LangGraph
下一篇
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) }}
直播中

尚未有邦友留言

立即登入留言