How polarbear333/rag-llm-based-recommender works
Project Type & Key Purpose
• This is a full-stack AI-powered e-commerce recommendation system that leverages Retrieval Augmented Generation (RAG), Large Language Models (LLMs), and sentiment analysis.
• It’s built to enhance the shopping experience via semantic search, product recommendation, and contextual content generation.
• It integrates a FastAPI backend with a React/Next.js frontend, uses Google Cloud Platform (GCP) services (BigQuery, Vertex AI, Cloud Storage) and manages infrastructure using Terraform.
Analyzing the File Structure
• The top-level directories clearly separate the backend, frontend, and infra:
• Backend: Contains the FastAPI application, API endpoints (e.g., search and sentiment endpoints), core modules (like search, database connectors, LLM integration via Vertex AI), and tests.
• Frontend: Contains a React/Next.js application with components (UI elements, chat interfaces, product cards) and utilities for API communication and theming.
• Infra: Holds Terraform configuration files and supporting infrastructure scripts to deploy the system on GCP.
• Additional directories (bigQuery, etl_full.py) denote SQL scripts for table creation, vector indexing, and data processing scripts (ETL using PySpark).
• There are also supplementary files (e.g., README, package.json, Dockerfiles) that indicate deployment and dependency management practices.
Key Components
a. Data Processing Pipeline:
• Data ingestion from the Amazon Reviews dataset.
• ETL processes using PySpark (etl_full.py) to clean data.
• Generation of vector embeddings via Vertex AI.
• Loading and indexing data into BigQuery (including SQL scripts for table creation and vector indexing).
b. Backend API Layer:
• FastAPI service (in the “backend/app/main.py”).
• API endpoints for product search, sentiment analysis (search_endpoints.py & sentiment_endpoints.py).
• Core processing modules handling vector search, RAG pipeline (modules in “backend/app/core”) and database operations (bigquery integration in “backend/app/db”).
• Integration with third-party services such as Vertex AI and ScaNN for vector search.
c. Frontend Web Interface:
• React/Next.js application responsible for displaying the chatbot interface, product recommendations, and dynamic visuals.
• Components for chat (ChatbotInterface, FullPageChat, MaximizedChatbox) and product display (ProductCard, ProductGrid).
• Utility functions used for API calls and theming.
d. Infrastructure & Deployment:
• Terraform scripts (in the infra folder) that set up GCP resources including Cloud Run, BigQuery, Vertex AI, and Cloud Storage.
• Dockerfiles in both the backend and infra directories to containerize services.
• CI/CD configuration in the .github/workflows directory for deployment automation.
Relationships & Data Flow
• Data flow from the ETL process to BigQuery (data ingestion and vector embedding generation).
• Communication between the FastAPI backend and BigQuery, Vertex AI for query processing and recommendation generation.
• API interaction between the Next.js frontend and the backend service.
• Infrastructure provisioning from Terraform to all deployed components on GCP.
• Use annotations to represent synchronous API calls, asynchronous processing, and streaming data (if applicable).
Architectural Patterns & Design Principles
• Microservices architecture:
• Separate services (backend API, frontend client, data pipeline, infrastructure provisioning) that can scale independently.
• Use of RAG (Retrieval Augmented Generation) and vector search:
• Modular divisions (e.g., separating core services like search, sentiment analysis, and helper utilities).
Technology Stack & Integration Points
• Backend Technologies: FastAPI, LangChain, Vertex AI, BigQuery, ScaNN, PySpark.
• Frontend Technologies: React, Next.js, Tailwind CSS, Axios.
• Infrastructure Tools: Terraform, Docker.
• Cloud Provider: Google Cloud Platform services (BigQuery, Vertex AI, Cloud Storage, Cloud Run).
• Dependencies (such as the integration between Vertex AI and LangChain for RAG).