takkars/aircraft-maintenance-rag
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
Aircraft Maintenance RAG Assistant
A Retrieval-Augmented Generation (RAG) system designed to assist aircraft maintenance personnel by providing intelligent, context-aware recommendations based on historical maintenance records.
Features
- ๐ Semantic Search: Utilizes ChromaDB for efficient vector storage and similarity search
- ๐ค LLM Integration: Flexible LLM access through OpenRouter.ai with local fallback options
- ๐ Advanced Retrieval: Supports MMR (Maximal Marginal Relevance) and multi-query retrieval
- ๐ Metadata Filtering: Filter maintenance records by aircraft model, system, or other attributes
- ๐ฌ Interactive UI: User-friendly Gradio interface for natural language queries
- ๐๏ธ Open Source: Built with LangChain for easy customization and extension
Installation
- Clone the repository:
git clone https://github.com/bhargavatakkars/aircraft-maintenance-rag.git
cd aircraft-maintenance-rag- Install dependencies:
pip install -r requirements.txt- Set up OpenRouter API key:
- Get your API key from OpenRouter.ai
- For local development: Create a
.envfile withOPENROUTER_API_KEY=your_key_here - For Hugging Face Spaces: Add as a Space Secret in Settings โ Variables
- Run the application:
./deploy.shProject Structure
app.py: Gradio web interface implementationrag_pipeline.py: Core RAG system implementation using LangChaindummy_data.py: Synthetic maintenance records generatordeploy.sh: Deployment script for local and Hugging Face Spacesrequirements.txt: Python dependencies
Usage
- Start the application:
python app.py- Access the web interface at
http://localhost:7860
- Enter maintenance-related queries in natural language, such as:
- "What are common hydraulic pump failures on Boeing 737s?"
- "Show me recent landing gear issues in Airbus A320"
- "What maintenance actions were taken for electrical system faults?"
Advanced Features
MMR Search
Enable diverse document retrieval:
rag.configure_retriever(search_type="mmr", k=3, lambda_mult=0.5)Multi-Query Retrieval
Enable query expansion for better results:
rag.enable_multi_query_retriever()Metadata Filtering
Filter by specific aircraft or system:
rag.configure_retriever(filters={"aircraft_model": "Boeing 737", "system": "Hydraulic"})Deployment on Hugging Face Spaces
Step 1: Get OpenRouter API Key
- Go to OpenRouter.ai
- Sign up/Login and navigate to API Keys
- Create a new API key
- Note down your API key (format:
sk-or-v1-...)
Step 2: Create Hugging Face Space
- Go to Hugging Face
- Sign up/Login if you haven't already
- Click on your profile picture โ "New Space"
- Fill in the Space creation form:
- Owner: Select your account
- Space name:
aircraft-maintenance-rag - License: MIT
- SDK: Gradio
- Space hardware: CPU (Free tier)
- Python version: 3.10
Step 3: Configure Space Settings
- Go to your Space's Settings โ Variables
- Click "New Secret"
- Add your OpenRouter API key:
- Secret name:
OPENROUTER_API_KEY - Secret value: Your API key from OpenRouter (sk-or-v1-...)
- Click "Add Secret"
Step 4: Upload Project Files
Option 1: Using Git:
git clone https://huggingface.co/spaces/YOUR_USERNAME/aircraft-maintenance-rag
cd aircraft-maintenance-rag
# Copy all project files here
git add .
git commit -m "Initial commit"
git pushOption 2: Using Web Interface:
- Go to your Space's "Files" tab
- Upload all project files:
app.pyrag_pipeline.pydummy_data.pydeploy.shrequirements.txtREADME.md
Step 5: Verify Deployment
- Wait for the automatic deployment to complete
- Check the "App" tab to see your application running
- Monitor the "Factory Logs" tab for any errors
- Test the application by submitting a maintenance query
Troubleshooting
- If the app fails to load, check the "Factory Logs" for errors
- Verify that
OPENROUTER_API_KEYis properly set in Space Secrets - Ensure all dependencies in
requirements.txtare correct - Check that the model name in
rag_pipeline.pymatches:"mistralai/mistral-7b-instruct:free"
First-Time Deployment
On first deployment, the system will:
- Create necessary directories (data/, chroma_db/)
- Generate synthetic maintenance records
- Build the vector store from scratch
- This process may take a few minutes
- Subsequent launches will reuse the existing data unless rebuild is forced
If you see "Building vector store..." message, this is normal for first deployment or when rebuilding is triggered.
OpenRouter Model Configuration
The system is configured to use mistralai/mistral-7b-instruct:free by default. To change models:
- In
rag_pipeline.py, locate theget_llm()method - Update the model name:
return ChatOpenRouter(
model="mistralai/mistral-7b-instruct:free", # or "deepseek-ai/deepseek-coder:free"
openrouter_api_key=os.getenv("OPENROUTER_API_KEY")
)Available free models and their specifications:
mistralai/mistral-7b-instruct:free- Context: 8K tokens
- Good for: General maintenance queries
deepseek-ai/deepseek-coder:free- Context: 16K tokens
- Good for: Technical procedures
anthropic/claude-2:free- Context: 100K tokens
- Good for: Complex analysis
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is open source and available under the MIT License.
Acknowledgments
- LangChain for the RAG framework
- ChromaDB for vector storage
- OpenRouter.ai for LLM access
- Gradio for the web interface
