A comprehensive Retrieval-Augmented Generation (RAG) chatbot system built with LangChain, LangGraph, FastAPI, and Streamlit. This enterprise-grade solution provides role-based access control and domain-specific knowledge retrieval for different organizational departments.


š Data Privacy & Security
In traditional RAG systems, users can potentially craft malicious prompts to access sensitive information across organizational silos, bypassing intended data boundaries. This poses significant security risks where employees might gain unauthorized access to confidential documents from other departments through clever prompt engineering.
Our Solution: This system implements role-based retrieval and response generation at the vector database level, ensuring that users can only access documents relevant to their organizational role. The retrieval mechanism filters documents based on user permissions before any LLM processing occurs, preventing data leakage through prompt manipulation.
š Features
- Role-Based Access Control: Different access levels for various departments (Engineering, Marketing, Finance, HR, C-Level)
- RAG Architecture: Combines retrieval and generation for accurate, context-aware responses
- Vector Database: ChromaDB for efficient document storage and retrieval
- Modern UI: Streamlit-based frontend with authentication
- FastAPI Backend: RESTful API with HTTP Basic Authentication
šļø Architecture
The project consists of three main components:
1. Backend (/backend
)
- FastAPI server with authentication and chat endpoints
- LangGraph agents for conversation flow management
- ChromaDB vector store for document retrieval
- Role-based access control system
2. Frontend (/frontend
)
- Streamlit web interface
- User authentication and session management
- Real-time chat interface
3. Training (/training
)
- Data processing and vector store creation
- Jupyter notebooks for experimentation
- Document ingestion pipeline
š Prerequisites
- Python 3.12+
- UV package manager (recommended) or pip
- Google Gemini API key (for LLM integration)
š ļø Installation
1. Clone the Repository
mkdir RAG-chatbot
git clone https://github.com/shashanksrajak/RBAC-RAG-chatbot.git .
cd RAG-chatbot
2. Environment Setup
.env
file in the root directory:GOOGLE_API_KEY=your_google_gemini_api_key_here
3. Install Dependencies
Using UV (Recommended)
# Backend
cd backend
uv sync
# Frontend
cd ../frontend
uv sync
# Training (optional)
cd ../training
uv sync
š Quick Start
1. Start the Backend Server
cd backend
uv run src/main.py
http://localhost:6001
2. Launch the Frontend
cd frontend
uv run streamlit run main.py
http://localhost:8501
3. Login with Demo Credentials
Use any of these demo accounts:
Username | Password | Role | Access Level |
---|---|---|---|
Tony | password123 | Engineering | Technical documents |
Bruce | securepass | Marketing | Marketing reports |
Sam | financepass | Finance | Financial data |
Natasha | hrpass123 | HR | HR policies |
Shashank | password123 | C-Level | All documents |
š Project Structure
RAG-chatbot/
āāā backend/ # FastAPI backend
ā āāā src/
ā ā āāā agents/ # LangGraph agents
ā ā ā āāā graph.py # Agent workflow
ā ā ā āāā nodes.py # Processing nodes
ā ā ā āāā prompts.py # LLM prompts
ā ā ā āāā states.py # State management
ā ā āāā services/ # Business logic
ā ā ā āāā chatbot.py # Chatbot service
ā ā āāā main.py # FastAPI application
ā āāā pyproject.toml
āāā frontend/ # Streamlit frontend
ā āāā main.py # Streamlit app
ā āāā pyproject.toml
āāā training/ # Data processing
ā āāā data/ # Source documents
ā ā āāā engineering/ # Technical docs
ā ā āāā finance/ # Financial reports
ā ā āāā general/ # General policies
ā ā āāā hr/ # HR documents
ā ā āāā marketing/ # Marketing materials
ā āāā chatbot_agent.ipynb # Training notebook
ā āāā RAG_intro.ipynb # RAG introduction
āāā docs/ # Documentation
š§ API Endpoints
Authentication
GET /login
- Authenticate user and get role informationGET /test
- Test authenticated access
Chat
POST /chat
- Send message to chatbot (requires authentication)- Parameters:
message
(string) - Returns: AI response based on user's role and access level
- Parameters:
Health Check
GET /
- Server status check
š§ AI Components
LangChain Integration
- Google Gemini: Primary LLM for response generation
- ChromaDB: Vector database for document storage
- Text Splitters: Intelligent document chunking
- Retrieval Chain: Semantic search and context retrieval
LangGraph Workflow
- Retrieve Node: Fetches relevant documents based on query and access level
- Generate Node: Creates contextual responses using retrieved information
- State Management: Maintains conversation context and user permissions
š Supported Document Types
- Markdown (.md)
- CSV (.csv)
- More formats can be added by extending the document loaders
šÆ Use Cases
- Internal Knowledge Base: Company-wide information retrieval
- Department-Specific Queries: Role-based information access
- Document Q&A: Natural language queries over company documents
- Compliance and Policy: Easy access to HR and legal documents
- Technical Support: Engineering documentation assistance
Note: This is a demonstration project with hardcoded credentials. For production use, implement proper authentication and authorization mechanisms.
Interested in this project?
Check out the full source code and documentation on GitHub.