google-cloud-db-context-engineering 0.6.0__tar.gz → 0.7.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google_cloud_db_context_engineering-0.7.1/PKG-INFO +122 -0
- google_cloud_db_context_engineering-0.7.1/README.md +104 -0
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/pyproject.toml +4 -2
- google_cloud_db_context_engineering-0.7.1/src/google/cloud/db_context_enrichment/common/context_store_client.py +190 -0
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google/cloud/db_context_enrichment/evaluate/db_generators/alloydb.py +17 -19
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google/cloud/db_context_enrichment/evaluate/db_generators/base.py +9 -15
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google/cloud/db_context_enrichment/evaluate/db_generators/mysql.py +17 -19
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google/cloud/db_context_enrichment/evaluate/db_generators/postgres.py +17 -19
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google/cloud/db_context_enrichment/evaluate/db_generators/spanner.py +18 -18
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google/cloud/db_context_enrichment/evaluate/evaluate_generator.py +18 -7
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google/cloud/db_context_enrichment/main.py +90 -8
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google/cloud/db_context_enrichment/model/context.py +32 -12
- google_cloud_db_context_engineering-0.7.1/src/google_cloud_db_context_engineering.egg-info/PKG-INFO +122 -0
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google_cloud_db_context_engineering.egg-info/SOURCES.txt +1 -0
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google_cloud_db_context_engineering.egg-info/requires.txt +2 -0
- google_cloud_db_context_engineering-0.6.0/PKG-INFO +0 -158
- google_cloud_db_context_engineering-0.6.0/README.md +0 -142
- google_cloud_db_context_engineering-0.6.0/src/google_cloud_db_context_engineering.egg-info/PKG-INFO +0 -158
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/LICENSE +0 -0
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/setup.cfg +0 -0
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google/cloud/db_context_enrichment/__init__.py +0 -0
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google/cloud/db_context_enrichment/common/__init__.py +0 -0
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google/cloud/db_context_enrichment/common/config.py +0 -0
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google/cloud/db_context_enrichment/common/context_mutator.py +0 -0
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google/cloud/db_context_enrichment/dataset/__init__.py +0 -0
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google/cloud/db_context_enrichment/dataset/dataset_generator.py +0 -0
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google/cloud/db_context_enrichment/evaluate/__init__.py +0 -0
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google/cloud/db_context_enrichment/evaluate/db_generators/__init__.py +0 -0
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google/cloud/db_context_enrichment/evaluate/result_reader.py +0 -0
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google/cloud/db_context_enrichment/model/__init__.py +0 -0
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google_cloud_db_context_engineering.egg-info/dependency_links.txt +0 -0
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google_cloud_db_context_engineering.egg-info/entry_points.txt +0 -0
- {google_cloud_db_context_engineering-0.6.0 → google_cloud_db_context_engineering-0.7.1}/src/google_cloud_db_context_engineering.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: google-cloud-db-context-engineering
|
|
3
|
+
Version: 0.7.1
|
|
4
|
+
Summary: A FastMCP server for generating natural language to SQL templates from database schemas.
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: fastmcp==3.3.1
|
|
9
|
+
Requires-Dist: google-genai==1.46.0
|
|
10
|
+
Requires-Dist: toolbox-core==0.5.2
|
|
11
|
+
Requires-Dist: google-cloud-geminidataanalytics==0.11.0
|
|
12
|
+
Requires-Dist: google-auth==2.41.1
|
|
13
|
+
Requires-Dist: requests==2.33.0
|
|
14
|
+
Provides-Extra: test
|
|
15
|
+
Requires-Dist: pytest; extra == "test"
|
|
16
|
+
Requires-Dist: pytest-asyncio; extra == "test"
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
This is not an officially supported Google product. This project is not eligible for the [Google Open Source Software Vulnerability Rewards Program](https://bughunters.google.com/open-source-security), [Google Cloud Platform/SecOps Terms of Service](https://cloud.google.com/terms), [How Gemini for Google Cloud uses your data](https://cloud.google.com/gemini/docs/discover/data-governance). 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.
|
|
20
|
+
|
|
21
|
+
# Context Engineering Agent
|
|
22
|
+
|
|
23
|
+
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](https://docs.cloud.google.com/gemini/data-agents/querydata/alloydb/data-agent-overview) | Cloud SQL: [PostgreSQL](https://docs.cloud.google.com/gemini/data-agents/querydata/sql-postgres/data-agent-overview) / [MySQL](https://docs.cloud.google.com/gemini/data-agents/querydata/sql-mysql/data-agent-overview) | [Spanner (GoogleSQL)](https://docs.cloud.google.com/gemini/data-agents/querydata/spanner/data-agent-overview)).
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Why Context Engineering?
|
|
28
|
+
|
|
29
|
+
When building data agents and natural language analytics interfaces, accurately translating user intent into database queries is critical.
|
|
30
|
+
|
|
31
|
+
As outlined in **Build Context with Context Engineering Agent** ([AlloyDB](https://docs.cloud.google.com/gemini/data-agents/querydata/alloydb/build-context-gemini-cli) | Cloud SQL: [PostgreSQL](https://docs.cloud.google.com/gemini/data-agents/querydata/sql-postgres/build-context-gemini-cli) / [MySQL](https://docs.cloud.google.com/gemini/data-agents/querydata/sql-mysql/build-context-gemini-cli) | [Spanner (GoogleSQL)](https://docs.cloud.google.com/gemini/data-agents/querydata/spanner/build-context-gemini-cli)), 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**.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Core Concepts
|
|
36
|
+
|
|
37
|
+
A `ContextSet` is the central artifact generated and managed by the agent, containing structured knowledge in three primary forms:
|
|
38
|
+
|
|
39
|
+
* **Templates**: Link natural language query patterns to complete query statements.
|
|
40
|
+
* **Facets**: Reusable, modular query fragments (e.g., parameterized `WHERE` clauses or specialized join filters) linked to domain vocabulary.
|
|
41
|
+
* **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.
|
|
42
|
+
|
|
43
|
+
For full schema details, structure specifications, and dialect-specific JSON representations of `ContextSets`, see the official **Context Sets Overview** ([AlloyDB](https://docs.cloud.google.com/gemini/data-agents/querydata/alloydb/context-sets-overview) | Cloud SQL: [PostgreSQL](https://docs.cloud.google.com/gemini/data-agents/querydata/sql-postgres/context-sets-overview) / [MySQL](https://docs.cloud.google.com/gemini/data-agents/querydata/sql-mysql/context-sets-overview) | [Spanner (GoogleSQL)](https://docs.cloud.google.com/gemini/data-agents/querydata/spanner/context-sets-overview)).
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Prerequisites & Environment Setup
|
|
48
|
+
|
|
49
|
+
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.
|
|
50
|
+
|
|
51
|
+
Follow the step-by-step setup guide in the official documentation:
|
|
52
|
+
👉 **Prepare Your Environment**: ([AlloyDB](https://docs.cloud.google.com/gemini/data-agents/querydata/alloydb/build-context-gemini-cli#prepare-your-environment) | Cloud SQL: [PostgreSQL](https://docs.cloud.google.com/gemini/data-agents/querydata/sql-postgres/build-context-gemini-cli#prepare-your-environment) / [MySQL](https://docs.cloud.google.com/gemini/data-agents/querydata/sql-mysql/build-context-gemini-cli#prepare-your-environment) | [Spanner (GoogleSQL)](https://docs.cloud.google.com/gemini/data-agents/querydata/spanner/build-context-gemini-cli#prepare-your-environment))
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Primary Workflow Phases
|
|
57
|
+
|
|
58
|
+
The agent enables you to craft an optimized context for QueryData API through three primary phases:
|
|
59
|
+
|
|
60
|
+
### Phase 1: Artifact Ingestion
|
|
61
|
+
*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.*
|
|
62
|
+
|
|
63
|
+
1. **Connect & Discover**: Inspect any resources shared with the agent that may be relevant to your application and its domain.
|
|
64
|
+
2. **Domain Concept Extraction**: Extract key terminology, domain rules, jargon, and common query patterns.
|
|
65
|
+
3. **Schema Mapping**: Map extracted concepts directly to their corresponding underlying database tables and columns.
|
|
66
|
+
|
|
67
|
+
### Phase 2: Dataset Creation
|
|
68
|
+
*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.*
|
|
69
|
+
|
|
70
|
+
1. **Dataset Planning**: Set goals for your dataset, deciding on question difficulty, business topics to cover, and total dataset size.
|
|
71
|
+
2. **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.
|
|
72
|
+
3. **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.
|
|
73
|
+
4. **Dataset Validation**: Audit the full dataset against your original plan and ask for your approval before proceeding.
|
|
74
|
+
|
|
75
|
+
### Phase 3: Context Optimization via Recursive Hill-Climbing
|
|
76
|
+
*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.*
|
|
77
|
+
|
|
78
|
+
The optimization loop creates an initial `ContextSet` and then iteratively refines it using evaluation feedback:
|
|
79
|
+
|
|
80
|
+
1. **Bootstrap**: Generate an initial baseline context.
|
|
81
|
+
2. **Evaluate**: Measure context effectiveness against a golden dataset.
|
|
82
|
+
3. **Hill-Climbing**: Perform gap analysis on failures and generate automated fixes.
|
|
83
|
+
4. **Iterate**: Apply the improved context and re-run evaluation to continuously improve quality.
|
|
84
|
+
5. **Final Validation** (Optional): Verify mutations against a separated test set to ensure generalization and prevent overfitting.
|
|
85
|
+
|
|
86
|
+
*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`.*
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Bring Artifacts via Filesystem or MCP
|
|
91
|
+
|
|
92
|
+
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**.
|
|
93
|
+
|
|
94
|
+
You can provide business artifacts directly to the agent from local filesystems or via **Model Context Protocol (MCP) Servers**.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Installing via a compatible Agent Plugins client
|
|
99
|
+
|
|
100
|
+
This repository ships a valid [Agent Plugins](https://github.com/agentplugins/agent-plugins-spec) (v1) plugin under [`plugin/`](plugin/), bundling both agent skills and its MCP servers. Any [Agent Plugins–compatible client](https://agent-plugins.org/compatible-clients) (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:
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
https://github.com/GoogleCloudPlatform/db-context-enrichment
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
See your agent's documentation for its exact install command.
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## How to Use
|
|
111
|
+
|
|
112
|
+
Launch your agent harness (Gemini CLI, Claude Code, or Antigravity) in your workspace directory and interact in natural language:
|
|
113
|
+
|
|
114
|
+
### Example Natural Language Prompts
|
|
115
|
+
* **End-to-End**: (From the app directory) *"Optimize context for my app."*
|
|
116
|
+
* **Dataset Curation**: *"Expand my dataset with app changes in `<PULL_REQUEST_LINK>`."*
|
|
117
|
+
* **Ad-hoc Evaluation**: *"Evaluate accuracy of QueryData with `ContextSet` `<context_set_id>` on dataset.json."*
|
|
118
|
+
* **Targeted Authoring**: *"Add a facet for active premium subscriptions."*
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
> 🛠️ **Developer Note**: For developer setup instructions, local CLI linking, unit testing (`pytest`), linting (`ruff`), and fork release testing, see [docs/development.md](docs/development.md).
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
This is not an officially supported Google product. This project is not eligible for the [Google Open Source Software Vulnerability Rewards Program](https://bughunters.google.com/open-source-security), [Google Cloud Platform/SecOps Terms of Service](https://cloud.google.com/terms), [How Gemini for Google Cloud uses your data](https://cloud.google.com/gemini/docs/discover/data-governance). 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.
|
|
2
|
+
|
|
3
|
+
# Context Engineering Agent
|
|
4
|
+
|
|
5
|
+
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](https://docs.cloud.google.com/gemini/data-agents/querydata/alloydb/data-agent-overview) | Cloud SQL: [PostgreSQL](https://docs.cloud.google.com/gemini/data-agents/querydata/sql-postgres/data-agent-overview) / [MySQL](https://docs.cloud.google.com/gemini/data-agents/querydata/sql-mysql/data-agent-overview) | [Spanner (GoogleSQL)](https://docs.cloud.google.com/gemini/data-agents/querydata/spanner/data-agent-overview)).
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Why Context Engineering?
|
|
10
|
+
|
|
11
|
+
When building data agents and natural language analytics interfaces, accurately translating user intent into database queries is critical.
|
|
12
|
+
|
|
13
|
+
As outlined in **Build Context with Context Engineering Agent** ([AlloyDB](https://docs.cloud.google.com/gemini/data-agents/querydata/alloydb/build-context-gemini-cli) | Cloud SQL: [PostgreSQL](https://docs.cloud.google.com/gemini/data-agents/querydata/sql-postgres/build-context-gemini-cli) / [MySQL](https://docs.cloud.google.com/gemini/data-agents/querydata/sql-mysql/build-context-gemini-cli) | [Spanner (GoogleSQL)](https://docs.cloud.google.com/gemini/data-agents/querydata/spanner/build-context-gemini-cli)), 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**.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Core Concepts
|
|
18
|
+
|
|
19
|
+
A `ContextSet` is the central artifact generated and managed by the agent, containing structured knowledge in three primary forms:
|
|
20
|
+
|
|
21
|
+
* **Templates**: Link natural language query patterns to complete query statements.
|
|
22
|
+
* **Facets**: Reusable, modular query fragments (e.g., parameterized `WHERE` clauses or specialized join filters) linked to domain vocabulary.
|
|
23
|
+
* **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.
|
|
24
|
+
|
|
25
|
+
For full schema details, structure specifications, and dialect-specific JSON representations of `ContextSets`, see the official **Context Sets Overview** ([AlloyDB](https://docs.cloud.google.com/gemini/data-agents/querydata/alloydb/context-sets-overview) | Cloud SQL: [PostgreSQL](https://docs.cloud.google.com/gemini/data-agents/querydata/sql-postgres/context-sets-overview) / [MySQL](https://docs.cloud.google.com/gemini/data-agents/querydata/sql-mysql/context-sets-overview) | [Spanner (GoogleSQL)](https://docs.cloud.google.com/gemini/data-agents/querydata/spanner/context-sets-overview)).
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Prerequisites & Environment Setup
|
|
30
|
+
|
|
31
|
+
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.
|
|
32
|
+
|
|
33
|
+
Follow the step-by-step setup guide in the official documentation:
|
|
34
|
+
👉 **Prepare Your Environment**: ([AlloyDB](https://docs.cloud.google.com/gemini/data-agents/querydata/alloydb/build-context-gemini-cli#prepare-your-environment) | Cloud SQL: [PostgreSQL](https://docs.cloud.google.com/gemini/data-agents/querydata/sql-postgres/build-context-gemini-cli#prepare-your-environment) / [MySQL](https://docs.cloud.google.com/gemini/data-agents/querydata/sql-mysql/build-context-gemini-cli#prepare-your-environment) | [Spanner (GoogleSQL)](https://docs.cloud.google.com/gemini/data-agents/querydata/spanner/build-context-gemini-cli#prepare-your-environment))
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Primary Workflow Phases
|
|
39
|
+
|
|
40
|
+
The agent enables you to craft an optimized context for QueryData API through three primary phases:
|
|
41
|
+
|
|
42
|
+
### Phase 1: Artifact Ingestion
|
|
43
|
+
*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.*
|
|
44
|
+
|
|
45
|
+
1. **Connect & Discover**: Inspect any resources shared with the agent that may be relevant to your application and its domain.
|
|
46
|
+
2. **Domain Concept Extraction**: Extract key terminology, domain rules, jargon, and common query patterns.
|
|
47
|
+
3. **Schema Mapping**: Map extracted concepts directly to their corresponding underlying database tables and columns.
|
|
48
|
+
|
|
49
|
+
### Phase 2: Dataset Creation
|
|
50
|
+
*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.*
|
|
51
|
+
|
|
52
|
+
1. **Dataset Planning**: Set goals for your dataset, deciding on question difficulty, business topics to cover, and total dataset size.
|
|
53
|
+
2. **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.
|
|
54
|
+
3. **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.
|
|
55
|
+
4. **Dataset Validation**: Audit the full dataset against your original plan and ask for your approval before proceeding.
|
|
56
|
+
|
|
57
|
+
### Phase 3: Context Optimization via Recursive Hill-Climbing
|
|
58
|
+
*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.*
|
|
59
|
+
|
|
60
|
+
The optimization loop creates an initial `ContextSet` and then iteratively refines it using evaluation feedback:
|
|
61
|
+
|
|
62
|
+
1. **Bootstrap**: Generate an initial baseline context.
|
|
63
|
+
2. **Evaluate**: Measure context effectiveness against a golden dataset.
|
|
64
|
+
3. **Hill-Climbing**: Perform gap analysis on failures and generate automated fixes.
|
|
65
|
+
4. **Iterate**: Apply the improved context and re-run evaluation to continuously improve quality.
|
|
66
|
+
5. **Final Validation** (Optional): Verify mutations against a separated test set to ensure generalization and prevent overfitting.
|
|
67
|
+
|
|
68
|
+
*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`.*
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Bring Artifacts via Filesystem or MCP
|
|
73
|
+
|
|
74
|
+
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**.
|
|
75
|
+
|
|
76
|
+
You can provide business artifacts directly to the agent from local filesystems or via **Model Context Protocol (MCP) Servers**.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Installing via a compatible Agent Plugins client
|
|
81
|
+
|
|
82
|
+
This repository ships a valid [Agent Plugins](https://github.com/agentplugins/agent-plugins-spec) (v1) plugin under [`plugin/`](plugin/), bundling both agent skills and its MCP servers. Any [Agent Plugins–compatible client](https://agent-plugins.org/compatible-clients) (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:
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
https://github.com/GoogleCloudPlatform/db-context-enrichment
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
See your agent's documentation for its exact install command.
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## How to Use
|
|
93
|
+
|
|
94
|
+
Launch your agent harness (Gemini CLI, Claude Code, or Antigravity) in your workspace directory and interact in natural language:
|
|
95
|
+
|
|
96
|
+
### Example Natural Language Prompts
|
|
97
|
+
* **End-to-End**: (From the app directory) *"Optimize context for my app."*
|
|
98
|
+
* **Dataset Curation**: *"Expand my dataset with app changes in `<PULL_REQUEST_LINK>`."*
|
|
99
|
+
* **Ad-hoc Evaluation**: *"Evaluate accuracy of QueryData with `ContextSet` `<context_set_id>` on dataset.json."*
|
|
100
|
+
* **Targeted Authoring**: *"Add a facet for active premium subscriptions."*
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
> 🛠️ **Developer Note**: For developer setup instructions, local CLI linking, unit testing (`pytest`), linting (`ruff`), and fork release testing, see [docs/development.md](docs/development.md).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "google-cloud-db-context-engineering"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.7.1"
|
|
4
4
|
description = "A FastMCP server for generating natural language to SQL templates from database schemas."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.12"
|
|
@@ -10,6 +10,8 @@ dependencies = [
|
|
|
10
10
|
"google-genai==1.46.0",
|
|
11
11
|
"toolbox-core==0.5.2",
|
|
12
12
|
"google-cloud-geminidataanalytics==0.11.0",
|
|
13
|
+
"google-auth==2.41.1",
|
|
14
|
+
"requests==2.33.0",
|
|
13
15
|
]
|
|
14
16
|
|
|
15
17
|
[project.scripts]
|
|
@@ -44,7 +46,7 @@ dev = [
|
|
|
44
46
|
|
|
45
47
|
[tool.db-context-engineering]
|
|
46
48
|
toolbox_version = "1.4.0"
|
|
47
|
-
evalbench_version = "1.
|
|
49
|
+
evalbench_version = "1.12.0"
|
|
48
50
|
|
|
49
51
|
[tool.ruff]
|
|
50
52
|
line-length = 88
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"""REST client for the Context Store API.
|
|
2
|
+
|
|
3
|
+
Hand-rolled because the service is GOOGLE_INTERNAL and has no public SDK.
|
|
4
|
+
All calls target the autopush sandbox endpoint pinned in this module.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
import time
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
import google.auth
|
|
12
|
+
import google.auth.exceptions
|
|
13
|
+
import requests
|
|
14
|
+
from google.auth.transport import requests as auth_requests
|
|
15
|
+
|
|
16
|
+
from google.cloud.db_context_enrichment.model import context
|
|
17
|
+
|
|
18
|
+
CONTEXT_STORE_ENDPOINT = "https://autopush-dataplex.sandbox.googleapis.com"
|
|
19
|
+
CONTEXT_STORE_LOCATION = "us-central1"
|
|
20
|
+
API_VERSION = "v1"
|
|
21
|
+
DEFAULT_OAUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",)
|
|
22
|
+
|
|
23
|
+
# Per-request HTTP timeout + LRO poll schedule. Transient-error retry is
|
|
24
|
+
# intentionally NOT done here — the MCP agent driving these tools retries
|
|
25
|
+
# failed tool calls on its own, and the Cloud SDK (once available) will bring
|
|
26
|
+
# proper retry back. Only the per-call timeout and op polling stay in this
|
|
27
|
+
# hand-rolled client.
|
|
28
|
+
_LRO_POLL_INTERVALS_SECONDS = (2.0, 4.0, 8.0, 16.0, 16.0, 16.0)
|
|
29
|
+
_REQUEST_TIMEOUT_SECONDS = 30
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ContextStoreClient:
|
|
33
|
+
"""REST client for the Context Store API (autopush sandbox).
|
|
34
|
+
|
|
35
|
+
The client is stateless w.r.t. project. Operations that build a resource
|
|
36
|
+
path from IDs (`ensure_*`) take `project_id` as an explicit argument;
|
|
37
|
+
operations that take a fully-qualified resource name don't need it.
|
|
38
|
+
|
|
39
|
+
The quota project (billing / quota) is always taken from ADC's
|
|
40
|
+
`quota_project_id` and sent as `X-Goog-User-Project` on every request.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
def __init__(self):
|
|
44
|
+
try:
|
|
45
|
+
credentials, _ = google.auth.default(scopes=DEFAULT_OAUTH_SCOPES)
|
|
46
|
+
except google.auth.exceptions.DefaultCredentialsError as e:
|
|
47
|
+
raise RuntimeError(
|
|
48
|
+
"No Application Default Credentials found. Run "
|
|
49
|
+
"'gcloud auth application-default login' first."
|
|
50
|
+
) from e
|
|
51
|
+
if not credentials.quota_project_id:
|
|
52
|
+
raise RuntimeError(
|
|
53
|
+
"No quota project set. Run "
|
|
54
|
+
"'gcloud auth application-default set-quota-project <PROJECT_ID>'."
|
|
55
|
+
)
|
|
56
|
+
self._session = auth_requests.AuthorizedSession(credentials)
|
|
57
|
+
self._session.headers["X-Goog-User-Project"] = credentials.quota_project_id
|
|
58
|
+
|
|
59
|
+
def ensure_context_set_group(self, project_id: str, csg_id: str) -> str:
|
|
60
|
+
"""Return a CSG's full resource name, creating it if absent.
|
|
61
|
+
|
|
62
|
+
Idempotent: a 409 (already exists, whether pre-existing or from a
|
|
63
|
+
concurrent create) is treated as success.
|
|
64
|
+
"""
|
|
65
|
+
parent = f"projects/{project_id}/locations/{CONTEXT_STORE_LOCATION}"
|
|
66
|
+
create_url = (
|
|
67
|
+
f"{CONTEXT_STORE_ENDPOINT}/{API_VERSION}/{parent}/contextSetGroups"
|
|
68
|
+
f"?context_set_group_id={csg_id}"
|
|
69
|
+
)
|
|
70
|
+
try:
|
|
71
|
+
self._request_lro("POST", create_url, json_body={})
|
|
72
|
+
except requests.HTTPError as e:
|
|
73
|
+
if e.response.status_code != 409:
|
|
74
|
+
raise
|
|
75
|
+
return f"{parent}/contextSetGroups/{csg_id}"
|
|
76
|
+
|
|
77
|
+
def delete_context_set_group(self, csg_resource_name: str) -> None:
|
|
78
|
+
"""Delete a ContextSetGroup by full resource name. Blocks on LRO.
|
|
79
|
+
|
|
80
|
+
Idempotent: a 404 (already deleted or never existed) is treated as
|
|
81
|
+
success. Cascades: all ContextSets inside the group are also deleted.
|
|
82
|
+
"""
|
|
83
|
+
try:
|
|
84
|
+
self._request_lro(
|
|
85
|
+
"DELETE", f"{CONTEXT_STORE_ENDPOINT}/{API_VERSION}/{csg_resource_name}"
|
|
86
|
+
)
|
|
87
|
+
except requests.HTTPError as e:
|
|
88
|
+
if e.response.status_code != 404:
|
|
89
|
+
raise
|
|
90
|
+
|
|
91
|
+
def ensure_context_set(
|
|
92
|
+
self, project_id: str, csg_id: str, cs_id: str, version: str
|
|
93
|
+
) -> str:
|
|
94
|
+
"""Return a CS's full resource name, creating it (and the parent CSG)
|
|
95
|
+
if absent.
|
|
96
|
+
|
|
97
|
+
Idempotent: a 409 on the CS create is treated as success. Body is not
|
|
98
|
+
touched — the caller still needs `upload_context_set` to overwrite it.
|
|
99
|
+
"""
|
|
100
|
+
csg_resource_name = self.ensure_context_set_group(project_id, csg_id)
|
|
101
|
+
url = (
|
|
102
|
+
f"{CONTEXT_STORE_ENDPOINT}/{API_VERSION}/{csg_resource_name}/contextSets"
|
|
103
|
+
f"?context_set_id={cs_id}"
|
|
104
|
+
)
|
|
105
|
+
body = {"context_set_id": cs_id, "version": version}
|
|
106
|
+
try:
|
|
107
|
+
self._request("POST", url, json_body=body)
|
|
108
|
+
except requests.HTTPError as e:
|
|
109
|
+
if e.response.status_code != 409:
|
|
110
|
+
raise
|
|
111
|
+
return f"{csg_resource_name}/contextSets/{cs_id}@{version}"
|
|
112
|
+
|
|
113
|
+
def upload_context_set(
|
|
114
|
+
self, cs_resource_name: str, ctx: context.ContextSet
|
|
115
|
+
) -> None:
|
|
116
|
+
"""Populate an existing ContextSet's body.
|
|
117
|
+
|
|
118
|
+
The resource must already exist (call `ensure_context_set` first).
|
|
119
|
+
"""
|
|
120
|
+
url = f"{CONTEXT_STORE_ENDPOINT}/{API_VERSION}/{cs_resource_name}:upload"
|
|
121
|
+
body = {"context_json": ctx.model_dump_json(exclude_none=True)}
|
|
122
|
+
self._request("POST", url, json_body=body)
|
|
123
|
+
|
|
124
|
+
def download_context_set(self, cs_resource_name: str) -> context.ContextSet:
|
|
125
|
+
"""Download and parse a ContextSet by full resource name."""
|
|
126
|
+
url = f"{CONTEXT_STORE_ENDPOINT}/{API_VERSION}/{cs_resource_name}:download"
|
|
127
|
+
resp = self._request("POST", url, json_body={})
|
|
128
|
+
raw = resp.get("contextJson")
|
|
129
|
+
if raw is None:
|
|
130
|
+
raise ValueError(f"DownloadContextSet response missing contextJson: {resp}")
|
|
131
|
+
# ContextSet models accept camelCase aliases too (see
|
|
132
|
+
# `_BaseContextModel`), so the server's mixed casing validates
|
|
133
|
+
# without conversion.
|
|
134
|
+
return context.ContextSet.model_validate(json.loads(raw))
|
|
135
|
+
|
|
136
|
+
def _request(
|
|
137
|
+
self,
|
|
138
|
+
method: str,
|
|
139
|
+
url: str,
|
|
140
|
+
json_body: dict[str, Any] | None = None,
|
|
141
|
+
) -> dict[str, Any]:
|
|
142
|
+
"""Send one HTTP request and return parsed JSON.
|
|
143
|
+
|
|
144
|
+
Returns an empty dict if the response body is empty (eg. 204 No
|
|
145
|
+
Content). Raises `requests.HTTPError` on 4xx/5xx,
|
|
146
|
+
`requests.RequestException` on network failure.
|
|
147
|
+
"""
|
|
148
|
+
response = self._session.request(
|
|
149
|
+
method, url, json=json_body, timeout=_REQUEST_TIMEOUT_SECONDS
|
|
150
|
+
)
|
|
151
|
+
response.raise_for_status()
|
|
152
|
+
return response.json() if response.content else {}
|
|
153
|
+
|
|
154
|
+
def _request_lro(
|
|
155
|
+
self,
|
|
156
|
+
method: str,
|
|
157
|
+
url: str,
|
|
158
|
+
json_body: dict[str, Any] | None = None,
|
|
159
|
+
) -> dict[str, Any]:
|
|
160
|
+
"""Issue a request that returns an LRO and poll until it completes.
|
|
161
|
+
|
|
162
|
+
- HTTP layer (`_request`): each call returns 200; raises on 4xx/5xx.
|
|
163
|
+
- Op layer: `done` / `response` / `error` live in the JSON body, not
|
|
164
|
+
the HTTP status.
|
|
165
|
+
- Sleeps per `_LRO_POLL_INTERVALS_SECONDS`; raises `TimeoutError`
|
|
166
|
+
on budget exhaustion or `RuntimeError` on op-reported error.
|
|
167
|
+
"""
|
|
168
|
+
op = self._request(method, url, json_body=json_body)
|
|
169
|
+
op_name = op.get("name")
|
|
170
|
+
if not op_name:
|
|
171
|
+
raise RuntimeError(f"{method} {url} returned no operation name: {op}")
|
|
172
|
+
|
|
173
|
+
# Skip the poll cycle if the initial op is already done (some LROs
|
|
174
|
+
# complete synchronously). Otherwise poll until it does or the
|
|
175
|
+
# budget is exhausted.
|
|
176
|
+
poll_url = f"{CONTEXT_STORE_ENDPOINT}/{API_VERSION}/{op_name}"
|
|
177
|
+
for delay in _LRO_POLL_INTERVALS_SECONDS:
|
|
178
|
+
if op.get("done"):
|
|
179
|
+
break
|
|
180
|
+
time.sleep(delay)
|
|
181
|
+
op = self._request("GET", poll_url)
|
|
182
|
+
if not op.get("done"):
|
|
183
|
+
raise TimeoutError(f"LRO {op_name} did not complete within the poll budget")
|
|
184
|
+
if "error" in op:
|
|
185
|
+
err = op["error"]
|
|
186
|
+
raise RuntimeError(
|
|
187
|
+
f"LRO {op_name} failed: [{err.get('code')}] "
|
|
188
|
+
f"{err.get('message', 'unknown LRO error')}"
|
|
189
|
+
)
|
|
190
|
+
return op.get("response", {})
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
from typing import Any
|
|
2
2
|
|
|
3
|
-
import google.cloud.geminidataanalytics_v1beta as gda
|
|
4
3
|
import yaml
|
|
5
4
|
|
|
6
5
|
from .base import BaseDBConfigGenerator
|
|
@@ -52,21 +51,20 @@ class AlloyDBConfigGenerator(BaseDBConfigGenerator):
|
|
|
52
51
|
db_config, sort_keys=False, default_flow_style=False
|
|
53
52
|
).strip()
|
|
54
53
|
|
|
55
|
-
def build_datasource_reference(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
agent_context_reference=
|
|
69
|
-
context_set_id
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return datasource_ref
|
|
54
|
+
def build_datasource_reference(self, context_set_id: str) -> dict[str, Any]:
|
|
55
|
+
ref: dict[str, Any] = {
|
|
56
|
+
"alloydb": {
|
|
57
|
+
"database_reference": {
|
|
58
|
+
"project_id": self.project,
|
|
59
|
+
"region": self.region,
|
|
60
|
+
"cluster_id": self.cluster,
|
|
61
|
+
"instance_id": self.instance,
|
|
62
|
+
"database_id": self.database,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if context_set_id:
|
|
67
|
+
ref["alloydb"]["agent_context_reference"] = {
|
|
68
|
+
"context_set_id": context_set_id
|
|
69
|
+
}
|
|
70
|
+
return ref
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
2
|
from typing import Any
|
|
3
3
|
|
|
4
|
-
import google.cloud.geminidataanalytics_v1beta as gda
|
|
5
4
|
import yaml
|
|
6
|
-
from google.protobuf.json_format import MessageToDict
|
|
7
5
|
|
|
8
6
|
|
|
9
7
|
class BaseDBConfigGenerator(ABC):
|
|
10
8
|
"""
|
|
11
9
|
Abstract Base Class enforcing the construction contract for Evalbench database topologies.
|
|
12
10
|
Each distinct DB type (Spanner, Postgres, AlloyDB, MySQL) must inherit and implement
|
|
13
|
-
the mappings required by both the standard EvalBench framework and the GDA
|
|
11
|
+
the mappings required by both the standard EvalBench framework and the GDA REST API.
|
|
14
12
|
"""
|
|
15
13
|
|
|
16
14
|
SOURCE_TYPE = "unknown"
|
|
@@ -29,11 +27,9 @@ class BaseDBConfigGenerator(ABC):
|
|
|
29
27
|
raise NotImplementedError("Subclasses must implement generate_db_config")
|
|
30
28
|
|
|
31
29
|
@abstractmethod
|
|
32
|
-
def build_datasource_reference(
|
|
33
|
-
self, context_set_id: str
|
|
34
|
-
) -> gda.DatasourceReferences:
|
|
30
|
+
def build_datasource_reference(self, context_set_id: str) -> dict[str, Any]:
|
|
35
31
|
"""
|
|
36
|
-
Constructs the
|
|
32
|
+
Constructs the REST datasource_references dictionary required by the QueryDataAPI
|
|
37
33
|
context generation flow.
|
|
38
34
|
"""
|
|
39
35
|
raise NotImplementedError(
|
|
@@ -54,23 +50,21 @@ class BaseDBConfigGenerator(ABC):
|
|
|
54
50
|
|
|
55
51
|
def generate_model_config(self, context_set_id: str) -> str:
|
|
56
52
|
"""
|
|
57
|
-
Standardized Model Builder converting the
|
|
53
|
+
Standardized Model Builder converting the datasource reference dict into an EvalBench model dict.
|
|
58
54
|
"""
|
|
59
55
|
datasource_ref = self.build_datasource_reference(context_set_id)
|
|
60
56
|
|
|
61
|
-
query_context = gda.QueryDataContext(datasource_references=datasource_ref)
|
|
62
|
-
|
|
63
|
-
query_context_dict = MessageToDict(
|
|
64
|
-
query_context._pb, preserving_proto_field_name=True
|
|
65
|
-
)
|
|
66
|
-
|
|
67
57
|
model_config = {
|
|
68
58
|
"generator": "query_data_api",
|
|
69
59
|
"project_id": self.params.get("project"),
|
|
70
60
|
"location": self.params.get("region") or "global",
|
|
71
|
-
"
|
|
61
|
+
"use_rest_api": True,
|
|
62
|
+
"context": {"datasource_references": datasource_ref},
|
|
72
63
|
}
|
|
73
64
|
|
|
65
|
+
if self.params.get("api_endpoint"):
|
|
66
|
+
model_config["api_endpoint"] = self.params.get("api_endpoint")
|
|
67
|
+
|
|
74
68
|
return yaml.safe_dump(
|
|
75
69
|
model_config, sort_keys=False, default_flow_style=False
|
|
76
70
|
).strip()
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
from typing import Any
|
|
2
2
|
|
|
3
|
-
import google.cloud.geminidataanalytics_v1beta as gda
|
|
4
3
|
import yaml
|
|
5
4
|
|
|
6
5
|
from .base import BaseDBConfigGenerator
|
|
@@ -49,21 +48,20 @@ class MySQLConfigGenerator(BaseDBConfigGenerator):
|
|
|
49
48
|
db_config, sort_keys=False, default_flow_style=False
|
|
50
49
|
).strip()
|
|
51
50
|
|
|
52
|
-
def build_datasource_reference(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
agent_context_reference=
|
|
66
|
-
context_set_id
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return datasource_ref
|
|
51
|
+
def build_datasource_reference(self, context_set_id: str) -> dict[str, Any]:
|
|
52
|
+
ref: dict[str, Any] = {
|
|
53
|
+
"cloud_sql_reference": {
|
|
54
|
+
"database_reference": {
|
|
55
|
+
"engine": "MYSQL",
|
|
56
|
+
"project_id": self.project,
|
|
57
|
+
"region": self.region,
|
|
58
|
+
"instance_id": self.instance,
|
|
59
|
+
"database_id": self.database,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if context_set_id:
|
|
64
|
+
ref["cloud_sql_reference"]["agent_context_reference"] = {
|
|
65
|
+
"context_set_id": context_set_id
|
|
66
|
+
}
|
|
67
|
+
return ref
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
from typing import Any
|
|
2
2
|
|
|
3
|
-
import google.cloud.geminidataanalytics_v1beta as gda
|
|
4
3
|
import yaml
|
|
5
4
|
|
|
6
5
|
from .base import BaseDBConfigGenerator
|
|
@@ -49,21 +48,20 @@ class PostgresConfigGenerator(BaseDBConfigGenerator):
|
|
|
49
48
|
db_config, sort_keys=False, default_flow_style=False
|
|
50
49
|
).strip()
|
|
51
50
|
|
|
52
|
-
def build_datasource_reference(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
agent_context_reference=
|
|
66
|
-
context_set_id
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return datasource_ref
|
|
51
|
+
def build_datasource_reference(self, context_set_id: str) -> dict[str, Any]:
|
|
52
|
+
ref: dict[str, Any] = {
|
|
53
|
+
"cloud_sql_reference": {
|
|
54
|
+
"database_reference": {
|
|
55
|
+
"engine": "POSTGRESQL",
|
|
56
|
+
"project_id": self.project,
|
|
57
|
+
"region": self.region,
|
|
58
|
+
"instance_id": self.instance,
|
|
59
|
+
"database_id": self.database,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if context_set_id:
|
|
64
|
+
ref["cloud_sql_reference"]["agent_context_reference"] = {
|
|
65
|
+
"context_set_id": context_set_id
|
|
66
|
+
}
|
|
67
|
+
return ref
|