A full-stack Retrieval-Augmented Generation (RAG) application that lets users upload private documents (PDFs, DOCX, TXT) and chat with them accurately using AI — powered by Groq LLM and ChromaDB.
- 📄 Upload PDF, DOCX, and TXT documents
- ⚡ Fast AI responses powered by Groq (LLaMA 3.3 70B)
- 🔍 Semantic search using vector embeddings
- 📌 Source citations with every answer (filename, page, excerpt)
- 🌊 Streamed responses word-by-word (like ChatGPT)
- 🗂️ Knowledge base management (upload, view, delete documents)
- 🎯 Confidence scoring based on similarity thresholds
- 🌙 Dark mode support
- 📱 Mobile responsive UI
User Question
↓
Embed Query (HuggingFace all-MiniLM-L6-v2)
↓
Search ChromaDB → Top 5 Similar Chunks
↓
Build Prompt (System + Chunks + Question)
↓
Groq API (llama-3.3-70b-versatile)
↓
Stream Answer + Return Sources
| Layer | Technology |
|---|---|
| Frontend | React + Tailwind CSS |
| Backend | Node.js + Express |
| LLM | Groq API (LLaMA 3.3 70B) |
| Embeddings | HuggingFace all-MiniLM-L6-v2 |
| Vector DB | ChromaDB |
| PDF Parsing | pdf-parse |
| DOCX Parsing | mammoth |
| Streaming | Server-Sent Events (SSE) |
knowledge-base-rag/
├── client/ # React frontend
│ ├── src/
│ │ ├── components/
│ │ │ ├── ChatWindow.jsx
│ │ │ ├── MessageBubble.jsx
│ │ │ ├── SourceCard.jsx
│ │ │ ├── DocumentSidebar.jsx
│ │ │ └── UploadZone.jsx
│ │ ├── pages/
│ │ │ ├── Chat.jsx
│ │ │ └── KnowledgeBase.jsx
│ │ └── App.jsx
│ └── package.json
│
├── server/ # Express backend
│ ├── routes/
│ │ ├── documents.js # Upload, list, delete
│ │ └── chat.js # Query + RAG pipeline
│ ├── services/
│ │ ├── embeddings.js # HuggingFace embeddings
│ │ ├── vectorDB.js # ChromaDB operations
│ │ ├── groqLLM.js # Groq API calls
│ │ └── chunker.js # Text chunking logic
│ ├── parsers/
│ │ ├── pdfParser.js
│ │ ├── docxParser.js
│ │ └── txtParser.js
│ ├── uploads/ # Temporary file storage
│ └── index.js
│
├── .env.example
├── docker-compose.yml
└── README.md
- Node.js v18+
- Python 3.9+ (for ChromaDB)
- npm or yarn
- Groq API Key → console.groq.com
git clone https://github.com/your-username/knowledge-base-rag.git
cd knowledge-base-ragcd server
npm installcd ../client
npm installpip install chromadb sentence-transformerscp .env.example .envEdit .env and fill in your values:
# Groq API
GROQ_API_KEY=your_groq_api_key_here
GROQ_MODEL=llama-3.3-70b-versatile
# Embeddings
EMBEDDING_MODEL=all-MiniLM-L6-v2
# ChromaDB
CHROMA_HOST=localhost
CHROMA_PORT=8000
# App Config
MAX_FILE_SIZE_MB=20
CHUNK_SIZE=500
CHUNK_OVERLAP=50
TOP_K_RESULTS=5
PORT=3001chroma run --host localhost --port 8000cd server
npm run devcd client
npm run devhttp://localhost:5173
POST /api/documents/upload
Content-Type: multipart/form-data
Body: file (PDF | DOCX | TXT)Response:
{
"id": "doc_abc123",
"filename": "policy.pdf",
"chunks": 42,
"status": "ready"
}GET /api/documentsResponse:
[
{
"id": "doc_abc123",
"filename": "policy.pdf",
"size": "1.2MB",
"uploadedAt": "2025-06-18T10:00:00Z",
"chunks": 42,
"status": "ready"
}
]DELETE /api/documents/:idPOST /api/chat
Content-Type: application/json
{
"question": "What is the refund policy?",
"documentIds": ["doc_abc123", "doc_xyz456"]
}Response (streamed via SSE):
{
"answer": "Based on the uploaded documents, customers can request a refund within 30 days...",
"sources": [
{
"filename": "policy.pdf",
"page": 2,
"excerpt": "...eligible for a full refund within 30 days...",
"score": 0.92,
"confidence": "high"
}
]
}| Similarity Score | Confidence | Behavior |
|---|---|---|
| 0.90 – 1.00 | 🟢 High | Answer directly |
| 0.75 – 0.89 | 🟡 Medium | Answer with disclaimer |
| 0.60 – 0.74 | 🟠 Low | "This might be relevant..." |
| Below 0.60 | 🔴 None | "Not found in documents" |
docker-compose up --buildServices started:
- Frontend →
http://localhost:5173 - Backend →
http://localhost:3001 - ChromaDB →
http://localhost:8000
# Backend tests
cd server
npm run test
# Frontend tests
cd client
npm run test- All uploaded documents are stored locally and never sent to third-party servers (except the text chunks sent to Groq for answering)
- API keys are stored in
.envand never exposed to the frontend - File type and size validation on upload
- Add authentication middleware before deploying to production
| Format | Library Used | Max Size |
|---|---|---|
.pdf |
pdf-parse |
20MB |
.docx |
mammoth |
20MB |
.txt |
Native Node.js | 20MB |
- User authentication (JWT)
- Multi-user support with isolated knowledge bases
- Support for
.csvand.xlsxfiles - URL/website ingestion
- Document versioning
- Export chat history as PDF
- Ollama support for fully local LLM
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Commit your changes:
git commit -m "Add my feature" - Push to the branch:
git push origin feature/my-feature - Open a Pull Request
MIT License — feel free to use, modify, and distribute.
If you run into issues, open a GitHub Issue or reach out at manindrachowdhary1715@email.com.
Built with ❤️ using Groq, ChromaDB, and React