How sanjeevsranjan/customchatbot works
Purpose and entry points
This is a Python medical-document RAG chatbot. It indexes data/Medical_book.pdf into Pinecone, then serves a Flask chat UI that answers questions with an OpenAI GPT model using retrieved medical-book context.
Primary commands:
• Build the vector index: store_index.py
• Run the web server: app.py
• Containerize/run the service: Dockerfile
Document ingestion and indexing
store_index.py is the offline ingestion entry point. It loads the medical PDF, splits its text into retrieval-sized chunks, creates embeddings, and persists them to Pinecone.
Core paths:
• store_index.py
• src/helper.py
• data/Medical_book.pdf
This stage establishes the external vector-store boundary: source document content is transformed into embeddings and uploaded, rather than stored locally by the application.
Shared RAG utilities
src/helper.py centralizes reusable document-processing and vector-store setup logic used by the indexing and/or serving paths. It is the likely boundary for PDF loading, chunking, embedding creation, and Pinecone connection configuration.
Core paths:
• src/helper.py
• src/__init__.py
• requirements.txt
The runtime depends on LangChain-style orchestration, OpenAI embeddings/LLM access, and Pinecone retrieval. Credentials are supplied through root .env variables, not hardcoded.
Prompt and answer generation
src/prompt.py defines the chatbot’s prompt contract. The serving path combines a user question with retrieved Pinecone context and sends that assembled prompt to the GPT provider.
Core paths:
• src/prompt.py
• app.py
• src/helper.py
The important control boundary is retrieval versus generation: Pinecone provides grounding context; OpenAI generates the final natural-language response.
Flask application and chat delivery
app.py is the online application entry point. It initializes Flask, connects the RAG chain/components, renders the chat page, accepts user input, and returns generated answers.
Core paths:
• app.py
• templates/chat.html
• Static/style.css
There are two chat-template locations, templates/chat.html and data/templates/chat.html; Flask convention favors the root templates/ copy, while the data/ copy may be legacy or duplicated content.
Runtime, infrastructure, and deployment
The application targets Python 3.10 and is containerized with Dockerfile. GitHub Actions supports CI/CD, building an image, pushing it to AWS ECR, and deploying/running it on an EC2 self-hosted runner.
Core paths:
• Dockerfile
• .github/workflows/cicd.yaml
• requirements.txt
Material external services are OpenAI, Pinecone, AWS ECR, and AWS EC2. Deployment requires AWS credentials plus PINECONE_API_KEY and OPENAI_API_KEY as GitHub secrets/environment variables.
Main entry points: app.py Flask app · helper.py RAG utilities · store_index.py Index builder · cicd.yaml GitHub Actions
Components 14
Offline Indexing
Builds the searchable medical-book index.
- Medical book PDF
data/Medical_book.pdf - Index builder
store_index.py
Chat Service
Online Flask RAG request path.
- Flask app · Handles chat requests and runs the RAG flow.
app.py - Chat page
templates/chat.html - Chat styles
Static/style.css - Prompt contract
src/prompt.py
CI/CD and Hosting
Builds and deploys the container.
- Container build · Packages the Python 3.10 chat service.
Dockerfile - GitHub Actions · Builds, publishes, and deploys the image.
.github/workflows/cicd.yaml - AWS ECR
- AWS EC2 runner · Self-hosted runner that runs the deployed container.
Other components
- RAG utilities · Loads, chunks, embeds documents, and configures Pinecone.
src/helper.py - Pinecone · Stores medical-book embeddings and serves retrieval context.
- OpenAI · Creates embeddings and generates grounded answers.
- Python dependencies · Includes Flask, LangChain-style RAG, OpenAI, and Pinecone libraries.
requirements.txt
Connections 17
- Medical book PDF → Index builder: loaded by
- Index builder → RAG utilities: uses
- RAG utilities → OpenAI: creates embeddings
- RAG utilities → Pinecone: uploads vectors
- Flask app → Chat page: renders
- Chat page → Chat styles: uses
- Flask app → RAG utilities: initializes retrieval
- Flask app → Pinecone: retrieves context
- Flask app → Prompt contract: assembles prompt
- Flask app → OpenAI: generates answer
- Python dependencies → Index builder: dependencies
- Python dependencies → Flask app: dependencies
- Container build → Flask app: packages
- GitHub Actions → Container build: builds image
- GitHub Actions → AWS ECR: pushes image
- AWS ECR → AWS EC2 runner: deploys image
- AWS EC2 runner → Flask app: runs container