A production-ready Retrieval-Augmented Generation (RAG) agent built with LangGraph, ChromaDB, and Streamlit. This system enables intelligent Q&A interactions with PDF documents through a modern web interface.
- π Intelligent Document Retrieval: ChromaDB vector database for semantic document search
- π§ Advanced AI: Powered by Google Gemini 2.0 Flash for high-quality responses
- β‘ LangGraph Workflow: Structured RAG pipeline with retrieve β generate workflow
- π¨ Modern UI: Dark-themed Streamlit interface with custom styling
- π‘οΈ Production Security: API key validation, rate limiting, and error handling
- πΎ Persistent Storage: Automatic vector database persistence and reuse
- π§ͺ Comprehensive Testing: Full test suite with unit, integration, and performance tests
- βοΈ CI/CD Ready: GitHub Actions workflow for automated testing and deployment
βββββββββββββββββββ ββββββββββββββββ βββββββββββββββββββ
β Streamlit βββββΆβ RAG Agent βββββΆβ ChromaDB β
β Frontend β β (LangGraph) β β Vector Store β
βββββββββββββββββββ ββββββββββββββββ βββββββββββββββββββ
β β β
β βΌ β
β ββββββββββββββββ β
ββββββββββββββββ Google Geminiβββββββββββββββββ
β 2.0 Flash β
ββββββββββββββββ
rag_agent/
βββ src/
β βββ agent/
β β βββ __init__.py
β β βββ agent_core.py # Core RAG logic with LangGraph
β βββ utils/
β βββ __init__.py
β βββ load_db.py # Vector database setup
β βββ security.py # API key validation
β βββ rate_limit.py # Request rate limiting
βββ tests/
β βββ conftest.py # Test fixtures and configuration
β βββ test_agent_core.py # Agent functionality tests
β βββ test_integration.py # End-to-end tests
β βββ test_streamlit_app.py # UI component tests
βββ .streamlit/
β βββ config.toml # Streamlit theming
β βββ secrets.toml.example # Environment variables template
βββ .github/
β βββ workflows/ # CI/CD configuration
βββ resources/
β βββ *.pdf # Sample documents
βββ streamlit_app.py # Main Streamlit application
βββ requirements.txt # Production dependencies
βββ pyproject.toml # Development configuration
- Python 3.9+
- Google AI API Key (Get it here)
-
Clone the repository
git clone https://github.com/CJRockball/rag_agent.git cd rag_agent -
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
# Copy the example secrets file cp .streamlit/secrets.toml.example .streamlit/secrets.toml # Edit with your configuration nano .streamlit/secrets.toml
Add your configuration:
GOOGLE_API_KEY = "your-google-api-key-here" CHROMA_DB_PATH = "src/utils/vectorstore/db_chroma" COLLECTION_NAME = "v_db" DOC_PATH = "resources/your-document.pdf"
-
Run the application
streamlit run streamlit_app.py
- Launch the Streamlit app
- The system automatically indexes your PDF documents
- Ask questions in natural language
- Get AI-powered answers with source context
from src.agent.agent_core import ask_rag_with_connection
from src.utils.load_db import setup_vector_database
# Initialize database
db = setup_vector_database(
doc_path="path/to/document.pdf",
db_path="vectorstore/db_chroma",
collection_name="documents"
)
# Ask questions
response = ask_rag_with_connection("What is the main topic?", db)
print(response)The project includes comprehensive testing with 90%+ coverage:
# All tests
pytest tests/
# Unit tests only
pytest tests/ -m unit
# Integration tests
pytest tests/ -m integration
# With coverage report
pytest tests/ --cov=. --cov-report=html- Unit Tests: Individual component testing with mocking
- Integration Tests: End-to-end pipeline validation
- Performance Tests: Response time and memory usage
- Error Handling: Resilience under failure conditions
| Variable | Description | Default |
|---|---|---|
GOOGLE_API_KEY |
Google AI API key | Required |
CHROMA_DB_PATH |
Vector database path | src/utils/vectorstore/db_chroma |
COLLECTION_NAME |
ChromaDB collection name | v_db |
DOC_PATH |
Path to PDF document | resources/document.pdf |
Built-in rate limiting prevents API abuse:
- 10 requests per minute per session
- 0.1 requests/second to LLM (Gemini free tier)
- Automatic backoff and retry logic
- Theming: Modify
.streamlit/config.tomlfor UI customization - Chunking: Adjust
chunk_sizeandchunk_overlapinload_db.py - Retrieval: Change
kparameter inagent_core.pyfor more/fewer results
# Install development dependencies
pip install -r dev-requirements.txt
# Install pre-commit hooks
pre-commit install
# Run code formatting
black src/ tests/- Implement feature with proper typing
- Add comprehensive tests
- Update documentation
- Ensure CI/CD passes
- Black: Code formatting
- pytest: Testing framework
- pre-commit: Git hooks for quality checks
- Type hints: Full typing support
- Fork this repository
- Connect to Streamlit Cloud
- Add secrets in deployment settings
- Deploy automatically
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 8501
CMD ["streamlit", "run", "streamlit_app.py"]- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes with tests
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow existing code style and patterns
- Add tests for new functionality
- Update documentation as needed
- Ensure all CI/CD checks pass
streamlit: Web interface frameworklangchain-core: LangChain core componentslangchain-google-genai: Google AI integrationlangchain-chroma: ChromaDB vector storelanggraph: Agent workflow orchestrationpypdf: PDF document processing
pytest: Testing frameworkpytest-cov: Coverage reportingblack: Code formattingpre-commit: Git hooks
"API key not found"
- Ensure
GOOGLE_API_KEYis set in.streamlit/secrets.toml - Verify the API key format starts with "AIza"
"Database connection failed"
- Check
CHROMA_DB_PATHpermissions - Ensure sufficient disk space for vector database
"Rate limit exceeded"
- Wait 60 seconds for rate limit reset
- Check Gemini API quotas in Google AI Studio
"Module import errors"
- Verify all dependencies installed:
pip install -r requirements.txt - Check Python path:
export PYTHONPATH=$PYTHONPATH:$(pwd)
This project is licensed under the MIT License - see the LICENSE file for details.
- LangChain for the RAG framework
- Google AI for Gemini API and embeddings
- ChromaDB for vector database capabilities
- Streamlit for the interactive web interface
For issues and questions:
- Open an Issue
- Check the Documentation
- Review existing Discussions
Built with β€οΈ for intelligent document interaction