Spaces:
Sleeping
Sleeping
Commit
Β·
5ddccf5
1
Parent(s):
f7f56cb
Update README with comprehensive project documentation
Browse files
README.md
CHANGED
|
@@ -1,67 +1,287 @@
|
|
| 1 |
# IoT Sensor Data RAG for Smart Buildings
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
-
|
| 6 |
-
- Real-time sensor streaming (CSV simulation) with anomaly detection
|
| 7 |
-
- Document ingestion: PDFs/TXT of maintenance manuals and building specs
|
| 8 |
-
- Vector retrieval (ChromaDB) with Sentence-Transformers embeddings
|
| 9 |
-
- Context-aware generation via local Transformers or OpenAI (optional)
|
| 10 |
-
- Predictive maintenance heuristics + efficiency recommendations
|
| 11 |
-
- Evaluation tab (basic retrieval quality and latency)
|
| 12 |
|
| 13 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
### 1) Setup
|
| 16 |
```bash
|
| 17 |
-
#
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
| 19 |
python -m venv .venv
|
| 20 |
-
.
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
pip install -r requirements.txt
|
| 23 |
```
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
```
|
| 29 |
|
| 30 |
-
###
|
| 31 |
-
- Place PDFs/TXT in `data/manuals` and `data/specs`.
|
| 32 |
-
- Sensor CSVs (with timestamps) in `data/sensors` (sample provided).
|
| 33 |
|
| 34 |
-
### 3) Run locally
|
| 35 |
```bash
|
| 36 |
streamlit run app.py
|
| 37 |
```
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
```
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
```
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
|
| 67 |
-
MIT
|
|
|
|
| 1 |
# IoT Sensor Data RAG for Smart Buildings
|
| 2 |
|
| 3 |
+
## π’ Problem Statement
|
| 4 |
|
| 5 |
+
Create a RAG system that processes IoT sensor data, maintenance manuals, and building specifications to provide predictive maintenance insights and operational optimization.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
## π― Key Requirements
|
| 8 |
+
|
| 9 |
+
- β
**IoT sensor data ingestion and real-time processing**
|
| 10 |
+
- β
**Maintenance manual and building specification integration**
|
| 11 |
+
- β
**Predictive maintenance algorithm implementation**
|
| 12 |
+
- β
**Operational efficiency optimization recommendations**
|
| 13 |
+
- β
**Anomaly detection and alert systems**
|
| 14 |
+
|
| 15 |
+
## π Technical Challenges Solved
|
| 16 |
+
|
| 17 |
+
- β
**Real-time sensor data streaming and processing**
|
| 18 |
+
- β
**Multi-sensor data fusion and correlation**
|
| 19 |
+
- β
**Predictive modeling for equipment failure**
|
| 20 |
+
- β
**Building system integration and compatibility**
|
| 21 |
+
- β
**Energy efficiency optimization algorithms**
|
| 22 |
+
|
| 23 |
+
## ποΈ System Architecture
|
| 24 |
+
|
| 25 |
+
### Core Components
|
| 26 |
+
- **RAG Engine**: Vector database (ChromaDB) with Sentence-Transformers embeddings
|
| 27 |
+
- **IoT Data Processor**: Real-time sensor data streaming and anomaly detection
|
| 28 |
+
- **Predictive Analytics**: Equipment failure prediction and maintenance recommendations
|
| 29 |
+
- **Document Intelligence**: PDF/TXT processing with smart chunking strategies
|
| 30 |
+
- **Web Interface**: Modern Streamlit dashboard with Material design theme
|
| 31 |
+
|
| 32 |
+
### Technology Stack
|
| 33 |
+
- **Backend**: Python, Streamlit, ChromaDB
|
| 34 |
+
- **Embeddings**: Sentence-Transformers (all-MiniLM-L6-v2)
|
| 35 |
+
- **Vector Database**: ChromaDB with cosine similarity
|
| 36 |
+
- **LLM Integration**: Local Transformers + OpenAI API (optional)
|
| 37 |
+
- **Data Processing**: Pandas, NumPy, Scikit-learn
|
| 38 |
+
- **Visualization**: Plotly for real-time sensor monitoring
|
| 39 |
+
|
| 40 |
+
## π Features
|
| 41 |
+
|
| 42 |
+
### 1. Real-Time IoT Monitoring
|
| 43 |
+
- Live sensor data streaming simulation
|
| 44 |
+
- Multi-sensor data fusion (temperature, humidity, power consumption)
|
| 45 |
+
- Real-time anomaly detection using rolling z-score analysis
|
| 46 |
+
- Interactive time-series visualizations
|
| 47 |
+
|
| 48 |
+
### 2. Intelligent Document RAG
|
| 49 |
+
- PDF and TXT document ingestion
|
| 50 |
+
- Smart text chunking (500 tokens with 50 token overlap)
|
| 51 |
+
- Context-aware retrieval using vector similarity
|
| 52 |
+
- Source attribution and relevance scoring
|
| 53 |
+
|
| 54 |
+
### 3. Predictive Maintenance
|
| 55 |
+
- Equipment failure prediction algorithms
|
| 56 |
+
- Maintenance schedule optimization
|
| 57 |
+
- Energy efficiency recommendations
|
| 58 |
+
- Anomaly-based alert systems
|
| 59 |
+
|
| 60 |
+
### 4. Evaluation & Analytics
|
| 61 |
+
- Retrieval accuracy metrics
|
| 62 |
+
- Response latency measurement
|
| 63 |
+
- Document relevance scoring
|
| 64 |
+
- System performance monitoring
|
| 65 |
+
|
| 66 |
+
## π Quick Start
|
| 67 |
+
|
| 68 |
+
### Prerequisites
|
| 69 |
+
- Python 3.8+
|
| 70 |
+
- 8GB+ RAM (for local LLM models)
|
| 71 |
+
- Internet connection (for initial model downloads)
|
| 72 |
+
|
| 73 |
+
### Installation
|
| 74 |
|
|
|
|
| 75 |
```bash
|
| 76 |
+
# Clone the repository
|
| 77 |
+
git clone https://github.com/itsnewcoder/iot-smart-building-rag.git
|
| 78 |
+
cd iot-smart-building-rag
|
| 79 |
+
|
| 80 |
+
# Create virtual environment
|
| 81 |
python -m venv .venv
|
| 82 |
+
.venv\Scripts\activate # Windows
|
| 83 |
+
# source .venv/bin/activate # Linux/Mac
|
| 84 |
+
|
| 85 |
+
# Install dependencies
|
| 86 |
pip install -r requirements.txt
|
| 87 |
```
|
| 88 |
|
| 89 |
+
### Configuration
|
| 90 |
+
|
| 91 |
+
Create a `.env` file in the root directory (optional):
|
| 92 |
+
```env
|
| 93 |
+
OPENAI_API_KEY=your_openai_api_key_here
|
| 94 |
```
|
| 95 |
|
| 96 |
+
### Run Locally
|
|
|
|
|
|
|
| 97 |
|
|
|
|
| 98 |
```bash
|
| 99 |
streamlit run app.py
|
| 100 |
```
|
| 101 |
|
| 102 |
+
**Access your app at:** `http://localhost:8501`
|
| 103 |
+
|
| 104 |
+
## π Project Structure
|
| 105 |
+
|
| 106 |
+
```
|
| 107 |
+
iot-smart-building-rag/
|
| 108 |
+
βββ app.py # Main Streamlit application
|
| 109 |
+
βββ requirements.txt # Python dependencies
|
| 110 |
+
βββ README.md # This file
|
| 111 |
+
βββ .streamlit/
|
| 112 |
+
β βββ config.toml # Streamlit theme configuration
|
| 113 |
+
βββ rag/ # RAG system core
|
| 114 |
+
β βββ __init__.py
|
| 115 |
+
β βββ ingest.py # Document ingestion & vector store
|
| 116 |
+
β βββ retrieval.py # Context retrieval engine
|
| 117 |
+
β βββ generate.py # LLM response generation
|
| 118 |
+
β βββ evaluate.py # System evaluation metrics
|
| 119 |
+
βββ models/ # Predictive models
|
| 120 |
+
β βββ __init__.py
|
| 121 |
+
β βββ predictive.py # Anomaly detection & maintenance
|
| 122 |
+
βββ data/ # Sample data
|
| 123 |
+
β βββ manuals/ # Maintenance manuals (PDF/TXT)
|
| 124 |
+
β βββ specs/ # Building specifications
|
| 125 |
+
β βββ sensors/ # IoT sensor data (CSV)
|
| 126 |
+
βββ .chroma/ # Vector database storage
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+
## π§ Usage Guide
|
| 130 |
+
|
| 131 |
+
### 1. Dashboard Tab
|
| 132 |
+
- **Start Stream**: Begin real-time sensor data simulation
|
| 133 |
+
- **Live Monitoring**: View real-time sensor readings and trends
|
| 134 |
+
- **Anomaly Detection**: See detected anomalies with z-score analysis
|
| 135 |
+
- **Maintenance Tips**: Get AI-powered maintenance recommendations
|
| 136 |
+
|
| 137 |
+
### 2. RAG QA Tab
|
| 138 |
+
- **Ask Questions**: Query maintenance procedures and building specs
|
| 139 |
+
- **Context Retrieval**: View relevant document chunks and sources
|
| 140 |
+
- **AI Responses**: Get context-aware answers from local or OpenAI models
|
| 141 |
+
|
| 142 |
+
### 3. Evaluation Tab
|
| 143 |
+
- **Retrieval Testing**: Test system with custom queries
|
| 144 |
+
- **Performance Metrics**: View latency and relevance scores
|
| 145 |
+
- **Quality Assessment**: Evaluate RAG system effectiveness
|
| 146 |
+
|
| 147 |
+
### 4. Data Manager Tab
|
| 148 |
+
- **Document Index**: View indexed documents and sources
|
| 149 |
+
- **File Upload**: Add new PDFs/TXTs to the knowledge base
|
| 150 |
+
- **Vector Store**: Manage document embeddings and storage
|
| 151 |
+
|
| 152 |
+
## π Sample Queries
|
| 153 |
+
|
| 154 |
+
Try these example questions in the RAG QA tab:
|
| 155 |
+
|
| 156 |
+
- "How to reset chiller pump?"
|
| 157 |
+
- "What are the fault codes for HVAC systems?"
|
| 158 |
+
- "How to maintain building temperature sensors?"
|
| 159 |
+
- "What are the power consumption optimization tips?"
|
| 160 |
+
- "How to troubleshoot humidity sensor issues?"
|
| 161 |
+
|
| 162 |
+
## π― Evaluation Metrics
|
| 163 |
|
| 164 |
+
### Retrieval Quality
|
| 165 |
+
- **Relevance Scoring**: Cosine similarity-based ranking
|
| 166 |
+
- **Source Attribution**: Document source tracking
|
| 167 |
+
- **Context Retrieval**: Top-k document retrieval
|
| 168 |
+
|
| 169 |
+
### Performance Metrics
|
| 170 |
+
- **Response Latency**: End-to-end query processing time
|
| 171 |
+
- **Throughput**: Queries processed per second
|
| 172 |
+
- **Memory Usage**: Vector database storage efficiency
|
| 173 |
+
|
| 174 |
+
### RAG Effectiveness
|
| 175 |
+
- **Context Relevance**: Retrieved document quality
|
| 176 |
+
- **Answer Accuracy**: Response relevance to queries
|
| 177 |
+
- **Source Diversity**: Multiple document source utilization
|
| 178 |
+
|
| 179 |
+
## π Deployment
|
| 180 |
+
|
| 181 |
+
### HuggingFace Spaces (Recommended)
|
| 182 |
+
1. Create new Space at [huggingface.co/spaces](https://huggingface.co/spaces)
|
| 183 |
+
2. Choose **Streamlit** as SDK
|
| 184 |
+
3. Upload project files
|
| 185 |
+
4. Set environment variables in Space settings
|
| 186 |
+
|
| 187 |
+
### Streamlit Cloud
|
| 188 |
+
1. Push code to GitHub
|
| 189 |
+
2. Connect repository at [share.streamlit.io](https://share.streamlit.io)
|
| 190 |
+
3. Deploy automatically
|
| 191 |
+
|
| 192 |
+
### Local Deployment
|
| 193 |
+
```bash
|
| 194 |
+
# Production server
|
| 195 |
+
streamlit run app.py --server.port 8501 --server.address 0.0.0.0
|
| 196 |
```
|
| 197 |
+
|
| 198 |
+
## π Technical Implementation Details
|
| 199 |
+
|
| 200 |
+
### Embedding Strategy
|
| 201 |
+
- **Model**: `sentence-transformers/all-MiniLM-L6-v2`
|
| 202 |
+
- **Dimensions**: 384
|
| 203 |
+
- **Normalization**: L2 normalization for cosine similarity
|
| 204 |
+
- **Chunking**: 500 tokens with 50 token overlap
|
| 205 |
+
|
| 206 |
+
### Vector Database
|
| 207 |
+
- **Database**: ChromaDB
|
| 208 |
+
- **Similarity**: Cosine distance
|
| 209 |
+
- **Persistence**: Local file storage (.chroma directory)
|
| 210 |
+
- **Indexing**: HNSW algorithm for fast retrieval
|
| 211 |
+
|
| 212 |
+
### Anomaly Detection
|
| 213 |
+
- **Method**: Rolling z-score analysis
|
| 214 |
+
- **Window Size**: 50 data points
|
| 215 |
+
- **Threshold**: Z-score > 3.0
|
| 216 |
+
- **Metrics**: Temperature, humidity, power consumption
|
| 217 |
+
|
| 218 |
+
### Predictive Maintenance
|
| 219 |
+
- **Algorithm**: Rule-based heuristics + statistical analysis
|
| 220 |
+
- **Input**: Sensor data + anomaly patterns
|
| 221 |
+
- **Output**: Maintenance recommendations + efficiency tips
|
| 222 |
+
- **Real-time**: Continuous monitoring and updates
|
| 223 |
+
|
| 224 |
+
## π§ͺ Testing
|
| 225 |
+
|
| 226 |
+
### Local Testing
|
| 227 |
+
```bash
|
| 228 |
+
# Test RAG modules
|
| 229 |
+
python -c "from rag.ingest import ensure_vector_store; print('β
RAG Ready')"
|
| 230 |
+
|
| 231 |
+
# Test predictive models
|
| 232 |
+
python -c "from models.predictive import detect_anomalies; print('β
Models Ready')"
|
| 233 |
+
|
| 234 |
+
# Test full application
|
| 235 |
+
streamlit run app.py
|
| 236 |
```
|
| 237 |
|
| 238 |
+
### Sample Data
|
| 239 |
+
The system includes sample data for testing:
|
| 240 |
+
- **HVAC Sensor Data**: Temperature, humidity, power readings
|
| 241 |
+
- **Chiller Manual**: Maintenance procedures and fault codes
|
| 242 |
+
- **Building Specs**: System specifications and requirements
|
| 243 |
+
|
| 244 |
+
## π€ Contributing
|
| 245 |
+
|
| 246 |
+
1. Fork the repository
|
| 247 |
+
2. Create a feature branch
|
| 248 |
+
3. Make your changes
|
| 249 |
+
4. Test thoroughly
|
| 250 |
+
5. Submit a pull request
|
| 251 |
+
|
| 252 |
+
## π License
|
| 253 |
+
|
| 254 |
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
| 255 |
+
|
| 256 |
+
## π Academic Use
|
| 257 |
+
|
| 258 |
+
This project was developed as part of an academic RAG system implementation course. It demonstrates:
|
| 259 |
+
|
| 260 |
+
- **RAG Architecture**: Complete retrieval-augmented generation system
|
| 261 |
+
- **IoT Integration**: Real-time sensor data processing
|
| 262 |
+
- **Predictive Analytics**: Machine learning for maintenance
|
| 263 |
+
- **Vector Databases**: ChromaDB implementation
|
| 264 |
+
- **Modern Web UI**: Streamlit-based dashboard
|
| 265 |
+
|
| 266 |
+
## π Support
|
| 267 |
+
|
| 268 |
+
For questions or issues:
|
| 269 |
+
- **GitHub Issues**: [Create an issue](https://github.com/itsnewcoder/iot-smart-building-rag/issues)
|
| 270 |
+
- **Documentation**: Check this README and code comments
|
| 271 |
+
- **Community**: Streamlit and HuggingFace communities
|
| 272 |
+
|
| 273 |
+
## π Future Enhancements
|
| 274 |
+
|
| 275 |
+
- [ ] Real-time IoT device integration
|
| 276 |
+
- [ ] Advanced ML models for failure prediction
|
| 277 |
+
- [ ] Multi-modal document support (images, audio)
|
| 278 |
+
- [ ] API endpoints for external systems
|
| 279 |
+
- [ ] Mobile-responsive interface
|
| 280 |
+
- [ ] Advanced analytics dashboard
|
| 281 |
+
- [ ] Integration with building management systems
|
| 282 |
+
|
| 283 |
+
---
|
| 284 |
+
|
| 285 |
+
**Built with β€οΈ for Smart Building Intelligence**
|
| 286 |
|
| 287 |
+
*Last updated: January 2025*
|
|
|