Skip to content

Repository files navigation

SAGEVAULT- MERN RAG Chatbot

Backend tests

This project is a Knowledge Management Platform built using the MERN stack (MongoDB, Express.js, React, Node.js) with RAG (Retrieval Augmented Generation) capabilities for conversational AI.

Table of Contents

Setup Instructions

Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js
  • npm
  • MongoDB
  • Git

Backend Setup

  1. Navigate to the backend directory:
    cd backend
  2. Install dependencies:
    npm install
  3. Create a .env file in the backend directory — see backend/sample.env for the full list of variables:
    MONGODB_URL=your_mongodb_connection_string
    JWT_SECRET=your_jwt_secret          # random string, 32+ characters
    GOOGLE_API_KEY=your_google_gemini_api_key
    FRONTEND_URL=http://localhost:5173  # comma-separated if you need more than one origin
    
    All four are required — the server exits immediately at boot with a clear error if any are missing, rather than failing confusingly on the first request.
  4. Start the backend server:
    npm run dev
    The backend server will typically run on http://localhost:3000.

Frontend Setup

  1. Navigate to the frontend directory:
    cd frontend
  2. Install dependencies:
    npm install
  3. Start the frontend development server:
    npm run dev
    The frontend application will typically run on http://localhost:5173.

Usage

Once both the backend and frontend servers are running:

  1. Open your web browser and navigate to the frontend URL (e.g., http://localhost:5173).
  2. Register a new user or log in with existing credentials.
  3. Upload documents through the Document Management System.
  4. Interact with the conversational AI by asking questions related to the uploaded documents.
  5. Explore the analytics dashboard for insights into document usage and user activity.

Architecture Overview

The platform follows a MERN stack architecture with a clear separation between the frontend and backend. The backend handles API requests, database interactions, and integrates with LLMs for RAG capabilities. The frontend provides a responsive user interface for document management, conversational AI, and analytics.

  • Frontend: Built with React, responsible for user interaction and displaying data.
  • Backend: Built with Node.js (Express.js), handles API routing, business logic, authentication, and integration with MongoDB and LLMs.
  • Database: MongoDB is used for storing user data, document metadata, chat history, and other application-specific information.
  • Vector Store: A vector database FAISS is used to store document embeddings for efficient retrieval during RAG.
  • LLM Integration: Utilizes Google Gemini for conversational AI and document understanding.

LLM Use

Large Language Models (LLMs) are primarily used in the Conversational AI Interface for Retrieval Augmented Generation (RAG). When a user asks a question:

  1. The query is embedded and used to retrieve relevant document chunks from the vector store.
  2. These retrieved chunks, along with the user's query, are sent to the LLM (Google Gemini).
  3. The LLM generates a coherent and contextually relevant response based on the provided documents.

This approach ensures that the AI responses are grounded in the organization's knowledge base, reducing hallucinations and providing accurate information.

API Documentation

Detailed API documentation can be found here or by exploring the backend/routes and backend/controllers directories. Key endpoints include:

  • /api/v1/auth/register: User registration (rate-limited).
  • /api/v1/auth/login: User login (rate-limited).
  • /api/v1/auth/profile: Get user profile.
  • /api/v1/document/upload: Upload a document.
  • /api/v1/document: List documents.
  • /api/v1/chat/sessions: Create a chat session / list sessions.
  • /api/v1/chat/sessions/:sessionId/messages: Send a message to the conversational AI.
  • /health: Liveness check, returns { status: "ok", uptime }.

For more details, refer to the source code in the backend directory.

Known issues

  • npm audit currently reports vulnerabilities in the LangChain dependency chain (@langchain/community, langsmith, transitively uuid) — mostly SSRF/prototype-pollution advisories in loaders and tracing this project doesn't use directly. A fix is available (npm audit fix --force) but it's a breaking major-version bump across the LangChain packages, so it hasn't been applied without re-testing the RAG pipeline against the new API surface. Tracked as follow-up work rather than a blind upgrade.

About

Knowledge management platform with RAG-powered conversational AI (MERN stack)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages