A production-grade RAG (Retrieval-Augmented Generation) system for querying Ethereum blockchain data using natural language, built entirely with BigQuery ML and Google APIs.
📄 Read the Technical Write-up - A comprehensive guide on building RAG systems using only SQL and Google APIs.
This guide uses the Application Default Credentials (ADC) method.
-
Set up a Google Cloud project
-
Install the gcloud CLI
- macOS:
brew install --cask google-cloud-sdk - Windows: gcloud CLI installer
- macOS:
-
Environment variables
Create a.envfile with your project and location settings.- Recommended: use
USas the location since public datasets are in the US region (this avoids cross-regional issues). - Use
.env.exampleas a template.
- Recommended: use
-
Authenticate with Google Cloud
Run the following commands in your terminal:# Load environment variables set -a; source .env; set +a; # Authenticate gcloud auth application-default login # Set project gcloud config set project "$GOOGLE_CLOUD_PROJECT"
-
Create a BigQuery connection
bq mk --connection \ --project_id="$GOOGLE_CLOUD_PROJECT" \ --location="$GOOGLE_CLOUD_LOCATION" \ --connection_type=CLOUD_RESOURCE \ bq-llm-connection || true echo '---' bq show --connection \ --project_id="$GOOGLE_CLOUD_PROJECT" \ --location="$GOOGLE_CLOUD_LOCATION" \ bq-llm-connection || true
More on BigQuery connections here
If you encounter the following error while running BigQuery ML models:
The [email protected] does not have the permission to access or use the endpoint. Please grant the Vertex AI user role to the [email protected] following https://cloud.google.com/bigquery/docs/generate-text-tutorial#grant-permissions. If issue persists, contact [email protected] for help.
Grant the Vertex AI User role to the service account:
- Follow this guide.
.
├── bigq_ai_app/
│ ├── core/
│ ├── utils/
│ └── ui.py
├── docs/
├── notebooks/
├── tests/
├── .env.example
├── .gitignore
├── app.py
├── pyproject.toml
└── README.md
-
Create a virtual environment:
uv venv
-
Activate the environment:
source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies from your
pyproject.toml:uv pip install -e .(The -e . installs your project in "editable" mode, which is great for development).
-
Run the Gradio app:
python app.py
- Open http://127.0.0.1:7865
- To expose a public link quickly: set share=True in launch()
- To bind for containers/VMs: use server_name="0.0.0.0
