A Next.js chatbot application for RapidClaims that uses RAG (Retrieval-Augmented Generation) with Google Gemini AI and DataStax Astra DB for vector storage.
AI-powered chatbot using Google Gemini
Vector similarity search with Astra DB
RAG (Retrieval-Augmented Generation) architecture
Streaming responses with real-time updates
Modern, responsive chat interface
Fully optimized for mobile devices
New Chat button to reset conversations
Prompt suggestions for quick interactions
Perfectly centered UI with enhanced positioning
Clean message bubbles without avatar prefixes
- Node.js 18+ and npm
- A Google AI Studio account (for Gemini API key)
- A DataStax Astra DB account (free tier available)
npm install- Go to Google AI Studio
- Sign in with your Google account
- Click "Create API Key"
- Copy your API key (you'll add it to
.envin step 4)
- Go to DataStax Astra DB
- Sign in or create a free account
- Click "Create Database" or "Add Database"
- Choose:
- Database Name: e.g.,
chatbot-db - Provider & Region: Choose the closest region to you
- Database Type: Select "Vector Database" (or "Serverless")
- Database Name: e.g.,
- Click "Create Database"
- Wait 2-3 minutes for the database to be created
Once your database is ready:
-
Click on your database name
-
Go to the "Connect" tab
-
Under "Application Tokens", click "Generate Token"
-
Choose:
- Token Name: e.g.,
chatbot-token - Role: Select "Database Administrator" (or "Database User" with appropriate permissions)
- Token Name: e.g.,
-
Click "Generate Token"
-
IMPORTANT: Copy the token immediately (you won't see it again!)
- It will look like:
AstraCS:xxxxxxxxxxxxx...
- It will look like:
-
Find your API Endpoint:
- In the "Connect" tab, look for "API Endpoint"
- It will look like:
https://xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-xxxxx.apps.astra.datastax.com - Copy this entire URL
-
Find your Namespace:
- In the Astra DB dashboard, go to "CQL Console" or "Data" tab
- The default namespace is usually
default_keyspaceor you can create a new one - For simplicity, you can use
default_keyspace
-
Copy the example file:
cp .env.example .env
-
Open
.envand fill in your values:# Astra DB Configuration ASTRA_DB_NAMESPACE=default_keyspace ASTRA_DB_COLLECTION=rapidclaims_docs ASTRA_DB_API_ENDPOINT=https://your-database-id-your-region.apps.astra.datastax.com ASTRA_DB_APPLICATION_TOKEN=AstraCS:your_token_here # Google Gemini API Key GEMINI_API_KEY=your_gemini_api_key_here
Important Notes:
- Replace
your-database-id-your-region.apps.astra.datastax.comwith your actual API Endpoint - Replace
AstraCS:your_token_herewith your actual Application Token - Replace
your_gemini_api_key_herewith your Gemini API key - The
ASTRA_DB_COLLECTIONname can be anything (e.g.,rapidclaims_docs)
- Replace
This will scrape the RapidClaims website and populate your vector database:
npm run seedThis script will:
- Create a collection in Astra DB (if it doesn't exist)
- Scrape
https://www.rapidclaims.ai/ - Split the content into chunks
- Generate embeddings using Gemini
- Store everything in your Astra DB collection
Note: The first run may take a few minutes depending on the website size.
npm run devOpen http://localhost:3000 in your browser.
chatbotRC/
├── app/
│ ├── api/
│ │ └── chat/
│ │ └── route.ts # API route for chat (RAG implementation)
│ ├── assets/
│ │ ├── RClogo.png # RapidClaims logo
│ │ └── chatbot_back2.jpg # Background image (if used)
│ ├── components/
│ │ ├── Bubble.tsx # Message bubble component with markdown support
│ │ ├── LoadingBubbles.tsx # Loading indicator for AI responses
│ │ ├── PromptSuggestionsButton.tsx # Individual prompt button
│ │ └── PromptSuggestionsRow.tsx # Row of prompt suggestion buttons
│ ├── global.css # Global styles and responsive design
│ ├── layout.tsx # Root layout with metadata
│ └── page.tsx # Main chat interface component
├── scripts/
│ ├── loadDB.ts # Database seeding script (scrapes website)
│ └── listModels.ts # Script to list available Gemini models
├── .env # Environment variables (create this)
├── next.config.js # Next.js configuration
├── package.json # Dependencies and scripts
└── tsconfig.json # TypeScript configuration
| Variable | Description | Where to Get It |
|---|---|---|
ASTRA_DB_NAMESPACE |
Database namespace/keyspace | Astra DB dashboard (usually default_keyspace) |
ASTRA_DB_COLLECTION |
Collection name for documents | You choose (e.g., rapidclaims_docs) |
ASTRA_DB_API_ENDPOINT |
Database API endpoint URL | Astra DB "Connect" tab |
ASTRA_DB_APPLICATION_TOKEN |
Authentication token | Astra DB "Application Tokens" |
GEMINI_API_KEY |
Google Gemini API key | Google AI Studio |
- Verify your
ASTRA_DB_API_ENDPOINTis correct (should start withhttps://) - Check that your
ASTRA_DB_APPLICATION_TOKENis complete (starts withAstraCS:) - Ensure your database is active (not paused/deleted)
- Verify your
GEMINI_API_KEYis correct - Check if you have API quota remaining in Google AI Studio
- Make sure the API key has not expired
Error: $vector value can't be empty or SHRED_BAD_VECTOR_SIZE
Cause: Your collection was created with a different vector dimension (e.g., 1024) than what Gemini's embedding-001 produces (768).
Solution:
- Go to Astra DB Dashboard
- Navigate to your database
- Go to the "Data Explorer" tab
- In the left sidebar, find your collection (e.g.,
chatrc_collection) - Click on the collection name
- Click the "Delete" or "Trash" icon to delete the collection
- Run
npm run seedagain - it will create a new collection with the correct 768 dimensions
Note: The script will automatically create a collection with 768 dimensions (matching Gemini's embedding-001 model) if it doesn't exist.
If you see "collection already exists", the script will skip creation and continue. If you want to start fresh or fix dimension issues, delete the collection as described above.
Error: routes-manifest.json not found or build cache issues
Solution:
rm -rf .next
npm run buildThis clears the build cache and regenerates all build files.
If you encounter errors when running npm run dev:
- Stop the server (Ctrl+C)
- Clean the build cache:
rm -rf .next - Restart:
npm run dev
If you see errors about unavailable models, run:
npm run list-modelsThis will show all available Gemini models in your account. The application automatically tries multiple models in sequence until one works.
npm run dev- Start development servernpm run build- Build for productionnpm run start- Start production servernpm run seed- Scrape website and populate databasenpm run seed:test- Seed database with test mode (only 3 chunks)npm run list-models- List available Gemini models in your accountnpm run lint- Run ESLint
- Framework: Next.js 15.4.10 (App Router)
- AI SDK: Vercel AI SDK v5.0.15
- AI Models: Google Gemini (auto-fallback:
gemini-2.5-flash,gemini-2.0-flash, etc.) - Vector DB: DataStax Astra DB
- Embeddings: Google Generative AI (
embedding-001- 768 dimensions) - Web Scraping: Puppeteer
- UI Libraries: React 18, React Markdown
- Language: TypeScript
- Desktop: Centered card layout with optimal spacing
- Mobile: Full-screen optimized experience with touch-friendly buttons
- Tablet: Adaptive layout that works on all screen sizes
- Streaming Responses: Real-time message streaming for better UX
- New Chat Button: Easily reset conversations and return to main menu
- Prompt Suggestions: Quick-start prompts for common questions
- Loading States: Visual feedback during AI processing
- Error Handling: User-friendly error messages with retry options
- Modern Gradient Background: RapidClaims-inspired purple-blue gradient
- Clean Message Bubbles: User messages (red) and assistant messages (white) with proper alignment
- Smooth Animations: Slide-in animations for messages
- Markdown Support: Rich text formatting in assistant responses
This project is ready for deployment on Vercel:
- Push to GitHub: Ensure your code is pushed to a GitHub repository
- Connect to Vercel: Import your repository in Vercel
- Add Environment Variables: Set all required environment variables in Vercel project settings:
ASTRA_DB_NAMESPACEASTRA_DB_COLLECTIONASTRA_DB_API_ENDPOINTASTRA_DB_APPLICATION_TOKENGEMINI_API_KEYorGOOGLE_GENERATIVE_AI_API_KEY
- Deploy: Vercel will automatically build and deploy your application
✅ Production build tested and verified ✅ All TypeScript errors resolved ✅ Mobile-responsive design implemented ✅ Optimized for performance
- ✨ Added "New Chat" button for easy conversation reset
- 🎨 Enhanced UI positioning and centering
- 📱 Improved mobile responsiveness and touch targets
- 🧹 Removed avatar prefixes ("U" and "RC") for cleaner messages
- 🔧 Fixed production build issues
- 🎯 Better message spacing and alignment
- 📐 Perfect vertical and horizontal centering
Private project for RapidClaims.