How krupa-srinivasan/asiamotors-chatbot works
Purpose and Entry Points
This repository implements a Retrieval-Augmented Generation (RAG) customer-support chatbot for Asia Motors Auto Garage. The API entry point is the FastAPI application in app.py; its primary interface is POST /ask. A standalone browser client is provided in ask.html. The knowledge source is the garage PDF at data/business.pdf.
Application Service and Request Boundary
app.py owns application startup, HTTP handling, retrieval, prompt construction, model invocation, and chat persistence. /ask accepts a session_id and customer question, returning a JSON answer. The API boundary allows other clients beyond the included widget, such as messaging integrations.
Grounding: app.py, ask.html
Startup Knowledge Ingestion
On startup, the service reads the business document, extracting page text and tables with pdfplumber. Extracted content is converted into LangChain documents, then split with recursive character chunking (about 1,000 characters with 200-character overlap). This establishes the PDF as the answer-context source.
Grounding: app.py, data/business.pdf
Embedding and Retrieval Layer
Chunks are embedded remotely using Jina AI’s jina-embeddings-v3 model and indexed in a local Chroma vector store (./chroma_data at runtime). Each /ask request runs similarity search for the top three relevant chunks. Retrieval context is the factual boundary supplied to generation.
Grounding: app.py, data/business.pdf
Conversation and Generation Pipeline
For an incoming question, the service loads the latest ten messages for the supplied session from PostgreSQL, combines history with retrieved PDF context and a garage-front-desk system persona, and sends the prompt to Groq’s hosted llama-3.3-70b-versatile. It persists both the user question and generated answer in the chat_messages table, scoped by session_id.
Grounding: app.py
External Services and Runtime Dependencies
The runtime is Python 3.11 with FastAPI/Uvicorn. Required external dependencies are PostgreSQL for durable per-session history, Jina AI for embeddings, and Groq for LLM completion. Credentials and database connectivity are supplied through JINA_API_KEY, GROQ_API_KEY, and DATABASE_URL.
Grounding: app.py, requirements.txt
Deployment and Client Integration
Dockerfile packages the service using python:3.11-slim and starts Uvicorn. The vector index is local container/runtime storage, while PostgreSQL is expected to be externally provisioned. ask.html is a dependency-free widget that calls a configured deployed /ask URL; its endpoint must match the hosted API.
Grounding: Dockerfile, ask.html, app.py
Main entry points: app.py POST /ask · ask.html Browser widget · business.pdf Garage knowledge PDF · Dockerfile Docker image
Components 14
Client
- Browser widget · Posts customer questions to the deployed API.
ask.html
RAG API
- FastAPI application · Owns startup, /ask handling, retrieval, generation, and persistence.
app.py - POST /ask · Accepts session_id and customer question and returns a JSON answer.
app.py - Top-3 similarity retrieval · Selects relevant PDF chunks for each question.
app.py - Session history loader · Loads the latest ten messages for a session.
app.py - Grounded prompt builder · Combines history, retrieved context, question, and front-desk persona.
app.py
Knowledge pipeline
- Garage knowledge PDF · Business facts used as answer context.
data/business.pdf - PDF extraction and chunking · Extracts page text and tables, then creates overlapping LangChain chunks.
app.py - Chroma vector index · Runtime-local index at ./chroma_data.
External services
- Jina embeddings · Uses jina-embeddings-v3 to embed document chunks.
- Groq LLM completion · Runs llama-3.3-70b-versatile.
- PostgreSQL chat_messages · Persists user and assistant messages by session_id.
Deployment
- Docker image · Python 3.11-slim container starts Uvicorn.
Dockerfile - Python dependencies · Defines FastAPI, Uvicorn, and integration libraries.
requirements.txt
Connections 16
- Browser widget → POST /ask: POST question
- Docker image → FastAPI application: runs Uvicorn
- Python dependencies → FastAPI application: provides runtime libraries
- FastAPI application → PDF extraction and chunking: startup
- Garage knowledge PDF → PDF extraction and chunking: read and extract
- PDF extraction and chunking → Jina embeddings: chunk embeddings
- Jina embeddings → Chroma vector index: index vectors
- POST /ask → Top-3 similarity retrieval: question
- Top-3 similarity retrieval → Chroma vector index: similarity search
- POST /ask → Session history loader: session_id
- Session history loader → PostgreSQL chat_messages: load last 10
- Top-3 similarity retrieval → Grounded prompt builder: retrieved context
- Session history loader → Grounded prompt builder: conversation history
- Grounded prompt builder → Groq LLM completion: completion request
- Groq LLM completion → POST /ask: generated answer
- POST /ask → PostgreSQL chat_messages: persist question and answer