How jatin-12-2002/e-commerce_chatbot works
1. Overall shape
- This repo is a Flask-based chatbot application wrapped around a RAG pipeline. The browser talks to Flask, Flask orchestrates retrieval plus LLM generation, and the answer is rendered back into a chat UI.
2. User-facing layer
- templates/chat.html defines the single-page chat experience.
- static/script.js handles client-side interaction and likely polling for task completion.
- static/style.css provides the presentation layer.
- app.py serves this UI and exposes the backend chat endpoints.
3. Core backend entrypoint
- app.py is the main runtime boundary for the application.
- It is the likely place where Flask routes, session/chat handling, and async task submission are wired together.
- Based on the README, it also likely integrates the background worker flow used to avoid long LLM response timeouts.
4. RAG domain package
- The ecommbot/ package contains the chatbot’s actual retrieval-generation logic.
- model.py centralizes model and embedding setup.
- retrieval_generation.py likely builds the retrieval chain and answer generation flow.
- data_converter.py and ingest.py handle turning raw dataset rows into retrievable documents and loading them into the vector store.
5. Data ingestion path
- The source dataset is data/flipkart_product_review.csv.
- Reviews, ratings, summaries, and product titles are converted into document-like records with metadata.
- Those documents are then ingested into the vector database for semantic search.
6. Vector retrieval layer
- The README identifies AstraDB as the vector store.
- Embeddings come from sentence-transformers/all-mpnet-base-v2.
- The retrieval subsystem uses semantic similarity to pull relevant product reviews before generation.
7. LLM generation layer
- The README says the generator model is LLaMA 3.1 8B via Ollama.
- This is the synthesis step after retrieval: retrieved review context is passed to the model to produce the final response.
- The architecture is therefore not just a raw chatbot; it is a retrieval-augmented answerer grounded in product reviews.
8. Conversation state
- The project uses a history-aware RAG approach.
- Chat history is part of the request context so follow-up questions can reference prior turns.
- This makes the boundary between stateless web requests and stateful conversation management important in the diagram.
9. Asynchronous execution path
- The README describes Redis + Celery for long-running inference.
- The architecture is: browser submits a query, Flask enqueues work, a Celery worker performs retrieval + LLM inference, and the browser polls for the result.
- This is a key runtime boundary because it decouples UI responsiveness from model latency.
10. External services
- AstraDB stores and serves vector embeddings.
- Ollama hosts the local LLaMA runtime.
- Redis acts as the broker for background tasks.
- These are the main non-local dependencies that materially shape the system diagram.
11. Build and packaging
- setup.py, requirements.txt, and ecommbot/__init__.py indicate a Python package layout rather than a monolithic script.
- notebook/research.ipynb is exploratory and supports development, but it is not part of the production request flow.
12. Deployment boundary
- The README describes running the app with Gunicorn and optionally placing Nginx in front on AWS EC2.
- In production, traffic flows from the browser to Nginx, then to Gunicorn/Flask, then to the async worker or retrieval stack.
13. End-to-end data flow
- Offline: CSV dataset → document conversion → embedding creation → AstraDB vector indexing.
- Online: user question → Flask endpoint → retrieval from AstraDB → LLaMA generation via Ollama → response returned to chat UI.
- If long-running, the online path goes through Celery/Redis before the response reaches the frontend.
14. What to draw as the main diagram boxes
- Frontend chat UI
- Flask application/API
- Celery worker + Redis broker
- RAG pipeline package (data_converter, ingest, retrieval_generation, model)
- AstraDB vector store
- Ollama LLaMA inference runtime
- CSV dataset as the offline source of truth
Main entry points: app.py Flask app · retrieval_generation.py RAG chain · ingest.py Ingest · chat.html Chat UI
Components 18
Frontend
Browser chat experience and client-side interaction.
Backend
Flask app, async task flow, and orchestration boundaries.
- Flask app · Main application entrypoint and HTTP route boundary.
app.py - Chat state · Session and history-aware conversation context.
app.py - Task queue · Background execution path for long-running inference requests.
app.py - Celery worker · Runs retrieval and generation outside the request thread.
RAG pipeline
Ingestion, retrieval, and generation components.
- Data converter · Turns CSV rows into retrievable document records.
ecommbot/data_converter.py - Ingest · Loads prepared documents into the vector store.
ecommbot/ingest.py - RAG chain · Builds retrieval and answer synthesis for chat queries.
ecommbot/retrieval_generation.py - Model setup · Centralizes embedding and model initialization.
ecommbot/model.py - Review CSV · Offline source data for product review grounding.
data/flipkart_product_review.csv
External services
Runtime and infrastructure dependencies outside the repository.
- Redis · Message broker for background task delivery.
- AstraDB · Stores embeddings and supports semantic retrieval.
- Ollama LLM · Serves the LLaMA 3.1 8B generation runtime.
- Embeddings · Semantic embedding model used for indexing and search.
- Gunicorn · Production process manager for the Flask app.
- Nginx · Optional front door for production deployment.
Connections 20
- Client JS → Flask app: chat requests · Sends user prompts and polls for completion.
- Chat UI → Client JS: loads UI · Browser page includes the interaction logic.
- Styles → Chat UI: styles · Provides presentation for the chat interface.
- Flask app → Chat state: manages · Stores and reads conversational context.
- Flask app → Task queue: enqueue · Submits long-running inference jobs when needed.
- Task queue → Redis: brokered by · Uses Redis for asynchronous job delivery.
- Redis → Celery worker: delivers jobs · Hands queued tasks to the worker process.
- Celery worker → RAG chain: runs · Executes retrieval-augmented answer generation.
- RAG chain → Model setup: uses · Consumes shared model and embedding initialization.
- RAG chain → AstraDB: retrieves from · Fetches semantically relevant review context.
- RAG chain → Ollama LLM: generates via · Calls the local LLaMA runtime for synthesis.
- Model setup → Embeddings: configures · Sets up the embedding model used for retrieval.
- Data converter → Review CSV: reads · Converts the review dataset into documents.
- Ingest → Data converter: prepares · Uses converted records for indexing.
- Ingest → AstraDB: indexes · Writes embeddings and metadata into the vector store.
- Ingest → Embeddings: embeds with · Creates vector representations during ingestion.
- Gunicorn → Flask app: serves · Runs the Flask application in production.
- Nginx → Gunicorn: proxies · Optional reverse proxy in front of the WSGI server.
- Flask app → RAG chain: invokes · Triggers the RAG pipeline for synchronous or async execution paths.
- Flask app → Celery worker: delegates · Hands off heavy work to the background worker flow.