Skip to content

dnspavankumar/nice-potato

Repository files navigation

# Email RAG - AI-Powered Email Assistant A Next.js application that provides intelligent email search and chat functionality using AI. Ask questions about your emails and get instant, relevant answers powered by vector search and large language models. ## Features - 🔍 **Semantic Email Search** - Find emails by meaning, not just keywords - 💬 **AI Chat Interface** - Ask questions about your emails in natural language - 📧 **Gmail Integration** - Sync and process emails from your Gmail account - 🧠 **Vector Search** - Powered by Pinecone for fast, accurate email retrieval - 🤖 **AI Summarization** - Automatically summarize emails using Groq's LLM - 🔐 **Secure Authentication** - Google OAuth integration for secure access ## Tech Stack - **Frontend**: Next.js 15, TypeScript, Tailwind CSS - **Backend**: Next.js API Routes - **Vector Database**: Pinecone - **LLM**: Groq API - **Email**: Gmail API - **Authentication**: Google OAuth ## Prerequisites Before you begin, ensure you have the following: 1. **Node.js** (v18 or higher) 2. **npm** or **yarn** 3. **Gmail Account** with API access 4. **Pinecone Account** - [Sign up here](https://www.pinecone.io/) 5. **Groq API Key** - [Get one here](https://console.groq.com/) 6. **Google Cloud Project** with Gmail API enabled ## Setup Instructions ### 1. Clone the Repository ```bash git clone cd emailrag ``` ### 2. Install Dependencies ```bash npm install ``` ### 3. Environment Configuration Create a `.env.local` file in the root directory: ```env # Database DATABASE_URL="postgresql://username:password@localhost:5432/emailrag" # Pinecone PINECONE_API_KEY="your_pinecone_api_key" PINECONE_ENVIRONMENT="your_pinecone_environment" PINECONE_INDEX_NAME="emailrag-index" # Google OAuth GOOGLE_CLIENT_ID="your_google_client_id" GOOGLE_CLIENT_SECRET="your_google_client_secret" NEXTAUTH_URL="http://localhost:3000" NEXTAUTH_SECRET="your_nextauth_secret" # Groq API GROQ_API_KEY="your_groq_api_key" # Gmail API GMAIL_CLIENT_ID="your_gmail_client_id" GMAIL_CLIENT_SECRET="your_gmail_client_secret" GMAIL_REDIRECT_URI="http://localhost:3000/api/auth/callback/google" ``` ### 4. Configure External Services #### Pinecone Setup 1. Create a Pinecone account at [pinecone.io](https://www.pinecone.io/) 2. Create a new project and get your API key 3. Set the environment variables in `.env.local` #### Groq API Setup 1. Sign up at [console.groq.com](https://console.groq.com/) 2. Generate an API key 3. Add the key to your `.env.local` file #### Google Cloud Setup 1. Go to [Google Cloud Console](https://console.cloud.google.com/) 2. Create a new project or select existing one 3. Enable the Gmail API 4. Create OAuth 2.0 credentials 5. Add authorized redirect URIs: - `http://localhost:3000/api/auth/callback/google` - `https://yourdomain.com/api/auth/callback/google` (for production) ### 5. Run the Application ```bash npm run dev ``` Open [http://localhost:3000](http://localhost:3000) to see the application. ## Usage ### 1. Connect Gmail - Click "Sync Emails" to authenticate with Gmail - Grant necessary permissions for email access ### 2. Sync Emails - The application will automatically fetch and process your emails - Emails are summarized and indexed for vector search ### 3. Chat with Your Emails - Use the Chat tab to ask questions about your emails - The AI will search through your email content and provide relevant answers ### 4. Search Emails - Use the Search tab for semantic email search - Find emails by meaning, not just keywords ## API Endpoints - `POST /api/emails/sync` - Sync emails from Gmail - `POST /api/chat` - Chat with your emails - `POST /api/emails/search` - Search emails semantically ## Development ### Project Structure ``` src/ ├── app/ │ ├── api/ # API routes │ ├── globals.css # Global styles │ ├── layout.tsx # Root layout │ └── page.tsx # Home page ├── lib/ # Utility functions │ ├── config.ts # Configuration │ ├── gmail.ts # Gmail API integration │ ├── groq.ts # Groq API integration │ ├── pinecone.ts # Pinecone integration │ └── vector-search.ts # Vector search logic └── types/ # TypeScript types └── index.ts ``` ### Key Components - **GmailService**: Handles Gmail API integration - **GroqService**: Manages LLM interactions - **VectorSearchService**: Handles vector operations - **Pinecone Integration**: Vector database operations ## Deployment ### Vercel (Recommended) 1. Push your code to GitHub 2. Connect your repository to Vercel 3. Add environment variables in Vercel dashboard 4. Deploy ### Other Platforms The application can be deployed to any platform that supports Next.js: - Netlify - AWS Amplify - Railway - DigitalOcean App Platform ## Security Considerations - All API keys are stored securely in environment variables - Gmail access is read-only - User data is processed locally and not stored permanently - Vector embeddings are stored in Pinecone with proper access controls ## Troubleshooting ### Common Issues 1. **Gmail API Quota Exceeded** - Check your Gmail API quota in Google Cloud Console - Implement rate limiting for large email syncs 2. **Pinecone Index Not Found** - Ensure the index name matches your configuration - Check if the index exists in your Pinecone dashboard 3. **Groq API Errors** - Verify your API key is correct - Check your Groq API usage limits ## Contributing 1. Fork the repository 2. Create a feature branch 3. Make your changes 4. Add tests if applicable 5. Submit a pull request ## License This project is licensed under the MIT License. ## Support For support, please open an issue in the GitHub repository or contact the development team.# nice-potato

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published