A Retrieval-Augmented Generation (RAG) based internal chatbot for enterprises, featuring robust role-based access control (RBAC). Built with FastAPI, Qdrant vector database, OpenAI GPT-4, and a modular, extensible architecture.
- Role-Based Access Control (RBAC): Restricts document access and chatbot responses based on user roles (engineering, finance, hr, marketing, general, c-level).
- Retrieval-Augmented Generation (RAG): Combines semantic search (Qdrant + Sentence Transformers) with GPT-4 for context-aware, accurate answers.
- Document Indexing: Supports Markdown and CSV files, chunked and embedded for efficient retrieval.
- Admin Endpoints: For indexing, stats, and user management.
- Authentication: HTTP Basic Auth (can be extended to OAuth/JWT).
- Dockerized: Easy deployment with Docker Compose (FastAPI, Qdrant, Postgres).
Architecture Overview
- FastAPI: Main API server, handles auth, chat, admin, and indexing endpoints.
- Qdrant: Vector database for semantic search.
- Sentence Transformers: Generates embeddings for document chunks.
- OpenAI GPT-4: Generates final answers using retrieved context.
- Postgres: Stores user data and roles.
- Resources/data: Folder structure for role-based documents.
resources/data/<role>/— Documents for each role (e.g., engineering, finance, hr, marketing, general)- Markdown:
*.md - CSV:
*.csv
- Markdown:
Example:
resources/data/engineering/engineering_master_doc.md
resources/data/hr/hr_data.csv
resources/data/general/employee_handbook.md
resources/data/marketing/marketing_report_2024.md
resources/data/finance/financial_summary.md
git clone <your-fork-url>
cd ds-rpc-01Create a .env file in the root with your OpenAI API key:
OPENAI_API_KEY=sk-...
python -m venv venv
source venv/bin/activate
pip install -r requirenmnets.txtdocker-compose up --build- FastAPI: http://localhost:8000/docs
- Qdrant: http://localhost:6333
- Postgres: localhost:5432
- Initialize Qdrant:
POST /admin/index/init - Index All Documents:
POST /admin/index/documents - Get Stats:
GET /admin/index/stats - Clear Index:
DELETE /admin/index/clear
- HTTP Basic Auth (username/password)
- Users and roles are stored in Postgres (
app/db/models.py)
POST /chat(requires login)- Body:
{ "message": "your question" } - Returns: RAG-powered answer, role-aware, with references
GET /admin/users— List usersPOST /admin/users— Add userDELETE /admin/users/{username}— Remove user
- engineering
- finance
- general
- hr
- marketing
- c-level (access to all docs)
- Add new roles: Create a new folder in
resources/data/and update user roles in the DB. - Add new document types: Extend
app/utils/file_loader.py. - Change embedding model: Update
EMBEDDING_MODELinapp/services/vector_store.py. - Switch LLM: Update
modelinapp/services/rag_engine.py.
- fastapi
- uvicorn
- qdrant-client
- sentence-transformers
- pandas
- python-dotenv
- streamlit
- httpx
- openai
- markdown
- sqlalchemy
- psycopg2-binary
This project is for internal use at FinSolve Technologies.
- Codebasics Resume Project Challenge
- Qdrant, OpenAI, FastAPI, Sentence Transformers