Skip to content

inbravo/rag-bot

Repository files navigation

A Python based local Retrieval-Augmented Generation (RAG) chatbot that can answer to queries questions based on the context information available

Solution components

# 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

Applicable usecases

Option I - Knoledge management - supports the scanning of the documents (pdf, doc, excel etc.).

call-flow

Option II - Salesforce data (Opportunity, Account, Lead, Contact etc.) intelligence

call-flow

LLM configuration

# 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.

Code repo setup and build

  1. Clone the repository and navigate to the project directory:
    git clone https://github.com/inbravo/rag-bot.git
    cd rag-bot
  2. Create a virtual environment:
    python -m venv venv
    source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
  3. Install the required libraries:
    pip install -r requirements.txt
  4. Insert you own Word/XLSX/PDF in /data folder. You can change this path in ENV file by changing the property 'DATA_PATH'
  5. Run once the populate_database script to index the pdf files into the vector db:
    python DocUploader.py
  6. Run the application:
    python FlaskApp.py
  7. Navigate to http://localhost:5000/ and If needed, click on ⚙️ icon to access the admin panel and adjust app parameters
  8. Perform a query and Chatbot will reply the best answer

About

A Python based RAG bot using LangChain Framework

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published