Skip to content

BuildSafe Copilot — an AI-powered construction safety and compliance assistant built on Elastic and Google Cloud Vertex AI. It delivers instant, grounded answers from policies, generates Job Safety Analyses, and automates audit packs to keep crews compliant.

License

Notifications You must be signed in to change notification settings

LightLLM/BuildSafeCopilot

Repository files navigation

BuildSafe Copilot

AI-powered construction compliance with Elastic hybrid search and Vertex AI grounding.

Overview

BuildSafe Copilot is a comprehensive construction compliance assistant that leverages Google Cloud's Vertex AI and Elastic's hybrid search capabilities to provide accurate, grounded answers about construction safety regulations and generate compliance documents.

Architecture

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   Next.js       │    │   FastAPI       │    │   Elastic       │
│   Frontend      │◄──►│   Backend       │◄──►│   Cloud         │
│   (Chat UI)     │    │   (Cloud Run)   │    │   (Serverless)  │
└─────────────────┘    └─────────────────┘    └─────────────────┘
                                │
                                ▼
                       ┌─────────────────┐
                       │   Google Cloud  │
                       │   - Vertex AI   │
                       │   - Gemini 1.5  │
                       │   - Embeddings  │
                       │   - GCS Bucket  │
                       └─────────────────┘

Tech Stack

Frontend

  • Next.js 14 with App Router
  • Tailwind CSS for styling
  • shadcn/ui for components
  • TypeScript for type safety

Backend

  • FastAPI with Python 3.11
  • Google Cloud Run for hosting
  • Vertex AI for LLM and embeddings
  • Elastic Cloud for hybrid search

Data Storage

  • Elastic Cloud Serverless for document storage and search
  • Google Cloud Storage for generated PDFs and ZIP files

Features

Core Capabilities

  • Hybrid Search: Combines BM25 text search with vector similarity search
  • Grounded AI: All answers are backed by cited sources from compliance documents
  • Document Generation: Creates Job Safety Analysis (JSA) PDFs
  • Audit Packs: Generates ZIP files with relevant compliance evidence

Supported Document Types

  • Compliance Documents (cc_docs): Safety regulations, standards, and procedures
  • Training Materials (cc_training): Educational content and certification requirements
  • Incident Reports (cc_incidents): Safety incidents and corrective actions

Quick Start

Prerequisites

  • Node.js 18+ and pnpm
  • Python 3.11+
  • Google Cloud Project with Vertex AI enabled
  • Elastic Cloud account

1. Clone and Install

git clone <repository-url>
cd BuildSafeCopilot
pnpm install
cd app/backend && pip install -r requirements.txt

2. Environment Setup

Copy and configure environment files:

cp app/backend/.env.example app/backend/.env
cp app/frontend/.env.example app/frontend/.env.local

3. Elastic Setup

# Create index template and indices
python scripts/elastic/setup_indices.py

# Ingest seed data
python scripts/embed_and_ingest.py --index cc_docs --file scripts/seed/seed_cc_docs.jsonl
python scripts/embed_and_ingest.py --index cc_training --file scripts/seed/seed_cc_training.jsonl
python scripts/embed_and_ingest.py --index cc_incidents --file scripts/seed/seed_cc_incidents.jsonl

4. Run Locally

# Backend (Terminal 1)
cd app/backend
uvicorn main:app --host 0.0.0.0 --port 8080

# Frontend (Terminal 2)
cd app/frontend
pnpm dev

Visit http://localhost:3000 to use the application.

Deployment

Google Cloud Run

# Deploy backend
cd app/backend
gcloud run deploy buildsafe-backend --source . --platform managed --region us-central1

# Deploy frontend
cd app/frontend
gcloud run deploy buildsafe-frontend --source . --platform managed --region us-central1

Terraform Infrastructure

cd infra/terraform
terraform init
terraform plan
terraform apply

API Endpoints

Search & Query

  • POST /search - Raw hybrid search results
  • POST /ask - AI-powered compliance answers with citations

Document Generation

  • POST /action/jsa - Generate Job Safety Analysis PDF
  • POST /action/audit-pack - Create compliance audit pack ZIP

Data Schema

Document Structure

{
  "id": "unique-document-id",
  "title": "Document Title",
  "source": "OSHA|CSA|Provincial",
  "doctype": "regulation|standard|procedure",
  "trade": "electrical|plumbing|general",
  "jurisdiction": "SK|ON|NS|Federal",
  "language": "en|fr",
  "published_at": "2024-01-01T00:00:00Z",
  "url": "https://source-url.com",
  "content": "Full document text...",
  "embedding": [0.1, 0.2, ...] // 768-dimensional vector
}

Compliance & Licensing

  • License: Apache 2.0
  • Data: All seed data is synthetic and created for demonstration purposes
  • No Copyrighted Content: No third-party copyrighted materials are included
  • Hackathon Compliance: Uses only Google Cloud AI services and Elastic Cloud

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Support

For questions or issues, please open a GitHub issue or contact the development team.


Built for AI Accelerate Hackathon 2025

About

BuildSafe Copilot — an AI-powered construction safety and compliance assistant built on Elastic and Google Cloud Vertex AI. It delivers instant, grounded answers from policies, generates Job Safety Analyses, and automates audit packs to keep crews compliant.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published