Advanced AI-powered Legal RAG & Multi-Provider Chatbot
DeClerk is a sophisticated full-stack chatbot solution designed for enterprise-grade Retrieval-Augmented Generation (RAG). It features deep structural analysis of PDF documents, semantic vector search with pgvector, and a multi-provider AI engine supporting Gemini, Groq, and OpenRouter.
DeClerk goes beyond simple keyword matching. It implements a multi-layered approach to information retrieval and conversation:
- Intelligent RAG: Semantic search using
pgvectorand local embedding generation with Transformers.js. - Structural PDF Analysis: Automatically detects "Parts" and "Chapters" in complex (e.g., legal) documents for contextual responses.
- Multi-Provider AI: Seamlessly switch between Google Gemini 1.5, Groq (Llama 3/Mixtral), or OpenRouter models.
- Fuzzy Search Fallback: High-performance local search using Fuse.js for exact and near-match queries.
Built with modern web standards, DeClerk demonstrates production-ready patterns for AI integration, document processing, and reactive UI design.
- Vector search: Deep semantic understanding using
pgvectoron Neon PostgreSQL. - Local Embeddings: Privacy-focused embedding generation using
@xenova/transformers. - Structural Awareness: Extracts hierarchical information (Chapter/Section) from PDFs to provide precise citations.
- Smart Chunking: Semantically-aware text splitting with overlap for better context preservation.
- Google Gemini: Integration with Gemini 1.5 Pro/Flash for high-reasoning tasks.
- Groq API: Blazing fast responses using Llama 3 and Mixtral models.
- OpenRouter: Unified access point for a wide range of open-source LLMs.
- Stateful Chats: Persistent conversation history for context-aware interactions.
- Vue 3 Composition API: Modular, reactive component architecture.
- Dynamic File Uploads: Real-time PDF processing and indexing via the UI.
- Rich Interaction: Fluid typing indicators, markdown rendering, and smooth transitions.
- Responsive Mastery: Tailored experiences for both desktop and mobile users.
- Scalable Architecture: Clean separation of services, controllers, and database layers.
- Automated Schema: Self-initializing database tables and vector extensions on startup.
- Health Monitoring: Built-in endpoints for service metrics and connectivity status.
- Vue 3 - Framework with Composition API
- Vite - Modern frontend tooling
- Axios - Promise-based HTTP client
- CSS3/Animations - Custom-crafted premium aesthetics
- Node.js & Express - Efficient server-side runtime and framework
- Neon / PostgreSQL - Serverless database with
pgvectorsupport - Fuse.js - Lightweight fuzzy search for local data
- PDF-parse - Robust PDF text extraction
- Gemini API - Google's latest generative models
- Groq API - Low-latency LLM inference
- Transformers.js - Local ML for embedding generation
- OpenRouter - Aggregated AI model gateway
- Node.js 18+ and npm
- Neon.tech account (or any PostgreSQL with
pgvector) - One or more AI API Keys (Gemini, Groq, or OpenRouter)
-
Clone the repository
git clone https://github.com/NelakaWith/de-clerk.git cd de-clerk -
Install all dependencies
npm install
-
Configure Environment Variables
Navigate to the
backenddirectory and create your.envfile:cd backend cp .env.example .envAdd your credentials to
.env:NEON_DATABASE_URL: Your PostgreSQL connection string.GEMINI_API_KEY: [Optional] Google AI Studio key.GROQ_API_KEY: [Optional] Groq Console key.OPENROUTER_API_KEY: [Optional] OpenRouter key.
-
Launch Development Servers
Terminal 1 (Backend):
cd backend npm run devTerminal 2 (Frontend):
cd frontend npm run dev -
Access Application
- Frontend UI: http://localhost:5173
- API Status: http://localhost:3000/health
Simply execute the included batch file for a onend-click setup:
run-demo.batdeclerk/
βββ backend/ # Express.js Server
β βββ src/
β β βββ controllers/ # Request logic handlers
β β βββ routes/ # API route definitions
β β βββ services/ # RAG, Search, and AI logic
β β βββ db/ # Database schema & connection
β βββ data/ # Default JSON knowledge bases
βββ frontend/ # Vue 3 Application
β βββ src/
β β βββ components/ # Reusable UI components
β β βββ composables/ # Shared reactive logic
βββ documents/ # Storage for local PDF sources
βββ scripts/ # Maintenance and utility scripts
βββ docker-compose.yml # Containerization config| Method | Endpoint | Description |
|---|---|---|
POST |
/api/chat |
Intelligent hybrid search query |
POST |
/api/chat/llm |
Multi-model AI conversation |
POST |
/api/rag/upload |
Upload and vectorize PDF document |
GET |
/status |
Real-time service usage & metrics |
GET |
/health |
System connectivity health check |
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Nelaka Withanage
- GitHub: @NelakaWith
- Portfolio: nelaka.xyz
- LinkedIn: in/nelaka-withanage/
Distributed under the MIT License. See LICENSE for more information.
β Star this repository if you found it helpful!
Built with excellence using Vue.js, Express.js, and next-gen AI.