Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧠 MD ChatBot: Advanced RAG System

A highly-extensible, production-ready Retrieval-Augmented Generation (RAG) API & Chatbot for your Markdown knowledge base.

Python Version FastAPI LangChain ChromaDB Pluggable LLM


🌟 Overview

MD ChatBot is a modern, full-stack chatbot application designed to instantly retrieve and synthesize information from your local Markdown (.md) files.

Built with enterprise-grade architecture, it seamlessly blends a lightweight frontend interface with a robust, highly-optimized FastAPI backend. Under the hood, it leverages LangChain and ChromaDB to execute advanced RAG (Retrieval-Augmented Generation) patterns—ensuring accurate, context-aware, and hallucination-free responses based strictly on your uploaded data.


✨ Key Features

🚀 High-Performance API

  • Built on FastAPI for blazing-fast response times, automatic Swagger documentation (/docs), and native async support.
  • Fully configured CORS middleware for effortless frontend integration.

🧠 Advanced RAG Pipeline

  • Pluggable LLM Providers: Effortlessly switch between OpenAI (GPT-4o-mini), Google Gemini (2.5 Flash), or entirely Local Open-Source Models (via HuggingFace).
  • Intelligent Chunking: Uses RecursiveCharacterTextSplitter to optimally segment Markdown files while preserving context.
  • MMR Search: Employs Maximum Marginal Relevance (MMR) retrieval to ensure diverse and relevant document fetching.
  • LLM-Based Reranking: Dynamically reranks retrieved context using the LLM to surface the most critical information to the top.
  • Context Compression: Eliminates duplicate context to maximize prompt efficiency and reduce token costs.

📂 Seamless Document Management

  • Instant Ingestion: Upload .md files directly via the UI or API endpoint (/upload) and trigger real-time vectorization.
  • Smart Idempotency: Hashes document chunks to prevent duplicate vector store entries, ensuring a clean and efficient Chroma database.

🏗️ Architecture Stack

Layer Technology Description
Frontend HTML / Vanilla CSS / JS Lightweight, static frontend served directly by FastAPI.
Backend API FastAPI Async Python framework routing requests and managing file uploads.
Orchestration LangChain Manages prompt building, document loaders, splitting, and LLM chains.
Vector Database ChromaDB Local, persistent vector store for fast embedding retrieval.
Embeddings/LLM OpenAI / Gemini / HF Flexible integration for state-of-the-art generative AI models.

⚙️ Quick Start Guide

1. Prerequisites

  • Python 3.10 or higher
  • An API key for your chosen provider (OpenAI or Google Gemini)

2. Installation

Clone the repository and install the required dependencies:

git clone https://github.com/your-org/md-chatbot.git
cd md-chatbot
pip install -r requirements.txt

3. Configuration

Create a .env file in the root directory and add your API keys:

# Example .env file
OPENAI_API_KEY="your-openai-api-key"
GEMINI_API_KEY="your-google-gemini-api-key"

Configure your provider preference directly in rag.py:

# rag.py configuration block
USE_PROVIDER = "gemini" # Options: "openai", "gemini", "local"

4. Running the Application

Start the FastAPI server using Uvicorn:

uvicorn main:app --reload

The application will now be available at:

  • Web UI: http://localhost:8000/
  • API Documentation (Swagger): http://localhost:8000/docs

🛠️ API Endpoints

Method Endpoint Description
GET / Serves the interactive Web UI.
POST /upload Accepts a .md file, saves it to the data/ directory, and triggers the LangChain ingestion pipeline.
POST /ask Accepts a JSON payload { "query": "string" }, runs the RAG pipeline, and returns the LLM-generated answer.

💡 How It Works Under the Hood

  1. Ingestion (/upload): When a user uploads a Markdown file, rag.py loads it using DirectoryLoader, splits it into 800-character chunks (with 150-character overlap), generates an MD5 hash for idempotency, embeds the text, and stores it locally in ChromaDB.
  2. Retrieval (/ask): Upon receiving a query, the system vectorizes the question, performs an MMR search in ChromaDB to fetch the top 12 chunks, and then uses a custom LLM prompt to rerank those chunks down to the top 5 most relevant pieces of context.
  3. Generation: The compressed, highly-relevant context is injected into a strict prompt template instructing the LLM to answer only based on the provided text, mitigating hallucination risks.

Built with ❤️ for modern data-driven teams.

About

MD ChatBot is a modern, full-stack chatbot application designed to instantly retrieve and synthesize information from your local Markdown (.md) files.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages