Skip to content

KodeCharya/gemini-RAG-chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 AI Assistant with RAG (Retrieval-Augmented Generation)

A powerful Streamlit chatbot that combines Google's Gemini API with RAG capabilities to provide intelligent responses based on your uploaded content. Supports multimodal inputs including text, images, audio, video, and web content.

✨ Features

📁 File Processing

  • Documents: PDF, Word (.docx), text files
  • Images: JPG, PNG, GIF, WebP with AI vision analysis
  • Audio: MP3, WAV, M4A with automatic transcription
  • Video: MP4, AVI, MOV with audio extraction and transcription
  • Web Content: Extract content from any webpage
  • YouTube: Automatic transcript extraction from YouTube videos

🧠 AI Capabilities

  • Multimodal Chat: Text + image queries using Gemini Vision
  • RAG System: Intelligent context retrieval from your knowledge base
  • Semantic Search: Find relevant information across all uploaded content
  • Chat Memory: Persistent conversation history
  • Source Attribution: See which documents informed each response

🗄️ Vector Storage Options

  • ChromaDB: Local vector database (default)
  • Pinecone: Cloud vector database (optional, requires API key)

🚀 Quick Start

1. Installation

# Clone the repository
git clone <repository-url>
cd streamlit-gemini-rag-chatbot

# Install dependencies
pip install -r requirements.txt

2. Configuration

# Copy the environment template
cp .env.example .env

# Edit .env and add your API keys
GOOGLE_API_KEY=your_gemini_api_key_here
PINECONE_API_KEY=your_pinecone_api_key_here  # Optional
PINECONE_ENVIRONMENT=your_pinecone_environment_here  # Optional

3. Get API Keys

Required: Google Gemini API

  1. Go to Google AI Studio
  2. Create a new API key
  3. Add it to your .env file

Optional: Pinecone API

  1. Sign up at Pinecone
  2. Create a new project and get your API key
  3. Add it to your .env file

4. Run the Application

streamlit run app.py

📖 How to Use

Upload Content

  1. Files: Use the sidebar to upload documents, images, audio, or video files
  2. Web URLs: Enter any webpage URL to extract and index its content
  3. YouTube: Paste YouTube URLs to get automatic transcripts

Chat with Your AI

  1. Ask questions about your uploaded content
  2. Upload images directly in the chat for multimodal queries
  3. Get responses with source attribution
  4. View chat history and export conversations

Example Queries

  • "Summarize the key points from the uploaded PDF"
  • "What does this image show?" (with image upload)
  • "Compare the information from different documents"
  • "What are the main topics discussed in the video?"

🏗️ Architecture

├── app.py                 # Main Streamlit application
├── config/
│   └── settings.py        # Configuration and settings
├── utils/
│   ├── gemini_client.py   # Gemini API integration
│   ├── vector_store.py    # Vector database operations
│   ├── file_processor.py  # File processing and content extraction
│   └── chat_memory.py     # Chat history management
├── components/
│   ├── sidebar.py         # Sidebar UI components
│   └── chat_interface.py  # Chat interface components
└── requirements.txt       # Python dependencies

🔧 Advanced Configuration

Vector Store Selection

  • ChromaDB (Default): Local storage, no API key required
  • Pinecone: Cloud storage, requires API key but offers better scalability

File Processing Settings

Edit config/settings.py to customize:

  • Maximum file size limits
  • Text chunking parameters
  • Supported file types
  • Embedding dimensions

RAG Parameters

  • Chunk Size: How text is split for processing
  • Top-K Retrieval: Number of relevant chunks to retrieve
  • Embedding Model: Sentence transformer model for embeddings

🛠️ Troubleshooting

Common Issues

  1. API Key Errors

    • Ensure your Gemini API key is valid and has sufficient quota
    • Check that the key is properly set in the .env file
  2. File Processing Errors

    • Large files may take time to process
    • Some video formats may require additional codecs
  3. Memory Issues

    • For large files, consider increasing chunk size
    • Use Pinecone for better scalability with large datasets

Performance Tips

  1. Optimize File Sizes: Compress large video/audio files before upload
  2. Use Specific Queries: More specific questions yield better results
  3. Regular Cleanup: Clear chat history periodically for better performance

📝 Development

Adding New File Types

  1. Update SUPPORTED_FILE_TYPES in config/settings.py
  2. Add processing logic in utils/file_processor.py
  3. Test with sample files

Custom Embedding Models

  1. Modify the generate_embeddings method in utils/gemini_client.py
  2. Update the embedding dimension in settings
  3. Rebuild your vector database

🤝 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 - see the LICENSE file for details.

🙏 Acknowledgments

  • Google Gemini API for multimodal AI capabilities
  • Streamlit for the amazing web framework
  • ChromaDB and Pinecone for vector storage solutions
  • OpenAI Whisper for audio transcription
  • All the open-source libraries that make this possible

📞 Support

If you encounter any issues or have questions:

  1. Check the troubleshooting section above
  2. Review the configuration settings
  3. Open an issue on GitHub with detailed information about your problem

Happy chatting with your AI assistant! 🚀

About

a comprehensive Streamlit chatbot with Gemini API and RAG capabilities that supports all the features

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages