Skip to content

mongodb-developer/ai-lab-assistant-2

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MongoDB AI Lab Assistant

License: MIT Node.js Version Next.js Version MongoDB GitHub issues GitHub stars Last Commit

AI LAB Assistant

This AI Lab Assistant is specifically designed to support MongoDB Developer Days workshops. It's a Next.js application that provides AI-powered assistance for MongoDB questions and design reviews, featuring Retrieval-Augmented Generation (RAG) for accurate, context-aware responses. The assistant helps workshop participants by providing contextual help and guidance for various MongoDB workshops and labs.

Related MongoDB Developer Days Workshops

This AI Lab Assistant supports the following workshops:

What is RAG?

Retrieval-Augmented Generation (RAG) is an AI architecture that enhances Large Language Models (LLMs) by providing them with relevant context from a curated knowledge base. Here's how our implementation works:

  1. Document Processing: Documents are split into chunks and converted into vector embeddings using OpenAI's embedding model
  2. Vector Search: When a question is asked, we find the most relevant document chunks using MongoDB Atlas Vector Search
  3. Context-Enhanced Generation: The relevant context is provided to the LLM along with the user's question to generate accurate, contextual responses

Features

  • AI-powered Q&A with RAG:
    • Vector search for accurate information retrieval
    • Support for multiple document formats (PDF, Markdown, Word)
    • Real-time document processing and embedding generation
  • Design Review System:
    • Submit architecture designs for AI-powered review
    • Get detailed feedback and recommendations
  • Admin Dashboard:
    • Upload and manage RAG documents
    • Monitor user questions and feedback
    • Manage design review submissions
  • User Authentication: Secure access with Google OAuth
  • Modern UI: Built with Material UI design system

Tech Stack

  • Frontend: React.js with Next.js App Router
  • UI Library: Material UI
  • Authentication: NextAuth.js with Google OAuth
  • Database: MongoDB with Atlas Vector Search
  • AI Integration:
    • OpenAI API for embeddings and chat completion
    • Vector search for semantic document retrieval
  • Document Processing:
    • PDF parsing with pdf-lib
    • Word document processing with mammoth
    • Markdown support
  • Deployment: Vercel

Building Your Own RAG Chatbot

1. Set Up MongoDB Atlas

  1. Create a MongoDB Atlas cluster
  2. Enable Atlas Vector Search
  3. Create a vector search index on your documents collection

2. Document Processing

Check out scripts/import-docs.js for our document processing pipeline:

// Example document processing
const chunks = await processDocument(content, {
  chunkSize: 1000,
  overlap: 200,
  generateEmbeddings: true
});

3. Vector Search Implementation

See lib/vectorSearch.js for vector search implementation:

// Example vector search query
const results = await collection.aggregate([
  {
    $vectorSearch: {
      index: "default",
      path: "embedding",
      queryVector: embedding,
      numCandidates: 100,
      limit: 5
    }
  }
]);

Getting Started

Prerequisites

  • Node.js 16+
  • MongoDB Atlas account with Vector Search enabled
  • OpenAI API key
  • Google OAuth credentials

Installation

  1. Clone the repository
git clone https://github.com/yourusername/mongodb-ai-lab-assistant.git
cd mongodb-ai-lab-assistant
  1. Install dependencies
npm install
  1. Set up environment variables
cp .env.local.example .env.local
# Edit .env.local with your configuration values

Required environment variables:

MONGODB_URI=your_mongodb_uri
OPENAI_API_KEY=your_openai_key
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
NEXTAUTH_SECRET=your_nextauth_secret
NEXTAUTH_URL=http://localhost:3000

# Admin Authentication
ADMIN_EMAIL=your_admin_email
ADMIN_PASSWORD=your_secure_password

Authentication and Admin Access

The application implements a secure authentication system:

  1. Admin Authentication:

    • Admin routes under /admin/* are protected by middleware and server-side checks
    • Only users who sign in with the credentials matching ADMIN_EMAIL and ADMIN_PASSWORD can access the admin area
    • Double protection: middleware checks the JWT token, and server-side checks occur in the admin layout
  2. Authentication Flow:

    • Users attempt to access admin routes
    • If not authenticated, they're redirected to the sign-in page
    • After successful authentication with admin credentials, they receive a JWT token with isAdmin: true
    • The token is verified on subsequent requests
  3. Environment Variables for Auth:

    • NEXTAUTH_SECRET: Required for secure JWT encryption
    • NEXTAUTH_URL: Your application's base URL
    • ADMIN_EMAIL: Email for admin access
    • ADMIN_PASSWORD: Password for admin access

When deploying to Vercel, ensure all these environment variables are properly configured in your Vercel project settings.

  1. Run the development server
npm run dev
  1. Open http://localhost:3000 in your browser

Developer Days Resources

This project was created for MongoDB Developer Days to demonstrate:

  • Building intelligent chatbots with MongoDB
  • Implementing RAG architecture
  • Using Atlas Vector Search
  • Creating secure, scalable Next.js applications

For more resources:

Deployment on Vercel

  1. Create a Vercel account if you don't have one
  2. Install the Vercel CLI
npm install -g vercel
  1. Deploy to Vercel
vercel

Contributing

We welcome contributions! Please see our Contributing Guide for details.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published