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.
This AI Lab Assistant supports the following workshops:
- Introduction to MongoDB - Get started with MongoDB basics
- Building AI Applications with RAG - Learn how to build AI applications using RAG architecture
- Atlas Search - Master MongoDB Atlas Search capabilities
- Atlas Vector Search - Deep dive into vector search implementation
- SQL to MongoDB Query API - Learn how to transition from SQL to MongoDB queries
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:
- Document Processing: Documents are split into chunks and converted into vector embeddings using OpenAI's embedding model
- Vector Search: When a question is asked, we find the most relevant document chunks using MongoDB Atlas Vector Search
- Context-Enhanced Generation: The relevant context is provided to the LLM along with the user's question to generate accurate, contextual responses
- 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
- 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
- Create a MongoDB Atlas cluster
- Enable Atlas Vector Search
- Create a vector search index on your documents collection
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
});
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
}
}
]);
- Node.js 16+
- MongoDB Atlas account with Vector Search enabled
- OpenAI API key
- Google OAuth credentials
- Clone the repository
git clone https://github.com/yourusername/mongodb-ai-lab-assistant.git
cd mongodb-ai-lab-assistant
- Install dependencies
npm install
- 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
The application implements a secure authentication system:
-
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
andADMIN_PASSWORD
can access the admin area - Double protection: middleware checks the JWT token, and server-side checks occur in the admin layout
- Admin routes under
-
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
-
Environment Variables for Auth:
NEXTAUTH_SECRET
: Required for secure JWT encryptionNEXTAUTH_URL
: Your application's base URLADMIN_EMAIL
: Email for admin accessADMIN_PASSWORD
: Password for admin access
When deploying to Vercel, ensure all these environment variables are properly configured in your Vercel project settings.
- Run the development server
npm run dev
- Open http://localhost:3000 in your browser
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:
- Create a Vercel account if you don't have one
- Install the Vercel CLI
npm install -g vercel
- Deploy to Vercel
vercel
We welcome contributions! Please see our Contributing Guide for details.
This project is licensed under the MIT License - see the LICENSE file for details.