Spaces:
Sleeping
Sleeping
Upload README.md
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227# Engineering Knowledge Assistant — RAG Pipeline
[](https://huggingface.co/spaces/arifme071/engineering-knowledge-rag)[](https://www.python.org/)[](https://streamlit.io/)[](https://github.com/facebookresearch/faiss)[](https://huggingface.co/)[](LICENSE)
> A production-grade Retrieval-Augmented Generation (RAG) pipeline grounded in published> research on railroad condition monitoring, DAS signal processing, and AI-driven> manufacturing optimization.
**🔗 Try it live →** [huggingface.co/spaces/arifme071/engineering-knowledge-rag](https://huggingface.co/spaces/arifme071/engineering-knowledge-rag)
---
## What it does
This app lets you query a knowledge base built from peer-reviewed research papers usingnatural language. Type a question, and the pipeline:
1. **Retrieves** the most semantically relevant passages from the knowledge base (FAISS + SentenceTransformers)2. **Augments** a prompt with those passages as context3. **Generates** a grounded, citation-backed answer (HuggingFace Flan-T5)
No hallucination about domain specifics — every answer is anchored to real research.
---
## Architecture
```User Query │ ▼┌─────────────────────────┐│ SentenceTransformers │ → Embed query (MiniLM-L6-v2, 384-dim)│ (all-MiniLM-L6-v2) │└────────────┬────────────┘ │ query vector ▼┌─────────────────────────┐│ FAISS Vector Index │ → Cosine similarity search (Inner Product)│ (IndexFlatIP) │ Returns top-k most relevant chunks└────────────┬────────────┘ │ retrieved chunks + scores ▼┌─────────────────────────┐│ Prompt Builder │ → Assembles context + question into LLM prompt│ │ with source attribution└────────────┬────────────┘ │ prompt ▼┌─────────────────────────┐│ HuggingFace Flan-T5 │ → Generates grounded answer│ (google/flan-t5-base) │ Open-source, runs locally — no API key needed└────────────┬────────────┘ │ answer + sources ▼┌─────────────────────────┐│ Streamlit Chat UI │ → Displays answer with expandable source cards│ │ showing relevance scores and paper metadata└─────────────────────────┘```
---
## Knowledge Base
The app ships with a built-in knowledge base from **7 peer-reviewed publications** (184+ citations):
| Paper | Venue | Year | Domain ||---|---|---|---|| [CNN-LSTM-SW for Railroad Anomaly Detection via DAS](https://doi.org/10.1016/j.geits.2024.100178) | Elsevier GEITS | 2024 | Railroad AI || [DAS-based Railroad CM with GRU/LSTM](https://doi.org/10.1117/1.JRS.18.016512) | SPIE JARS | 2024 | DAS Signal Processing || [Review of DAS Applications for Railroad CM](https://www.sciencedirect.com/science/article/abs/pii/S0888327023008919) | Elsevier MSSP | 2023 | DAS Review || HMM-RL for WAAM Intelligent Control | Springer | 2026 | Manufacturing AI |
**You can extend the knowledge base** by dropping your own PDFs into `data/papers/` — the pipeline auto-ingests and indexes them on first run.
---
## Example queries
```How does the CNN-LSTM sliding window correct misclassifications?What are the four condition classes in the DAS railroad dataset?How does SMOTE handle class imbalance in the training data?What is the difference between GRU and LSTM for DAS signal processing?How does the HMM-RL pipeline optimize WAAM manufacturing?What features are extracted from DAS signals for model training?What is the ROC AUC score for each condition class?How does distributed acoustic sensing work on railroad tracks?```
---
## Repository Structure
```engineering-knowledge-rag/├── app/│ └── main.py # Streamlit UI — chat interface, settings sidebar│├── src/│ ├── retrieval/│ │ └── rag_pipeline.py # Core RAG: embed → FAISS search → LLM generate│ ├── ingestion/│ │ ├── builtin_knowledge.py # Pre-loaded paper excerpts (works offline)│ │ └── document_loader.py # PDF/TXT ingestion + chunking pipeline│ └── utils/│ └── ui_helpers.py # Source cards, example query buttons│├── data/│ ├── papers/ # Drop your PDFs here to extend knowledge base│ └── index/ # Auto-generated FAISS index (git-ignored)│├── Dockerfile # Container for HuggingFace Spaces deployment├── requirements.txt├── .gitignore└── README.md```
---
## Quickstart
### Run locally
```bashgit clone https://github.com/arifme071/engineering-knowledge-rag.gitcd engineering-knowledge-ragpip install -r requirements.txtstreamlit run app/main.py```
Open `http://localhost:8501` — loads instantly with the built-in knowledge base.
### Add your own documents
```bash# Drop PDFs into data/papers/cp your_paper.pdf data/papers/
# Delete cached index so it rebuildsrm -rf data/index/
# Rerun — auto-ingests on startupstreamlit run app/main.py```
### Run with Docker
```bashdocker build -t engineering-rag .docker run -p 7860:7860 engineering-rag```
---
## Deploy to HuggingFace Spaces (free)
1. Go to [huggingface.co](https://huggingface.co) → **New Space**2. Name: `engineering-knowledge-rag` | SDK: **Streamlit** | Visibility: **Public**3. Upload all files from this repo4. HuggingFace builds and deploys automatically (~5 min)5. Live URL: `https://huggingface.co/spaces/YOUR_USERNAME/engineering-knowledge-rag`
---
## Tech Stack
| Component | Technology | Why ||---|---|---|| **Embeddings** | `sentence-transformers/all-MiniLM-L6-v2` | Fast, high-quality 384-dim, runs on CPU || **Vector store** | FAISS `IndexFlatIP` | Exact cosine similarity, no server needed || **LLM** | `google/flan-t5-base` | Open-source, instruction-tuned, zero API cost || **Frontend** | Streamlit | Shareable demo, native chat components || **Deployment** | HuggingFace Spaces + Docker | Free hosting, permanent public URL |
---
## Extending the Pipeline
**Swap the LLM** — any HuggingFace model works:```pythonllm_model: str = "mistralai/Mistral-7B-Instruct-v0.1" # Better quality, needs GPUllm_model: str = "google/flan-t5-large" # Bigger, still CPU-friendly```
**Use OpenAI/Anthropic instead:**```pythonfrom openai import OpenAIclient = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))response = client.chat.completions.create(model="gpt-4o", messages=[...])```
**Persistent vector store with ChromaDB:**```pythonimport chromadbclient = chromadb.PersistentClient(path="data/chroma")```
---
## Related Repositories
- [railroad-anomaly-detection-cnn-lstm](https://github.com/arifme071/railroad-anomaly-detection-cnn-lstm) — CNN-LSTM-SW paper repo (Elsevier GEITS 2024)- 📚 [Google Scholar](https://scholar.google.com/citations?user=iafas1MAAAAJ&hl=en) — Full publication list
---
## Author
**Md Arifur Rahman**PIN Fellow (AI in Manufacturing) · Georgia Tech | MSc Applied Engineering · Georgia Southern University
[](https://scholar.google.com/citations?user=iafas1MAAAAJ&hl=en)[](https://www.linkedin.com/in/marahman-gsu/)[](https://github.com/arifme071)
---
## License
MIT License — see [LICENSE](LICENSE) for details.README.mdAdded+227