clear# π€ SCADA RAG Chatbot
A production-ready Retrieval-Augmented Generation (RAG) chatbot built with Streamlit, LlamaIndex, PostgreSQL, and Ollama. This application processes PDF documents, generates embeddings, and provides intelligent question-answering capabilities based on your document corpus.
- Document Processing: Automatic PDF parsing and text extraction
- Vector Storage: PostgreSQL with pgvector for efficient similarity search
- Lightweight LLM: Ollama integration with local models
- Modern UI: Beautiful Streamlit interface with chat functionality
- Containerized: Full Docker setup with orchestration
- Production Ready: Nginx reverse proxy, health checks, and monitoring
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Streamlit β β PostgreSQL β β Ollama β
β Frontend βββββΊβ + pgvector βββββΊβ LLM Models β
β β β β β (M3 Max Opt) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β² β² β²
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Document Proc β β RAG Pipeline β β Vector Search β
β β β β β β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
- Docker and Docker Compose
- Make (optional, for easier management)
- At least 8GB RAM (for Ollama models)
- Optimized for Apple Silicon M3 Max π
- Frontend: Streamlit
- Backend: Python 3.11
- Database: PostgreSQL 16 + pgvector
- LLM: Ollama (llama3.1:8b, nomic-embed-text) - M3 Max optimized
- Framework: LlamaIndex
- Containerization: Docker + Docker Compose
- Package Manager: uv
git clone <repository-url>
cd Scada_Chatbotmake initThis will:
- Build Docker images
- Start PostgreSQL and Ollama services
- Pull required LLM models
- Set up the database schema
make up- Streamlit App: http://localhost:8501
- Ollama API: http://localhost:11434
- Place your PDF files in the
data/d_warehouse/directory - Open the Streamlit app
- Click "π Process Documents" in the sidebar
- Wait for processing to complete
- Use the chat interface to ask questions
- The system will retrieve relevant document chunks
- Responses include source citations and relevance scores
- Use suggested questions for quick starts
- Health Checks: Monitor system status
- Model Management: Pull or update Ollama models
- Document Management: View processed documents
- Chat History: Persistent conversation storage
| Command | Description |
|---|---|
make init |
Initialize the application |
make up |
Start all services |
make down |
Stop all services |
make logs |
Show application logs |
make status |
Show service status |
make models |
Pull Ollama models |
make restart |
Restart services |
make rebuild |
Rebuild and restart |
make clean |
Clean up everything |
make health |
Health check |
make info |
Show application info |
Scada_Chatbot/
βββ src/ # Source code
β βββ __init__.py
β βββ config.py # Configuration settings
β βββ database.py # Database operations
β βββ document_processor.py # PDF processing
β βββ rag_pipeline.py # RAG implementation
β βββ streamlit_app.py # Main application
βββ data/
β βββ d_warehouse/ # Source PDF files
β βββ d_mart/ # Processed embeddings
βββ docker-compose.yml # Docker orchestration
βββ Dockerfile # Application container
βββ Makefile # Easy management commands
βββ init-db.sql # Database initialization
βββ pyproject.toml # Python dependencies
βββ README.md # This file
The application supports configuration via environment variables:
# Database Settings
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=scada_chatbot
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
# Ollama Settings
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_MODEL=llama3.1:8b
OLLAMA_EMBEDDING_MODEL=nomic-embed-text
# Application Settings
CHUNK_SIZE=1000
CHUNK_OVERLAP=200
MAX_TOKENS=4000
TEMPERATURE=0.7To use different Ollama models, update the configuration:
# In src/config.py
OLLAMA_MODEL = "llama3.1:70b" # Larger model
OLLAMA_EMBEDDING_MODEL = "all-minilm" # Different embedding model- Image:
pgvector/pgvector:pg16 - Port: 5432
- Features: Vector similarity search, JSONB support
- Image:
ollama/ollama:latest - Port: 11434
- Models: llama3.1:8b, nomic-embed-text
- Optimization: Native Apple Silicon support
- Build: Custom Python 3.11 image
- Port: 8501
- Features: Chat interface, document processing
- Streamlit:
http://localhost:8501/_stcore/health - PostgreSQL: Built-in health checks
- Ollama:
http://localhost:11434/api/tags
- Application logs:
docker-compose logs -f app - Database logs:
docker-compose logs -f postgres - Ollama logs:
docker-compose logs -f ollama
- Non-root container execution
- Environment variable configuration
- Network isolation
- Resource limits
- Health check timeouts
-
Ollama Models Not Found
make models # Pull required models -
Database Connection Issues
make status # Check service status make logs-postgres # Check database logs
-
Memory Issues
# Increase Docker memory limit to 8GB+ # Use smaller models: llama3.1:8b instead of 70b
-
Port Conflicts
# Modify ports in docker-compose.yml # Default ports: 8501 (Streamlit), 5432 (PostgreSQL), 11434 (Ollama)
- Apple Silicon M3 Max: Native performance with optimized models
- Memory: Allocate sufficient RAM for models (8GB+ recommended)
- Storage: Use SSD for database and vector storage
- Network: Ensure stable connection for model downloads
- Document Processing: ~15-30 PDFs/minute (M3 Max acceleration)
- Query Response: 1-5 seconds (Apple Silicon optimization)
- Embedding Generation: ~150 chunks/minute (native ARM64)
- Database Operations: Sub-second similarity search
# Start only database and Ollama
make dev-up
# Install dependencies
uv pip install -r pyproject.toml
# Run locally
streamlit run src/streamlit_app.py# Run health checks
make health
# Test individual components
python -m pytest tests/- Multiple Streamlit instances behind load balancer
- Database read replicas
- Ollama model sharding
- Larger models (70B parameters) - M3 Max handles efficiently
- More unified memory (M3 Max advantage)
- Increased database resources
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License. See LICENSE file for details.
For issues and questions:
- Check the troubleshooting section
- Review application logs
- Open an issue on GitHub
- Contact the development team
- Multi-language support
- Advanced analytics dashboard
- API endpoints for external integration
- Enhanced security features
- Performance optimizations
- Cloud deployment guides
Happy Chatting! π