A Python based local Retrieval-Augmented Generation (RAG) chatbot that can answer to queries questions based on the context information available
| # | Code/File | Purpose | Design Principle | Tech Stack |
|---|---|---|---|---|
| 1 | FlaskApp | Server side to manage user request from web browser | WSGI | Flask |
| 2 | AppConfig and Enviornment file | Application module to load configuration from environment variables, initializes the retriever and LLM model and provides methods to update the configuration dynamically. | 12 Factor Config | DotEnv |
| 3 | RagRetriever | RAGRetriever class to handle retrieval-augmented generation. It interacts with a vector database to fetch relevant documents based on query similarity. It uses an embedding model to compute text embeddings for similarity comparison. It extracts relevant context and source information from the retrieved documents. | 2 Step RAG | Langchain Chroma Vectorstore |
| 4 | EmbeddingFactory | Embedding Factory class to select and return the appropriate embedding function based on the specified model name (Ollama, OpenAI etc) | Vectorization & Similarity Scoring | Langchain Embeddings |
| 5 | DocUploader | Manage the database population with embeddings | Vector Database | Langchain Chroma |
| 6 | LLMFactory | Factory class to create LLM instances based on model type e.g., 'ollama', 'gpt', 'claude') | Factory Pattern | Langchain Models |
| # | Option | Description |
|---|---|---|
| 1 | Local Setup with Ollama | Download and install Ollama on your PC: Visit Ollama's official website to download and install Ollama. Ensure you have sufficient hardware resources to run the local language model. Pull a LMM of your choice: sh ollama pull <model_name> # e.g. ollama pull llama3:8b |
| 2 | Use OpenAI API for GPT Models | Set up OpenAI API: you can sign up and get your API key from OpenAI's website. |
| 3 | Use Anthropic API for Claude Models | Set up Anthropic API: you can sign up and get your API key from Anthropic's website. |
- Clone the repository and navigate to the project directory:
git clone https://github.com/inbravo/rag-bot.git cd rag-bot - Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
- Install the required libraries:
pip install -r requirements.txt
- Insert you own Word/XLSX/PDF in /data folder. You can change this path in ENV file by changing the property 'DATA_PATH'
- Run once the populate_database script to index the pdf files into the vector db:
python DocUploader.py
- Run the application:
python FlaskApp.py
- Navigate to
http://localhost:5000/and If needed, click on ⚙️ icon to access the admin panel and adjust app parameters - Perform a query and Chatbot will reply the best answer

