A full-stack GraphRAG (Graph Retrieval Augmented Generation) chatbot application built with FastAPI + Langchain backend and Next.js frontend. The system leverages Google Cloud Spanner for graph storage, Vertex AI for embeddings (text-embedding-004) and LLM (Gemini 2.5 flash) capabilities, and deploys seamlessly to Google Cloud Platform.
- Frontend: https://frontend-471866182091.us-central1.run.app
- Backend API: https://graphrag-chatbot-471866182091.us-central1.run.app
- API Documentation: https://graphrag-chatbot-471866182091.us-central1.run.app/docs
- FastAPI: High-performance Python web framework
- Google Cloud Spanner: Distributed SQL database for graph storage
- Vertex AI: LLM (text-bison) and embedding (textembedding-gecko) models
- GraphRAG: Knowledge graph-based retrieval augmented generation
- Docker: Containerization for consistent deployment
- *Crawl4AI: Playwright based web scrapper for collecting site data
- Next.js 15: React framework with App Router
- TypeScript: Type-safe development
- Tailwind CSS: Utility-first CSS framework
- Radix UI: Headless UI components
- React Hook Form: Form management
- Markdown Rendering: Rich response formatting
- Google Cloud Run: Serverless container deployment
- Google Container Registry: Docker image storage
- Google Spanner DB: Managed Graph DB for knowledge graph
- Google Vertex AI: LLM and Embeddings modals
Before starting, ensure you have:
- Google Cloud Project with billing enabled
- gcloud CLI installed and authenticated
- Docker installed locally
- Node.js 18+ and Python 3.11+
- Service Account Key with appropriate permissions
- Cloud Spanner API
- Vertex AI API
- Cloud Run API
- Cloud Build API
- Container Registry API
# Clone the repository
git clone <your-repo-url>
cd GraphRAG-Chatbot
# Start all services with Docker Compose
docker-compose up -d
# Access the application
# Frontend: http://localhost:3000
# Backend: http://localhost:8000
# API Docs: http://localhost:8000/docs# 1. Backend Setup
cd backend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
# Configure environment
cp .env.example .env
# Edit .env with your settings
# Start backend
python start_server.py
# 2. Frontend Setup (in new terminal)
cd frontend
npm install # or pnpm install
npm run devCreate the following environment files:
Backend (backend/.env):
GCP_PROJECT_ID=your-project-id
SPANNER_INSTANCE_ID=graphrag-instance
SPANNER_DATABASE_ID=graphrag-db
GOOGLE_APPLICATION_CREDENTIALS_PATH=../GraphRAG-IAM-Admin.json
GOOGLE_CLOUD_LOCATION=us-central1Frontend (frontend/.env.local):
NEXT_PUBLIC_API_URL=http://localhost:8000# Create service account
gcloud iam service-accounts create graphrag-service-account \
--display-name="GraphRAG Service Account"
# Create and download key
gcloud iam service-accounts keys create GraphRAG-IAM-Admin.json \
--iam-account=graphrag-service-account@YOUR_PROJECT_ID.iam.gserviceaccount.com
# Grant necessary roles
gcloud projects add-iam-policy-binding YOUR_PROJECT_ID \
--member="serviceAccount:graphrag-service-account@YOUR_PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/spanner.databaseUser"
gcloud projects add-iam-policy-binding YOUR_PROJECT_ID \
--member="serviceAccount:graphrag-service-account@YOUR_PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/aiplatform.user"# Create Spanner instance
gcloud spanner instances create graphrag-instance \
--config=regional-us-central1 \
--description="GraphRAG Instance" \
--nodes=1
# Create database
gcloud spanner databases create graphrag-db \
--instance=graphrag-instanceBefore using the chatbot, populate your knowledge graph:
cd backend
python ingest_data.pyOr use the scraper to collect web data:
cd scraper
python scraper.py# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down# Backend
cd backend
docker build -t graphrag-backend .
# Frontend
cd frontend
docker build -t graphrag-frontend .cd backend
# Build and push image
gcloud builds submit --tag gcr.io/YOUR_PROJECT_ID/graphrag-backend .
# Deploy to Cloud Run
gcloud run deploy graphrag-backend \
--image gcr.io/YOUR_PROJECT_ID/graphrag-backend \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--memory 2Gi \
--cpu 1 \
--concurrency 10 \
--timeout 300 \
--set-env-vars GCP_PROJECT_ID=YOUR_PROJECT_ID,SPANNER_INSTANCE_ID=graphrag-instance,SPANNER_DATABASE_ID=graphrag-db,GOOGLE_CLOUD_LOCATION=us-central1cd frontend
# Build and push image
gcloud builds submit --tag gcr.io/YOUR_PROJECT_ID/graphrag-frontend .
# Deploy to Cloud Run
gcloud run deploy graphrag-frontend \
--image gcr.io/YOUR_PROJECT_ID/graphrag-frontend \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--port 3000 \
--set-env-vars NEXT_PUBLIC_API_URL=https://YOUR_BACKEND_URLSend a message to the chatbot:
{
"question": "What products does Nestle offer?",
"conversation_id": "conv_123456"
}Response:
{
"answer": "Nestle offers a wide range of products including...",
"citations": ["https://www.madewithnestle.ca/products"],
"conversation_id": "conv_123456",
"message_id": "msg_789012",
"timestamp": "2024-01-15T10:30:00Z",
"processing_time": 2.34
}Retrieve conversation history
Clear conversation history
Backend health check
Visit /docs endpoint for Swagger UI documentation when running the backend.
- β GraphRAG-based question answering
- β Conversation history management
- β Source citation tracking
- β Google Cloud Spanner integration
- β Vertex AI LLM and embeddings
- β FastAPI with automatic documentation
- β Docker containerization
- β Health check endpoints
- β Modern chat interface
- β Real-time messaging
- β Markdown response rendering
- β Source citation display
- β Conversation management
- β Loading states and error handling
- β Responsive design
# Local
curl http://localhost:8000/health
# Production
curl https://your-backend-url/health# Local Docker logs
docker-compose logs -f backend
# Cloud Run logs
gcloud run logs read graphrag-backend --region us-central1

