A sophisticated Retrieval-Augmented Generation (RAG) system designed for Australian building regulatory compliance queries. This system combines multimodal document processing with AI-powered question answering to provide expert guidance on building massing, setbacks, and compliance requirements.
- ColPali - Multimodal RAG using ColBERT + PaliGemma for visual document understanding
- Qdrant - High-performance vector database for similarity search
- OpenAI GPT-4o - Large language model for generating expert responses
- Flask - Lightweight web framework for API endpoints
- PDF2Image - Convert PDF pages to images for visual processing
- PyPDF2 - PDF metadata extraction
- PIL (Pillow) - Image processing and manipulation
- Base64 - Image encoding for API responses
- ColPali - Advanced document embedding encoder and retriever
- Transformers - Hugging Face transformers for model processing
- PyTorch - Deep learning framework
- CUDA - GPU acceleration support
- PDF Processing: Converts building regulation PDFs into processable format
- Visual Embedding: Creates multimodal embeddings that understand both text and visual layout
- Vector Storage: Stores embeddings in Qdrant for fast similarity search
- Metadata Preservation: Maintains document filename, page numbers, and other metadata
- Natural Language Input: Accept complex regulatory questions in plain English
- Semantic Search: Find relevant document sections using advanced similarity matching
- Expert Analysis: Generate comprehensive compliance assessments using GPT-4o
- Regulatory Citations: Provide specific clause references and calculations
- Python 3.8+
- CUDA-compatible GPU (recommended)
- OpenAI API key
- Qdrant cloud instance or local installation
# Clone the repository
git clone <repository-url>
cd mmrag_hackathon
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtCreate a .env file in the project root:
OPENAI_API_KEY=your_openai_api_key_here
QDRANT_API_KEY=your_qdrant_api_key_here
HF_TOKEN=your_huggingface_token_here# Place your PDF documents in the regulations folder
mkdir -p regulations/
# Copy your building regulation PDFs to this folder# Run the database update script to process and index documents
python update_db.py# Launch the Flask API
python app.pyThe API will be available at http://localhost:5000
Main RAG endpoint for building regulatory queries.
Request Format:
{
"query": "What are the setback requirements for a 2-storey residential building in NSW?"
}Response Format:
{
"response": "**COMPLIANCE ASSESSMENT:** Requires Clarification...",
"docs": [
{
"filename": "nsw_building_code.pdf",
"page_number": 15,
"score": 0.89,
"image": "base64_encoded_image_data"
}
]
}Get summary information about regulations.
Request Format:
{
"language": "en"
}import requests
import json
def query_regulations(question):
url = "http://localhost:5000/query"
headers = {"Content-Type": "application/json"}
data = {"query": question}
response = requests.post(url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
result = response.json()
print("Expert Analysis:", result["response"])
print(f"Found {len(result['docs'])} relevant documents")
return result
else:
print(f"Error: {response.status_code}")
return None
# Example usage
question = """
I have a 800mΒ² site in Melbourne, VIC. I want to build a 3-storey apartment building
with 60% site coverage. What are the required setbacks and height limits?
"""
result = query_regulations(question)curl -X POST http://localhost:5000/query \
-H "Content-Type: application/json" \
-d '{
"query": "What is the maximum building height allowed in R3 Medium Density Residential zones in NSW?"
}'Use the provided test script for quick validation:
python api_test.pyβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β RAG SYSTEM ARCHITECTURE β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β π PDF Documents β π ColPali Processing β ποΈ Qdrant β
β (Building Codes) (Visual + Text) (Vector DB) β
β β
β π€ User Query β π Similarity Search β π Results β
β β
β π Retrieved Docs β π€ GPT-4o Analysis β β
Response β
β (Relevant Pages) (Expert System) (Compliance) β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1. Document Processing Pipeline:
update_db.py- Indexes PDFs and creates vector embeddingsmultimodal_utils.py- Handles PDF to image conversionmodels.py- Defines ColPali model configurations
2. RAG Query Engine:
rag_retrieval.py- Implements retrieval and response generationapp.py- Flask API endpoints and routing
3. Utilities:
api_test.py- Testing and validation scripts
- Visual Layout Recognition: Understands tables, diagrams, and complex layouts
- Multimodal Processing: Combines text and visual information
- Precise Retrieval: Finds relevant sections with high accuracy
- Australian Building Code Expertise: Specialized knowledge of NCC, Australian Standards
- Regulatory Compliance Checking: Identifies non-compliant elements
- Quantitative Analysis: Performs calculations and provides specific measurements
- Citation References: Provides exact clause numbers and standards
- Error Handling: Robust timeout and retry mechanisms
- Response Formatting: Structured, professional outputs
- Scalable Architecture: Designed for high-volume queries
- Performance Optimization: GPU acceleration and caching
- Verify building designs against regulatory requirements
- Calculate setback requirements for specific sites
- Understand height limits and bulk controls
- Check site coverage and plot ratio compliance
- Assess development potential of sites
- Understand zoning restrictions and opportunities
- Navigate complex regulatory frameworks
- Optimise building designs for compliance
This system provides general guidance based on available regulatory documents. Always consult with:
- Licensed architects and building designers
- Local council planning departments
- Building certifiers and surveyors
- Legal professionals for complex matters
- Building codes and planning schemes change regularly
- Ensure your document database is current
- Check for updates to Australian Standards
- Verify local council amendments
- Responses are based on documents in the vector database
- Complex site-specific issues may require human expertise
- Performance depends on quality of source documents
- GPU recommended for optimal processing speed
OpenAI API Timeout:
- Increase timeout values in
rag_retrieval.py - Check OpenAI API status
- Verify API key permissions
Qdrant Connection Issues:
- Verify API key and endpoint in
.env - Check network connectivity
- Ensure collection exists
GPU Memory Issues:
- Reduce batch sizes in
update_db.py - Use CPU fallback if necessary
- Monitor GPU memory usage
Document Processing Errors:
- Verify PDF files are not corrupted
- Check file permissions
- Ensure sufficient disk space
We welcome contributions to improve the system:
- Bug fixes and performance improvements
- Additional regulatory document processing
- Enhanced query capabilities
- Documentation improvements