Transform your academic textbooks into an intelligent AI tutor using advanced RAG (Retrieval Augmented Generation) technology
Academic RAG Assistant is an intelligent tutoring system that transforms your course textbooks into an interactive AI conversation partner. Using advanced agentic RAG architecture, it provides contextual answers from your specific academic materials across multiple subjects including Linear Algebra, Discrete Structures, and Calculus & Analytical Geometry.
- π Multi-Subject Expertise: Specialized tools for Linear Algebra, Discrete Structures, and Calculus & Analytical Geometry
- π€ Agentic RAG System: Intelligent query enhancement and routing for optimal retrieval
- π Real-time Streaming: Live response generation with visual typing indicators
- π± Modern UI: Clean, responsive dark-themed interface with custom styling
- πΎ Session Management: Persistent chat history with export functionality
- ποΈ Model Selection: Support for multiple Google Gemini models (2.5 Pro, Flash, 2.0 Flash, etc.)
- π‘οΈ Error Handling: Comprehensive error management with user-friendly messages
- π Progress Tracking: Visual feedback during initialization and processing
- π Smart Retrieval: MMR and multi-query retrieval strategies for better context
- π§ Memory System: SQLite-based conversation persistence
- Frontend: Streamlit with custom CSS styling
- Backend: Python with asyncio for concurrent operations
- AI Framework: OpenAI Agents SDK for agentic behavior
- LLM Integration: Google Gemini via OpenAI-compatible API
- Vector Database: Pinecone for document storage and retrieval
- Embeddings: HuggingFace Sentence Transformers (all-MiniLM-L6-v2)
- Text Processing: LangChain framework for RAG implementation
- Memory: SQLite for session and conversation management
- Python 3.12 or higher
- Google Gemini API Key (Get one here)
- Pinecone API Key (Get one here)
- Pre-processed textbook data in Pinecone vector store
git clone https://github.com/ZohaibCodez/academic-rag-assistant.git
cd academic-rag-assistant# Using pip
pip install -r requirements.txt
# Using uv (recommended)
uv sync# Create .env file
cp .env.example .env
# Edit .env with your API keysstreamlit run app.pyOpen your browser and navigate to http://localhost:8501
Create a .env file in the root directory:
GOOGLE_API_KEY=your_google_gemini_api_key_here
PINECONE_API_KEY=your_pinecone_api_key_heregemini-2.5-pro(Most capable, recommended for complex analysis)gemini-2.5-flash(Balanced performance and speed)gemini-2.5-flash-lite(Lightweight and fast)gemini-2.0-flash(Fast responses with good accuracy)gemini-1.5-pro(Reliable baseline model)gemini-1.5-flash(Quick processing)
CHUNK_OVERLAP = 100 # Text chunk overlap for context
RETRIEVER_K_MMR = 2 # MMR retrieval count
RETRIEVER_K_SIMILARITY = 5 # Similarity search count
LAMBDA_MUL = 0.7 # MMR diversity parameter
EMBEDDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"- Enter API Keys: Add your Google Gemini and Pinecone API keys in the sidebar
- Select Model: Choose your preferred Gemini model from the dropdown
- Start Learning: Ask questions about your coursework in natural language
- View Subjects: Check available subjects in the "Subjects" tab
- Export History: Download your conversation anytime from the "Info" tab
- Matrix operations and properties
- Systems of linear equations (Gaussian elimination, substitution)
- Eigenvalues and eigenvectors
- Vector spaces and transformations
- Determinants and matrix inverses
- Mathematical logic and proof techniques
- Set theory and relations
- Graph theory and trees
- Combinatorics and counting principles
- Boolean algebra and functions
- Limits and continuity
- Differentiation techniques and applications
- Integration methods and applications
- Analytical geometry in 2D and 3D
- Sequences and series
- "Explain the steps to solve a system of linear equations using Gaussian elimination"
- "What is mathematical induction and how do I write a proof?"
- "How do you find the derivative of a composite function using chain rule?"
- "What are eigenvalues and eigenvectors? Provide examples"
- "Explain the fundamental theorem of calculus with applications"
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β User Query βββββΆβ Query Enhancer βββββΆβ Subject Router β
β (Natural) β β (Agent System) β β (Classification)β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Streamlit UI ββββββ Agent Runner ββββββ Function Tools β
β (Frontend) β β (Orchestrator) β β (Subject RAG) β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Session Store β β Gemini Models β β Pinecone Vector β
β (SQLite) β β (Generation AI) β β Database β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
βββββββββββββββββββ
β HuggingFace β
β Embeddings β
βββββββββββββββββββ
# Create .env file with your API keys
echo "GOOGLE_API_KEY=your-gemini-key-here" >> .env
echo "PINECONE_API_KEY=your-pinecone-key-here" >> .env
# Build and run
docker build -t academic-rag-assistant .
docker run -p 8501:8501 --env-file .env academic-rag-assistantacademic-rag-assistant/
β
βββ app.py # Main Streamlit application
β
βββ notebooks/
β βββ data_preparation_pipeline.ipynb # Complete RAG pipeline setup
β βββ Step 1a β Multi-Document Ingestion
β βββ Step 1b β Subject-Aware Text Splitting
β βββ Step 2 β Retrieval System Setup
β βββ Step 3 β Tool Definitions
β βββ Agentic RAG Final Form
β
βββ logs/ # Application logs directory
βββ Dockerfile # Container configuration
βββ requirements.txt # Python dependencies
βββ pyproject.toml # Project configuration
βββ uv.lock # UV dependency lock
βββ .env.example # Example environment variables
βββ .gitignore # Git ignore rules
βββ README.md # Project documentation
- Query Processing: ~1-3 seconds for typical academic queries
- Memory Usage: Optimized vector storage with Pinecone
- Retrieval Accuracy: High precision with multi-strategy retrieval
- Response Quality: Enhanced by agentic query reformulation
- Concurrent Users: Supports multiple simultaneous sessions
- Streaming Speed: Real-time response generation with 0.05s intervals
- Subject Scope: Limited to three core subjects (Linear Algebra, Discrete Structures, Calculus)
- Language: Optimized for English academic content
- Data Dependency: Requires pre-processed textbooks in Pinecone
- API Limits: Subject to Google Gemini and Pinecone rate limits
- Context Window: Limited by model context length for very long documents
The included Jupyter notebook (data_preparation_pipeline.ipynb) provides a complete walkthrough:
- PDF text extraction and processing
- Document metadata handling
- Quality validation and cleanup
- Intelligent chunking based on academic structure
- Subject-specific namespace organization
- Context preservation across chunks
- Vector store initialization with Pinecone
- Embedding model configuration
- Index creation and optimization
- Subject-specific RAG function tools
- Query enhancement and routing logic
- Response formatting and validation
- Complete agent system integration
- Testing and validation procedures
- Performance optimization techniques
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Install development dependencies (
uv sync) - Make your changes with comprehensive logging
- Test across multiple Gemini models
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow PEP 8 style guidelines
- Add comprehensive logging for new features
- Include error handling for all external API calls
- Update documentation for new functionality
- Test with multiple subjects and query types
- Support for additional subjects (Physics, Chemistry, Statistics)
- Multi-language academic content support
- Advanced visualization tools for mathematical concepts
- Integration with learning management systems
- Collaborative study session features
- Custom textbook upload and processing
- Mobile-responsive design improvements
- Voice interaction capabilities
- Progress tracking and learning analytics
- API endpoint for programmatic access
- Large textbook corpora may require extended initialization time
- Complex mathematical notation may not render perfectly
- API rate limiting may affect performance during peak usage
- Memory usage can be high with multiple concurrent users
"Agent initialization failed" error:
- Verify both Google Gemini and Pinecone API keys are valid
- Check internet connectivity and API service status
- Ensure sufficient API quota remaining
"Vector store connection failed":
- Confirm Pinecone API key and index configuration
- Verify the "semester-books" index exists with correct namespaces
- Check Pinecone service status and regional settings
Slow response times:
- Try switching to gemini-2.5-flash for faster responses
- Check your network connection stability
- Consider using a different model if quota limits are reached
Memory errors:
- Restart the Streamlit application
- Clear browser cache and session storage
- For Docker: increase memory allocation limits
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
- OpenAI Agents SDK for the agentic framework
- Streamlit for the incredible web framework
- LangChain for comprehensive RAG implementation
- Google AI for Gemini API access
- Pinecone for scalable vector database services
- HuggingFace for open-source embedding models
- Academic community for inspiration and feedback
If you encounter any issues or have questions:
- Open an Issue
- Check existing issues for solutions
- Review the troubleshooting section above
- Contact: itxlevicodez@gmail.com
β Star this repository if you found it helpful for your academic journey!
Built with π€ for students by @ZohaibCodez using Google Gemini AI and advanced RAG techniques