How manu9986/llm-booking-analytics works
Project type and purpose
• This is a backend-focused, data-driven “full-stack” service (no separate UI) that offers (a) hotel booking analytics via FastAPI endpoints and (b) a Retrieval-Augmented Generation (RAG) chatbot powered by OpenAI and ChromaDB.
File structure
• Top-level scripts and config:
• precompute.py (in scripts/): loads raw CSV, cleans data, computes analytics, writes to data/analytics.db and data/bookings.db.
• main.py and database.py (in app/): launch FastAPI app, define endpoints, wire up SQLite and ChromaDB clients.
• analytics.py and rag.py (in app/): modules encapsulating analytics queries and RAG logic.
• Data stores under data/:
• analytics.db & bookings.db (SQLite analytic tables),
• chromadb/ (vector DB directory),
• raw CSV files.
• Dependencies: FastAPI, ChromaDB, OpenAI, SQLite.
Extract architecture clues from the README
• Two main usage flows:
a. Precompute pipeline: raw CSV → cleaning → analytic tables & ChromaDB embeddings.
b. API server: HTTP REST endpoints → analytics queries & RAG QA calls → JSON responses.
• External service: OpenAI API for GPT-4.
Main components
a. Data Ingestion & Precompute (Offline Batch)
• Raw CSVs (hotel_bookings.csv)
• Precompute script (scripts/precompute.py)
• SQLite analytic DB (analytics.db, bookings.db)
• ChromaDB vector store (data/chromadb/...)
b. API Server (Online / Real-time)
• FastAPI Application (app/main.py)
• Analytics Module (app/analytics.py) → reads from analytics.db
• RAG Module (app/rag.py) → queries ChromaDB + calls OpenAI
c. External Services
• OpenAI GPT-4 API
d. Clients
• API consumer (e.g., web front-end or CLI)
Relationships & data flows
1. CSV files → precompute.py → writes to SQLite (analytics.db)
2. main.py initialization or separate script → processes embeddings → writes to ChromaDB
1. Client HTTP request → FastAPI router
2. If /api/analytics/* → analytics.py → SQLite query → JSON response
3. If /ask → rag.py → vector search in ChromaDB → top-k docs → OpenAI API call → answer → JSON response
Architectural patterns & design principles
• Separation of Concerns:
• Batch processing (data prep) vs. real-time serving (FastAPI).
• Analytics logic vs. RAG logic in separate modules.
• RAG Pattern: integrating vector DB + LLM for QA.
• Precompute for performance: denormalized analytics tables.
Essential elements to capture
• Clear boundary between offline and online.
• Component names matching code modules/files: precompute.py, analytics.py, rag.py, database.py.
• All data stores (analytics.db, bookings.db, chromadb directory).
• External dependency: OpenAI API.