A high-performance, developer-first Retrieval-Augmented Generation (RAG) server, database management dashboard, and embeddable AI widget generator. This repository provides a fully modular, framework-free RAG engine designed to ingest private document data, test it live, and deploy a context-grounded AI assistant to any external website via a simple JavaScript snippet.
Unlike monolithic setups, the RAG core is isolated as a self-contained, importable Python class (RAGPipeline) that you can drop directly into external projects, APIs, or personal websites.
rag-project/
├── backend/
│ ├── main.py # FastAPI ASGI backend: exposes management, chat & widget APIs
│ ├── config.py # Configuration hub: manages mutable runtime settings
│ └── services/
│ ├── rag.py # 📦 Reusable standalone RAG orchestrator class (RAGPipeline)
│ ├── pdf_loader.py # Text extractor
│ ├── chunker.py # Text segmenter (sliding window chunking)
│ ├── embeddings.py # Local vector generation (Sentence-Transformers)
│ ├── vectordb.py # Persistent storage (ChromaDB)
│ ├── retriever.py # Vector semantic matcher
│ └── llm.py # LIVE model router (Ollama / Groq API)
├── frontend/ # Administration Console & Interface
│ ├── index.html # Data, Playground, Widget Customizer, and Settings panels
│ ├── style.css # Premium slate-dark SaaS design sheets
│ └── script.js # Live stats binder, widget builder script, and chat inspector
├── requirements.txt # Dependency configurations
└── .env.example # Runtime environment variables template
Clone the repository and install the dependencies in a virtual environment:
git clone https://github.com/Sahil002620Q/RAG-pipeline.git
cd RAG-pipeline
# Initialize virtual environment
python3 -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
Create your .env file:
cp .env.example .env
Default parameters are configured for local operation.
Start the FastAPI server:
uvicorn main:app --host 127.0.0.1 --port 8000 --reload --app-dir backend
Access the RAG Control Console at http://localhost:8000.
The Data Management panel in the administration dashboard allows you to build and clean your knowledge base index:
- Upload Documents: Drag and drop any
.pdffile. The ingestion engine extracts, chunks, generates embeddings, and indexes them in ChromaDB. - Knowledge Base Manager: Review indexed files in the database table and selectively remove documents. Deleting a document instantly wipes all its vector chunks and deletes the file from disk.
- Purge Database: Flush the entire ChromaDB index and physical uploads to start clean.
Easily deploy your RAG-powered chatbot onto any external website (e.g., business site, portfolio, documentation page) to handle FAQs, inquiries, and data queries automatically.
- Open your RAG Control Console dashboard and navigate to the Widget Generator tab.
- Customize Appearance: Pick your preferred color style and theme configurations for the floating chat bubble sitting at the bottom right corner of your page.
- Get the Snippet: Once confirmed, the system generates a clean, plug-and-play JavaScript snippet.
- Embed: Copy and paste the script tag right before the closing
</body>tag of your target website, following the on-screen instructions:
<!-- Paste this snippet into your target website HTML -->
<script
src="http://localhost:8000/widget.js"
data-color="#4f46e5"
data-position="bottom-right">
</script>- Live Testing: The exact behavior, context-grounding, and responses tested inside your RAG pipeline interface will immediately reflect on the external site where the script is embedded. This makes it effortless to integrate an AI assistant for Q&A, repetitive questions, inquiries, and data retrieval on any website.
FastAPI exposes the pipeline as a JSON endpoint. You can query the bot from any external frontend or custom application:
async function askRagBot(question) {
const response = await fetch('http://localhost:8000/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: question })
});
const data = await response.json();
console.log("Answer:", data.reply);
console.log("Sources Used:", data.context);
}The entire engine is encapsulated inside the RAGPipeline class in backend/services/rag.py. To use it in a separate Python project:
- Copy the
backend/services/directory into your project. - Initialize and call the pipeline directly:
from services.rag import RAGPipeline
# Initialize the pipeline
rag = RAGPipeline()
# Ingest document data
rag.ingest_document("/path/to/private_specs.pdf", "specs.pdf")
# Run semantic queries
response = rag.query("What is the hardware requirement?")
print("AI Response:", response["answer"])
# Inspect matched chunks
for chunk in response["context"]:
print(f"Matched from: {chunk['source']} (Distance: {chunk['distance']})")
print(f"Text snippet: {chunk['text']}\n")Through the Settings panel, you can hot-swap the LLM provider at runtime:
- Local Mode (Ollama): Automatically detects live models on your local machine (e.g.,
gemma3:1b). - Cloud API Mode (Groq): Switch to Groq for fast cloud inference by saving your API key in the UI.