A full-stack RAG (Retrieval-Augmented Generation) application that lets you chat with the Marvel Universe using AI. Ask questions about Marvel characters, storylines, and lore with context-aware responses powered by vector search and GPT-4.
π Try Marvel Oracle
- Context-Aware Conversations: Remembers chat history for follow-up questions
- Query Rewriting: Automatically enhances ambiguous questions using conversation context
- Vector Search: Uses Pinecone for semantic similarity search across Marvel content
- GPT-4 Integration: Powered by OpenAI's most advanced language model
- Multiple Timelines: Create and manage separate conversation threads
- Real-time Responses: Streaming responses with loading indicators
- Chat History: Persistent conversation storage with Appwrite
- Context Menu: Edit chat names, delete conversations
- Auto-scroll: Automatically scrolls to latest messages
- Secure Login/Signup: Email-password authentication via Appwrite
- Password Reset: Email-based password recovery system
- HTTP-only Cookies: Secure session management
- Route Protection: Middleware-based authentication guards
- Dark Theme: Marvel-inspired red and gray color scheme
- Responsive Design: Works seamlessly on desktop and mobile
- Smooth Animations: Polished loading states and transitions
- Intuitive Navigation: Clean sidebar with chat history
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Next.js β β Vercel β β External β
β Frontend βββββΊβ Serverless βββββΊβ Services β
β β β Functions β β β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β β β
β β’ React Components β β’ Python API β β’ Appwrite DB
β β’ Zustand Store β β’ LangChain RAG β β’ Pinecone Vector
β β’ TailwindCSS β β’ Query Processing β β’ OpenAI GPT-4
β β’ TypeScript β β’ Chat History β β’ Email Service
- Next.js 14 - React framework with App Router
- TypeScript - Type-safe JavaScript
- TailwindCSS - Utility-first CSS framework
- Zustand - Lightweight state management
- Python - Server-side logic
- LangChain - RAG pipeline and AI orchestration
- Vercel Serverless - Serverless function deployment
- OpenAI GPT-4 - Large language model
- Pinecone - Vector database for embeddings
- OpenAI Embeddings - Text-to-vector conversion
- Appwrite - Backend-as-a-Service for auth and data
- Appwrite Database - Document database for chats
- Node.js 18+
- Python 3.9+
- npm or yarn
Create these environment variable files:
NEXT_PUBLIC_APPWRITE_ENDPOINT=https://cloud.appwrite.io/v1
NEXT_PUBLIC_APPWRITE_PROJECT_ID=your_project_id
NEXT_PUBLIC_APPWRITE_DATABASE_ID=your_database_id
NEXT_PUBLIC_APPWRITE_COLLECTION_ID=your_collection_id
NEXT_PUBLIC_API_URL=http://localhost:3000/apiOPENAI_API_KEY=your_openai_api_key
PINECONE_API_KEY=your_pinecone_api_key- Clone the repository
git clone https://github.com/yourusername/marvel-oracle.git
cd marvel-oracle- Install dependencies
# Install client dependencies
cd client
npm install
# Install server dependencies (for local development)
cd ../server
pip install -r requirements.txt-
Set up external services
Appwrite Setup:
- Create account at Appwrite Cloud
- Create new project
- Set up database and collection for chat storage
- Configure authentication settings
Pinecone Setup:
- Create account at Pinecone
- Create index named
marvel-embeddings - Upload your Marvel content embeddings
OpenAI Setup:
- Get API key from OpenAI Platform
-
Run development servers
# Start Next.js frontend (from project root)
npm run dev:client
# Start Python backend (from project root)
npm run dev:server- Open the application
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
The application is configured for one-click deployment to Vercel:
- Using Vercel CLI
npm install -g vercel
vercel --prod- Using GitHub Integration
- Push code to GitHub
- Import repository in Vercel dashboard
- Configure environment variables
- Deploy automatically
Set these in your Vercel dashboard:
OPENAI_API_KEY=your_openai_api_key
PINECONE_API_KEY=your_pinecone_api_key
NEXT_PUBLIC_APPWRITE_ENDPOINT=https://cloud.appwrite.io/v1
NEXT_PUBLIC_APPWRITE_PROJECT_ID=your_project_id
NEXT_PUBLIC_APPWRITE_DATABASE_ID=your_database_id
NEXT_PUBLIC_APPWRITE_COLLECTION_ID=your_collection_idmarvel-oracle/
βββ client/ # Next.js frontend
β βββ src/
β β βββ app/ # App Router pages
β β β βββ login/ # Authentication pages
β β β βββ signup/
β β β βββ reset-password/
β β βββ components/ # React components
β β β βββ Chatbot.tsx # Main chat interface
β β β βββ Chatbar.tsx # Message input
β β β βββ History.tsx # Chat sidebar
β β β βββ ...
β β βββ store/ # Zustand state management
β β βββ types/ # TypeScript type definitions
β β βββ utils.ts # API utilities
β βββ middleware.ts # Route protection
β βββ package.json
βββ api/ # Vercel serverless functions
β βββ index.py # Health check endpoint
β βββ query.py # RAG query processing
βββ server/ # Local development server
β βββ server.py # FastAPI development server
βββ requirements.txt # Python dependencies
βββ vercel.json # Vercel configuration
βββ README.md
The core RAG (Retrieval-Augmented Generation) system works as follows:
- Query Processing: User questions are analyzed for context dependency
- Query Rewriting: Ambiguous questions are rewritten using chat history
- Vector Search: Enhanced queries retrieve relevant Marvel content from Pinecone
- Response Generation: GPT-4 generates responses using retrieved context and chat history
User: "Who is the boss of Peter Parker's newspaper?"
AI: "J. Jonah Jameson is the editor-in-chief of the Daily Bugle..."
User: "Who is that?" β Ambiguous question
AI: β
Understands "that" refers to J. Jonah Jameson from context
- Multiple Timelines: Each chat maintains separate conversation history
- Persistent Storage: All conversations saved to Appwrite database
- Real-time Updates: UI updates immediately with new messages
- Context Isolation: Each chat has its own context window
GET /api/query
Headers:
Query: "Who is Spider-Man?"
Session-Id: "unique_chat_id"
Response:
{
"query": "Who is Spider-Man?",
"response": "Spider-Man is Peter Parker, a young man who gained spider-like abilities...",
"session_id": "unique_chat_id"
}GET /api/
Response:
{
"message": "Marvel RAG API is running!",
"status": "healthy",
"env_check": {
"openai_key_set": true,
"pinecone_key_set": true
}
}- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Marvel Comics - For the incredible universe and characters
- OpenAI - For GPT-4 and embedding models
- LangChain - For RAG framework and tools
- Vercel - For seamless deployment platform
- Appwrite - For authentication and database services
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: your.email@example.com
π·οΈ Built with β€οΈ for Marvel fans by Marvel fans π·οΈ Live Demo