How eragon-amansirohi/hea_qa works
Project type and purpose
• HEA_QA is a full‑stack web application for Retrieval‑Augmented Generation (RAG) question answering on research abstracts about High Entropy Alloys.
• The user interface is served by Flask; the core functionality is chunking, embedding, storing context, and generating answers via either a local fine‑tuned language model (Phi‑2 QLoRA) or an API-based model (DeepSeek/OpenAI).
File structure
• Top level:
• app.py – Flask application entry point
• qa_pair_gen.py – standalone script for generating QA pairs
• requirements.txt, README.md, LICENSE
• models/phi2-lora-finetuned – local LLM adapter files
• static/ – front‑end assets (css, js)
• templates/index.html – main HTML template
• test/ – sample CSV and TXT for upload
• Patterns and modules:
• MVC‑like separation: templates (views), static (assets), app.py (controller), models (ML resources), scripts
• Storage/config: Flask sessions & pickle, FAISS index persists in memory or pickled storage
• Build/deploy: minimal (python app.py), configurable via requirements.txt
README for additional insights
• Uses FAISS for vector search and SentenceTransformer for embeddings
• Switchable model layer abstraction (local vs. API)
• Persistent document store via Flask sessions & pickle
• QA pair generation is run in background by qa_pair_gen.py
a. Main components:
• Client Browser (UI)
• Flask Web Server (app.py)
• Frontend Static & Templates
• Document Store (Flask sessions + pickle files)
• Embedding Service (SentenceTransformer)
• Vector Index (FAISS)
• Model Routing Layer
– Local Model: Phi‑2 QLoRA adapter
– External API: DeepSeek/OpenAI
• QA Pair Generation Module (qa_pair_gen.py)
• Optional Storage: CSV/JSON upload
b. Relationships & interactions:
1. User → Browser UI: submit abstract or upload CSV
2. Browser → Flask endpoint: POST abstract
3. Flask → Embedding Service: chunk & embed text
4. Embeddings → FAISS: add to/inquire from index
5. Flask persists raw text & index references in session (pickle)
6. User asks question → Flask retrieves relevant chunks via FAISS
7. Flask routes to local model or API model
8. Model returns answer → Flask sends JSON → UI displays
9. QA Pair Gen module can be invoked by Flask or run separately
c. Architectural patterns & design principles:
• Modular separation: web layer, ML layer, storage layer
• Strategy pattern for switching between local and API models
• RAG pipeline: chunk → embed → index → retrieve → generate
• Persistent session management for user state
d. Key technologies:
• Flask, Jinja2
• Python: transformers, peft, sentence-transformers, faiss-cpu, flask-session
• Frontend: HTML/CSS/JavaScript (static/js/script.js, static/css/style.css)
Final advice
• Do not over‑complicate: a clear 4‑layer view (UI → Web Server → ML Services → Storage) plus the model router suffices