This is not an officially supported Google product. This project is not eligible for the Google Open Source Software Vulnerability Rewards Program, Google Cloud Platform/SecOps Terms of Service, How Gemini for Google Cloud uses your data. This tool is provided "as is" without warranty of any kind. Users are solely responsible for understanding and managing the tool's interaction with their databases. Use of this tool constitutes acceptance of all risks associated with database access, reading, usage, and modifications.
Context Engineering Agent
The Context Engineering Agent is an AI coding agent plugin designed to run in developer agent harnesses (such as Claude Code, Antigravity, or Gemini CLI). It generates, evaluates, and iteratively tunes tailored context artifacts (ContextSets comprising Templates, Facets, and Value Searches) to enrich database schemas for Gemini Data Analytics's data agent developer platform tools, such as QueryData (AlloyDB | Cloud SQL: PostgreSQL / MySQL | Spanner (GoogleSQL)).
Why Context Engineering?
When building data agents and natural language analytics interfaces, accurately translating user intent into database queries is critical.
As outlined in Build Context with Context Engineering Agent (AlloyDB | Cloud SQL: PostgreSQL / MySQL | Spanner (GoogleSQL)), by optimizing a ContextSet to match your application's expected query stream, the QueryData API acts as a data agent tool capable of achieving ~100% NL-to-SQL translation accuracy with low latency.
Core Concepts
A ContextSet is the central artifact generated and managed by the agent, containing structured knowledge in three primary forms:
- Templates: Link natural language query patterns to complete query statements.
- Facets: Reusable, modular query fragments (e.g., parameterized
WHEREclauses or specialized join filters) linked to domain vocabulary. - Value Searches: Specialized mapping queries that dynamically resolve user-supplied values (e.g., "Lndn") to database records ("London") via the capabilities of the underlying database, such as embedding search, AI operators, or simple trigram search.
For full schema details, structure specifications, and dialect-specific JSON representations of ContextSets, see the official Context Sets Overview (AlloyDB | Cloud SQL: PostgreSQL / MySQL | Spanner (GoogleSQL)).
Prerequisites & Environment Setup
Before getting started, prepare your GCP environment, required APIs (Data Analytics API, Gemini for Google Cloud API, Dataplex Universal Catalog API), IAM permissions, and database Data API settings.
Follow the step-by-step setup guide in the official documentation: 👉 Prepare Your Environment: (AlloyDB | Cloud SQL: PostgreSQL / MySQL | Spanner (GoogleSQL))
Primary Workflow Phases
The agent enables you to craft an optimized context for QueryData API through three primary phases:
Phase 1: Artifact Ingestion
Why it matters: Without broader context on the application's goals and scope, AI models generate sterile queries based solely on database column names, missing how your users actually ask for information.
- Connect & Discover: Inspect any resources shared with the agent that may be relevant to your application and its domain.
- Domain Concept Extraction: Extract key terminology, domain rules, jargon, and common query patterns.
- Schema Mapping: Map extracted concepts directly to their corresponding underlying database tables and columns.
Phase 2: Dataset Creation
Why it matters: A realistic golden dataset establishes your benchmark for accuracy, ensuring your data agent is evaluated against messy human language rather than artificially simple database queries.
- Dataset Planning: Set goals for your dataset, deciding on question difficulty, business topics to cover, and total dataset size.
- Initial Question Generation: Create a core set of natural language questions grounded in your business documents, verifying that each question's corresponding query runs accurately on your database.
- Dataset Expansion: Scale up the question set by adding real-world variations, such as different human phrasing, complex combinations of joins and measures, and realistic values—to cover the ambiguity of natural language.
- Dataset Validation: Audit the full dataset against your original plan and ask for your approval before proceeding.
Phase 3: Context Optimization via Recursive Hill-Climbing
Why it matters: Iterative evaluation and gap analysis systematically fix query translation failures, driving accuracy toward ~100% while ensuring fixes don't break previously working queries.
The optimization loop creates an initial ContextSet and then iteratively refines it using evaluation feedback:
- Bootstrap: Generate an initial baseline context.
- Evaluate: Measure context effectiveness against a golden dataset.
- Hill-Climbing: Perform gap analysis on failures and generate automated fixes.
- Iterate: Apply the improved context and re-run evaluation to continuously improve quality.
- Final Validation (Optional): Verify mutations against a separated test set to ensure generalization and prevent overfitting.
Note: While there is a typical ordering for these CUJs, the agent is flexible in how you want to execute. You can run the full pipeline end-to-end, trigger any individual phase, or ask for targeted changes to the ContextSet.
Bring Artifacts via Filesystem or MCP
To prevent the AI from generating trivial schema-only questions (e.g., "What is the count of users?"), the agent bridges the semantic gap by grounding context generation in real-world business documents—such as product glossaries, business wikis, SOPs, ORM data models, emails, or application or database logs.
You can provide business artifacts directly to the agent from local filesystems or via Model Context Protocol (MCP) Servers.
Installing via a compatible Agent Plugins client
This repository ships a valid Agent Plugins (v1) plugin under plugin/, bundling both agent skills and its MCP servers. Any Agent Plugins–compatible client (VS Code, Cursor, GitHub Copilot, Kiro, and others) can install it directly using its own built-in plugin command — no extra tooling required — by pointing at this repository:
https://github.com/GoogleCloudPlatform/db-context-enrichment
See your agent's documentation for its exact install command.
How to Use
Launch your agent harness (Gemini CLI, Claude Code, or Antigravity) in your workspace directory and interact in natural language:
Example Natural Language Prompts
- End-to-End: (From the app directory) "Optimize context for my app."
- Dataset Curation: "Expand my dataset with app changes in
<PULL_REQUEST_LINK>." - Ad-hoc Evaluation: "Evaluate accuracy of QueryData with
ContextSet<context_set_id>on dataset.json." - Targeted Authoring: "Add a facet for active premium subscriptions."
🛠️ Developer Note: For developer setup instructions, local CLI linking, unit testing (
pytest), linting (ruff), and fork release testing, see docs/development.md.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file google_cloud_db_context_engineering-0.7.1.tar.gz.
File metadata
- Download URL: google_cloud_db_context_engineering-0.7.1.tar.gz
- Upload date:
- Size: 28.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfb821ce249506fac640b14f4c6f6bdc867a2dd64e0606421f106dea9be7e78a
|
|
| MD5 |
d5fff5a042926317fe97d42e42448fe7
|
|
| BLAKE2b-256 |
88957cd3916cdeac69fb6dfe24fac98536609749304284e65c5811ebd2eed17f
|
Provenance
The following attestation bundles were made for google_cloud_db_context_engineering-0.7.1.tar.gz:
Publisher:
google-cloud-sdk-py@oss-exit-gate-prod.iam.gserviceaccount.com
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
google_cloud_db_context_engineering-0.7.1.tar.gz -
Subject digest:
bfb821ce249506fac640b14f4c6f6bdc867a2dd64e0606421f106dea9be7e78a - Sigstore transparency entry: 2348134478
- Sigstore integration time:
-
Token Issuer:
https://accounts.google.com -
Service Account:
google-cloud-sdk-py@oss-exit-gate-prod.iam.gserviceaccount.com
-
Statement type:
File details
Details for the file google_cloud_db_context_engineering-0.7.1-py3-none-any.whl.
File metadata
- Download URL: google_cloud_db_context_engineering-0.7.1-py3-none-any.whl
- Upload date:
- Size: 32.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41d9f82b221bcd333f98aac4d386c74ddd12b599ee4d4ee2bb660b524671cb5f
|
|
| MD5 |
792b36c85d817c7612ca04f31cba43fa
|
|
| BLAKE2b-256 |
6e63fd899623602723cf0b52610f550909679e821b378d2a6da57c012af7017b
|
Provenance
The following attestation bundles were made for google_cloud_db_context_engineering-0.7.1-py3-none-any.whl:
Publisher:
google-cloud-sdk-py@oss-exit-gate-prod.iam.gserviceaccount.com
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
google_cloud_db_context_engineering-0.7.1-py3-none-any.whl -
Subject digest:
41d9f82b221bcd333f98aac4d386c74ddd12b599ee4d4ee2bb660b524671cb5f - Sigstore transparency entry: 2348133980
- Sigstore integration time:
-
Token Issuer:
https://accounts.google.com -
Service Account:
google-cloud-sdk-py@oss-exit-gate-prod.iam.gserviceaccount.com
-
Statement type: