This is a full-stack mobile application that leverages LLMs and vector embeddings to provide a semantic search and conversational recommendation engine for movies.
movie_recommendation_llm.mp4
The project consists of a React Native (Expo) frontend and a Python (FastAPI) backend. It offers two primary ways for users to discover movies:
- Semantic Search: A traditional search screen where users can type in a description, a theme, or a vague idea of a movie, and the system will find the most relevant matches based on semantic meaning, not just keywords.
- Conversational Chat: A chat interface where users can interact with an AI assistant. Users can ask for recommendations, refine their search, and get movie suggestions in a natural, conversational flow.
| Area | Technology |
|---|---|
| Backend | Python, FastAPI, Sentence-Transformers (for embeddings), ChromaDB/FAISS (for vector search) |
| Frontend | React Native, Expo, TypeScript, Expo Router |
| Data | The Movie Database (TMDB) API |
| AI/LLM | OpenAI API (or similar, for the chat functionality) |
- Node.js and npm/yarn
- Python 3.8+ and pip
- A TMDB API Key
- An OpenAI API Key (or another LLM provider)
- Expo Go app on your mobile device for testing.
-
Navigate to the backend directory:
cd backend -
Install Python dependencies:
pip install -r requirements.txt
-
Set up environment variables: Create a
.envfile in thebackenddirectory and add your API keys:TMDB_API_KEY="your_tmdb_api_key_here" OPENAI_API_KEY="your_openai_api_key_here"
-
Fetch and Process Data: Run the script to download movie data from TMDB. This will create a
movies_with_genres.csvfile in thedata/directory.python src/database/fetch_data_from_tmdb.py
(Note: A second script to generate and store embeddings in a vector database would also be run here, e.g.,
python src/database/generate_embeddings.py) -
Run the backend server:
uvicorn src.main:app --host 0.0.0.0 --port 8000 --reload
The server will be available at
http://<YOUR_LOCAL_IP>:8000.
-
Navigate to the frontend directory:
cd frontend -
Install Node.js dependencies:
npm install # or yarn install -
Configure the API URL: Open the following files and update the
API_BASE_URLconstant to point to your backend server's local IP address:frontend/app/(tabs)/index.tsxfrontend/app/(tabs)/chat.tsx
// Replace <YOUR_MACHINE_LOCAL_IP> with your actual IP const API_BASE_URL = "http://<YOUR_MACHINE_LOCAL_IP>:8000/api";
-
Start the development server:
npx expo start
-
Scan the QR code with the Expo Go app on your iOS or Android device to run the application. Ensure your device is on the same Wi-Fi network as your computer.
- The
fetch_data_from_tmdb.pyscript queries the TMDB API for a list of popular movies. - It saves relevant data (title, overview, genres, etc.) into a CSV file.
- A separate process (not shown in context) would then read this CSV, use a model like
Sentence-Transformersto convert the movie overviews into numerical vector embeddings, and store these embeddings in a vector database like ChromaDB.
- The React Native app sends the user's query text to the FastAPI backend.
- The backend converts the incoming query into an embedding using the same sentence-transformer model.
- It performs a similarity search (e.g., cosine similarity) in the vector database to find the movie embeddings that are "closest" to the query embedding.
- The top N results are returned to the frontend and displayed in a list.
- The user sends a message in the chat UI.
- The frontend sends the entire conversation history to the
/api/chat_searchendpoint. - The backend forwards this conversation to an LLM (like GPT-4). The LLM is prompted to act as a helpful movie assistant and is given access to a "tool" which is our semantic search function.
- If the user's request requires finding movies, the LLM calls the search tool with an appropriate query.
- The backend executes the search, gets the movie results, and passes them back to the LLM.
- The LLM formats a natural language response, which might include a sentence like "Here are some movies you might like," and includes the structured movie data.
- The backend sends this complete response to the frontend, which then renders the text and the movie recommendation carousel.