A full-stack Retrieval-Augmented Generation (RAG) application that allows users to upload documents and ask questions about them using AI. The system combines semantic search with a large language model to provide accurate, context-aware responses streamed in real-time.
βββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β Frontend ββββββΆβ Backend API ββββββΆβ Redis β
β (Next.js) β β (Laravel) β β (Cache + β
β Port 3000 β β Port 8000 β β History) β
ββββββββ¬ββββββββ ββββββββββββββββ ββββββββββββββββ
β
β Streaming Chat
βΌ
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β AI Backend ββββββΆβ Pinecone β β Ollama β
β (FastAPI) β β (Vector DB) β β (Embeddings) β
β Port 8081 β ββββββββββββββββ β Port 11434 β
ββββββββ¬ββββββββ ββββββββββββββββ
β
βΌ
ββββββββββββββββ
β Google AI β
β (Gemini) β
ββββββββββββββββ
- Streaming responses β real-time token-by-token output like ChatGPT
- Markdown rendering β bold, tables, code blocks, lists, headings rendered in chat
- Semantic cache β identical/similar questions are answered instantly from Redis cache
- Conversation history β stored per session in Redis with 24h TTL
- Re-ranking β retrieves 10 documents, re-ranks to top 4 using FlashRank for accuracy
- Session management β create, rename, and delete chat conversations
- Upload documents β supports PDF, DOCX, TXT, and Markdown files
- Automatic chunking β documents are split with
RecursiveCharacterTextSplitter - Vector embeddings β chunks are embedded using Ollama (
mxbai-embed-large) and stored in Pinecone - Delete documents β remove documents and their vectors from Pinecone
- Total tokens used, total chats, active users
- Cache hit rate monitoring
- Hourly token usage trend (last 24 hours)
- Top FAQ topics
- Recent chat logs
- Email/password login via Laravel Sanctum
- Google OAuth login via Laravel Socialite
- Protected routes with middleware
- Dark/light mode toggle
- Responsive sidebar with session management
- Smooth streaming with RAF-based rendering (no jitter)
- Loading states and micro-animations
| Layer | Technology |
|---|---|
| Frontend | Next.js 16, React 19, TypeScript, Tailwind CSS v4, Zustand, Framer Motion |
| Backend API | Laravel 12, PHP 8.2, Sanctum, Socialite |
| AI Backend | FastAPI, LangChain, Python 3.10 |
| LLM | Google Gemini (via langchain-google-genai) |
| Embeddings | Ollama (mxbai-embed-large) |
| Vector DB | Pinecone |
| Cache & History | Redis (Redis Stack with vector search) |
| Re-ranking | FlashRank |
| Containerization | Docker & Docker Compose |
Before you begin, make sure you have the following installed:
- Node.js β₯ 20.x
- PHP β₯ 8.2 + Composer
- Python β₯ 3.10
- Docker & Docker Compose
- Ollama running locally with
mxbai-embed-largemodel pulled - Pinecone account
- Google AI API Key (for Gemini)
git clone https://github.com/SatyaFebi/NEW_RAG.git
cd NEW_RAG# Install Ollama: https://ollama.com/download
ollama pull mxbai-embed-large
ollama serve # Runs on port 11434# Copy environment file
cp backend-fastapi/.env.example backend-fastapi/.envEdit backend-fastapi/.env with your credentials:
PINECONE_API_KEY=your_pinecone_api_key
PINECONE_INDEX_NAME=your_index_name
EMBEDDING_MODEL_NAME=mxbai-embed-large
GOOGLE_API_KEY=your_google_ai_api_key
GEMINI_MODEL=gemini-2.5-flash-lite
REDIS_URL=redis://redis:6379
# Optional: LangSmith tracing
LANGSMITH_TRACING=false
LANGSMITH_API_KEY=
LANGSMITH_PROJECT=docker compose up -d --buildThis starts:
- FastAPI AI backend on
http://localhost:8081 - Redis Stack on
http://localhost:6379
cd backend
cp .env.example .env
composer install
php artisan key:generate
php artisan migrate
php artisan serve # Runs on port 8000cd frontend
npm installCreate/edit frontend/.env:
NEXT_PUBLIC_API_URL=http://localhost:8000/api
NEXT_PUBLIC_AI_API_URL=http://localhost:8081npm run dev # Runs on port 3000Navigate to http://localhost:3000 β login and start chatting!
cd frontend
npm run build
npm start # Serves production build on port 3000Uncomment the laravel_app and nextjs_web services in docker-compose.yml, then:
docker compose up -d --buildNEW_RAG/
βββ backend/ # Laravel API (Auth, User Management)
β βββ app/
β βββ routes/api.php # API routes (login, user, OAuth)
β βββ .env.example
β βββ ...
β
βββ backend-fastapi/ # FastAPI AI Service
β βββ main.py # All AI logic (chat, upload, dashboard)
β βββ requirements.txt # Python dependencies
β βββ Dockerfile
β βββ .env.example
β
βββ frontend/ # Next.js Frontend
β βββ src/
β β βββ app/
β β β βββ chat/ # Chat page with streaming
β β β βββ dashboard/ # Analytics dashboard
β β β βββ documents/ # Document management
β β β βββ login/ # Login page
β β β βββ globals.css # Design system + markdown styles
β β βββ components/ # Sidebar, ThemeProvider
β β βββ store/ # Zustand stores (chat, auth, theme)
β β βββ lib/ # API utilities
β βββ .env
β
βββ docker-compose.yml # Orchestrates FastAPI + Redis
βββ README.md
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Health check |
POST |
/chat |
Send message, receive streaming AI response |
POST |
/documents/upload |
Upload document (PDF, DOCX, TXT, MD) |
GET |
/documents |
List documents (limited) |
DELETE |
/documents/{doc_id} |
Delete document by ID |
GET |
/dashboard/stats |
Get analytics data |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/login |
Email/password login |
GET |
/api/user |
Get authenticated user (Sanctum) |
GET |
/api/auth/google |
Redirect to Google OAuth |
GET |
/api/auth/google/callback |
Handle Google OAuth callback |
| Problem | Solution |
|---|---|
| Ollama connection refused | Make sure ollama serve is running on port 11434 |
| Pinecone timeout | Check your API key and index name in .env |
| Redis connection error | Ensure Redis container is running: docker ps |
| Frontend not updating | Run npm run dev or npm run build |
| FastAPI container error | Check logs: docker logs fastapi_rag |
| Vite manifest error | Run npm run build in /frontend |
This project is for educational and personal use.
Built with β€οΈ by Satya