How kimcheolhui/rag works
Project Type and Purpose
• This is a full-stack chatbot application built for querying movie information.
• It employs a RAG architecture: it processes user queries by computing embeddings, performs vector-based search in Cosmos DB to retrieve related movie data, and then generates a natural language answer via OpenAI’s GPT model.
• The application has a UI component (with a Streamlit-based interface as the primary option) and an alternative Gradio interface (though marked as non-used in the README).
File Structure
• Top-Level Files: The README, main_sl.py (Streamlit UI), requirements.txt, and data files (both JSON and a ZIP with MovieLens information).
• The src Directory Contains Key Modules:
• db_setup.py: Handles Cosmos DB container setup and configuration.
• insert_data.py: Inserts the movie dataset into Cosmos DB.
• embedding.py: Interfaces with the OpenAI Embedding API to convert text into vectors.
• search.py: Executes vector-based similarity search and cache retrieval using Cosmos DB.
• completion.py: Uses OpenAI’s GPT model to generate natural language responses; also caches generated responses.
• main.py: Contains a Gradio-based UI (provided as an alternate front-end).
• There’s also a configuration file (rag_env.env) for storing essential environment variables such as API keys and endpoints.
Architectural Components
• Frontend Components:
• Streamlit UI: main_sl.py (primary interface for users).
• (Alternate) Gradio UI: src/main.py.
• Backend Components:
• API Clients/Modules:
• Embedding Module: Converts user queries into vector representations.
• Search Module: Uses the resulting vectors to perform similarity search in Cosmos DB.
• Completion Module: Generates natural language responses based on search results via GPT.
• Data Handling:
• Data Insertion Module: Streamlines the process of inserting and managing movie data in Cosmos DB.
• Database:
• Cosmos DB: Serves as the vector store and caching mechanism to store both movie embeddings and possibly response caches.
• External Services:
• Azure OpenAI: Used for both embeddings (text-embedding-3-small) and completions (gpt-35-turbo).
• Azure Cosmos DB: Provides vector search capabilities and caching.