iT邦幫忙

2026 iThome 鐵人賽

DAY 9
0
AI Engineering

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

Day 14-Building a Content-Based Recommendation System with Embeddings and FAISS

  • 分享至 

  • xImage
  •  

In Day 13, we introduced the basic ideas behind recommendation systems, including users, items, preferences, candidate generation, and ranking. Today, we will turn those ideas into a working system by building a simple content-based recommender. Instead of using behavior from many users, we will represent both user interests and item descriptions as embeddings, then use FAISS to find the items that are most semantically similar to the user profile. Content-based recommendation works by matching item characteristics with a user’s known interests, while FAISS gives us an efficient way to search over dense vectors and return the nearest candidates.

    User Interests
         ↓
    Create User Profile
         ↓
    Embedding Model
         ↓
    User Vector
         ↓
    FAISS Similarity Search
         ↓
    Top-K Similar Items
         ↓
    Recommendations
    
    
    

Amazon Reviews’23 Dataset:

In this article, we will use the Amazon Reviews’23 dataset released by the McAuley Lab. The dataset contains user reviews, ratings, item metadata, and user–item interactions, making it suitable for both retrieval and recommendation experiments. It includes approximately 571 million reviews, 54 million users, and 48 million items across 33 product domains. Since the full dataset is very large, we will focus on a single product category and use its metadata to build a simple content-based recommendation system with embeddings and FAISS

Step 1 — Install packages:

pip install pandas pyarrow sentence-transformers faiss-cpu

Step 2 — Load the metadata:

Step 2 — Load the metadata

Step 3 — Generate product embeddings

from sentence_transformers import SentenceTransformer

model = SentenceTransformer(
    "sentence-transformers/all-MiniLM-L6-v2"
)

product_embeddings = model.encode(
    df["product_text"].tolist(),
    normalize_embeddings=True,
    show_progress_bar=True
)

Summary

Today, we built our first content-based recommendation system using the Amazon Reviews’23 dataset. We used product metadata such as titles, descriptions, features, and categories to create text representations for each item. These texts were converted into embeddings with a SentenceTransformer model and stored in a FAISS index for similarity search.

The most important idea is that a recommendation system can reuse many of the same techniques we learned from RAG. In RAG, vector search retrieves relevant documents for answering a question. In recommendation, vector search retrieves items that are similar to a user’s interests.

However, this system is still only content-based. It does not yet learn from user behavior such as ratings, reviews, or previous purchases. In the next step, we can use the review and interaction data in Amazon Reviews’23 to build a more personalized user profile and move toward a stronger recommendation system.

Referece:

  1. Amazon-Reviews-2023

update later .........


上一篇
Day 13 — How Recommendation Systems Work: From User Preferences to Personalized Results
下一篇
Day 15: Building a Personalized Recommendation Workflow with LangGraph
系列文
從 LLM 到 AI Agent:30 天打造 vLLM × RAG × LangChain 智慧推薦系統15
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言