Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions alloydb-ai-nla/data_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def call_querydata_api(
"generationOptions": {
"generateNaturalLanguageAnswer": True,
"generateQueryResult": True,
"generateExplanation": True
"generateExplanation": True,
"generateDisambiguationQuestion": True

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are making this default soon.

}
}

Expand All @@ -137,7 +138,7 @@ def call_querydata_api(
skills=[database_query_skill]
)

MODEL_ID = "gemini-3.6-flash"
MODEL_ID = "gemini-3.5-flash"

# Agent configuration

Expand Down
2 changes: 1 addition & 1 deletion alloydb-ai-nla/data_agent/env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GOOGLE_GENAI_USE_VERTEXAI=true
GOOGLE_GENAI_USE_ENTERPRISE=true
GOOGLE_CLOUD_PROJECT=my-test-project
GOOGLE_CLOUD_LOCATION=global
QUERYDATA_CONTEXTSET=projects/my-test-project/locations/us-east1/contextSets/sixrecipes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ curl -X POST "https://geminidataanalytics.googleapis.com/v1beta/projects/${GOOGL
\"generationOptions\": {
\"generateNaturalLanguageAnswer\": true,
\"generateQueryResult\": true,
\"generateExplanation\": true
\"generateExplanation\": true,
\"generateDisambiguationQuestion\": true
}
}"
```
Expand Down
22 changes: 8 additions & 14 deletions alloydb-ai-nla/real_estate_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ CREATE TABLE real_estate.offers (
FOREIGN KEY (seller_agent_id)
REFERENCES real_estate.agents(agent_id)
);


-- Populating municipalities
INSERT INTO real_estate.municipalities (municipality_name, average_school_ranking, crime_rate_per_100k) VALUES
('Waterloo', 8.50, 2900.50),
Expand All @@ -121,14 +119,13 @@ INSERT INTO real_estate.cities (municipality_id, city_name, city_province) VALUE
(8, 'Westwood', 'California');
-- Populating agents
INSERT INTO real_estate.agents (firstname, lastname, email, phone, brokerage, is_active) VALUES
('Liam', 'O''Connell', 'liam.oconnell@broker.ca', '519-555-0011', 'KW Realty', TRUE),
('Aisha', 'Patel', 'aisha.patel@broker.com', '408-555-0022', 'Silicon Valley Homes', TRUE),
('Ben', 'Chen', 'ben.chen@broker.ca', '519-555-0033', 'KW Realty', TRUE),
('Chloe', 'Davis', 'chloe.davis@broker.com', '951-555-0044', 'Riverside Estates', TRUE),
('David', 'Kim', 'david.kim@broker.com', '619-555-0055', 'Pacific Coast Homes', TRUE),
('Sarah', 'Miller', 'sarah.miller@broker.com', '858-555-0066', 'Coastal Luxury Group', TRUE),
('Chris', 'Foster', 'chris.foster@westwood.com', '310-555-0077', 'Westwood', TRUE);

('Liam', 'O''Connell', 'liam.oconnell@example.com', '519-555-0011', 'KW Realty', TRUE),
('Aisha', 'Patel', 'aisha.patel@example.com', '408-555-0022', 'Silicon Valley Homes', TRUE),
('Ben', 'Chen', 'ben.chen@example.com', '519-555-0033', 'KW Realty', TRUE),
('Chloe', 'Davis', 'chloe.davis@example.com', '951-555-0044', 'Riverside Estates', TRUE),
('David', 'Kim', 'david.kim@example.com', '619-555-0055', 'Pacific Coast Homes', TRUE),
('Sarah', 'Miller', 'sarah.miller@example.com', '858-555-0066', 'Coastal Luxury Group', TRUE),
('Chris', 'Foster', 'chris.foster@example.com', '310-555-0077', 'Westwood', TRUE);
-- Populating properties
INSERT INTO real_estate.properties (property_id, address_street, city_id, address_postal_code, price, bedrooms, bathrooms, listing_status, is_single_family, is_condo, has_garage, num_stories) VALUES
(1, '123 University Ave W', 1, 'N2L 3G7', 750000.00, 3, 2.5, 'Active', FALSE, FALSE, TRUE, 2),
Expand Down Expand Up @@ -163,8 +160,6 @@ INSERT INTO real_estate.properties (property_id, address_street, city_id, addres
(30, '450 Veteran Ave', 7, '90024', 3800000.00, 4, 3.5, 'Pending', TRUE, FALSE, TRUE, 2),
(31, '999 Main Ave', 6, '90024', 3800000.00, 4, 3.5, 'Active', TRUE, FALSE, TRUE, 1),
(32, '999 Main St', 8, '99999', 3800000.00, 4, 3.5, 'Sold', TRUE, FALSE, TRUE, 1);


-- ID 3: Waterfront (Lake/River, updated to panoramic vista)
UPDATE real_estate.properties
SET description = 'Spacious 4-bedroom executive home on a half-acre lot. This beautiful property features an unobstructed, panoramic view of the lake, offering a truly breathtaking lifestyle. Includes two fireplaces and a triple garage.'
Expand Down Expand Up @@ -242,8 +237,7 @@ INSERT INTO real_estate.property_transactions (property_id, sale_date, sale_pric
(10, '2025-09-01', 550000.00, 4),
(18, '2025-08-28', 610000.00, 4),
(27, '2025-10-10', 6450000.00, 6),
(30, '2025-09-30', 3800000.00, 7),
(32, '2025-09-12', 1000000, 7);
(30, '2025-09-30', 3800000.00, 7);
-- Populating offers
INSERT INTO real_estate.offers (offer_id, property_id, buyer_agent_id, seller_agent_id, offer_amount, offer_date, offer_status, offer_expiration_date, contingencies) VALUES
(1, 3, 3, 1, 1250000.00, '2025-05-18', 'ACCEPTED', '2025-05-20', 'Clear closing in 5 days'),
Expand Down
6 changes: 3 additions & 3 deletions alloydb-ai-nla/sixrecipe_context1_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
{
"nl_query": "Riverside houses close to good schools.",
"sql": "SELECT \"p\".\"address_street\", \"p\".\"address_postal_code\", \"s\".\"school_name\", \"stp\".\"proximity_miles\" FROM \"real_estate\".\"properties\" AS \"p\" JOIN \"real_estate\".\"cities\" AS \"c\" ON \"p\".\"city_id\" = \"c\".\"city_id\" JOIN \"real_estate\".\"school_to_property\" AS \"stp\" ON \"p\".\"property_id\" = \"stp\".\"property_id\" JOIN \"real_estate\".\"schools\" AS \"s\" ON \"stp\".\"school_id\" = \"s\".\"school_id\" WHERE \"c\".\"city_name\" = 'Riverside' AND \"s\".\"school_ranking\" <= 5 AND \"stp\".\"proximity_miles\" <= 2 ORDER BY 0.8 * \"s\".\"school_ranking\" + 0.2 * \"stp\".\"proximity_miles\"",
"intent": "Riverside houses close to good schools.",
"intent": "Houses in Riverside close to good schools (within 2 miles of schools with a rank of at least 5).",
"manifest": "A given city houses close to good schools.",
"parameterized": {
"parameterized_intent": "$1 houses close to good schools.",
"parameterized_intent": "Houses in $1 close to good schools (within 2 miles of schools with a rank of at least 5).",
"parameterized_sql": "SELECT \"p\".\"address_street\", \"p\".\"address_postal_code\", \"s\".\"school_name\", \"stp\".\"proximity_miles\" FROM \"real_estate\".\"properties\" AS \"p\" JOIN \"real_estate\".\"cities\" AS \"c\" ON \"p\".\"city_id\" = \"c\".\"city_id\" JOIN \"real_estate\".\"school_to_property\" AS \"stp\" ON \"p\".\"property_id\" = \"stp\".\"property_id\" JOIN \"real_estate\".\"schools\" AS \"s\" ON \"stp\".\"school_id\" = \"s\".\"school_id\" WHERE \"c\".\"city_name\" = $1 AND \"s\".\"school_ranking\" <= 5 AND \"stp\".\"proximity_miles\" <= 2 ORDER BY 0.8 * \"s\".\"school_ranking\" + 0.2 * \"stp\".\"proximity_miles\""
}
}
]
}
}
6 changes: 3 additions & 3 deletions alloydb-ai-nla/sixrecipe_context1_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
{
"nl_query": "Riverside houses close to good schools, or are great for families with kids.",
"sql": "SELECT \"p\".\"address_street\", \"s\".\"school_name\", \"stp\".\"proximity_miles\" FROM \"real_estate\".\"properties\" AS \"p\" JOIN \"real_estate\".\"cities\" AS \"c\" ON \"p\".\"city_id\" = \"c\".\"city_id\" JOIN \"real_estate\".\"school_to_property\" AS \"stp\" ON \"p\".\"property_id\" = \"stp\".\"property_id\" JOIN \"real_estate\".\"schools\" AS \"s\" ON \"stp\".\"school_id\" = \"s\".\"school_id\" WHERE \"c\".\"city_name\" = 'Riverside' AND \"s\".\"school_ranking\" <= 5 AND \"stp\".\"proximity_miles\" <= 2 ORDER BY 0.8 * \"s\".\"school_ranking\" + 0.2 * \"stp\".\"proximity_miles\"",
"intent": "Riverside houses close to good schools.",
"intent": "Houses in Riverside close to good schools (within 2 miles of schools with a rank of at least 5).",
"manifest": "A given city houses close to good schools, or are great for families with kids.",
"parameterized": {
"parameterized_intent": "$1 houses close to good schools.",
"parameterized_intent": "Houses in $1 close to good schools (within 2 miles of schools with a rank of at least 5).",
"parameterized_sql": "SELECT \"p\".\"address_street\", \"s\".\"school_name\", \"stp\".\"proximity_miles\" FROM \"real_estate\".\"properties\" AS \"p\" JOIN \"real_estate\".\"cities\" AS \"c\" ON \"p\".\"city_id\" = \"c\".\"city_id\" JOIN \"real_estate\".\"school_to_property\" AS \"stp\" ON \"p\".\"property_id\" = \"stp\".\"property_id\" JOIN \"real_estate\".\"schools\" AS \"s\" ON \"stp\".\"school_id\" = \"s\".\"school_id\" WHERE \"c\".\"city_name\" = $1 AND \"s\".\"school_ranking\" <= 5 AND \"stp\".\"proximity_miles\" <= 2 ORDER BY 0.8 * \"s\".\"school_ranking\" + 0.2 * \"stp\".\"proximity_miles\""
}
}
]
}
}
16 changes: 8 additions & 8 deletions alloydb-ai-nla/sixrecipe_context2_1.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"facets": [
{
"sql_snippet": "real_estate.properties.is_condo = FALSE AND real_estate.properties.is_single_family = TRUE AND real_estate.properties.listing_status = 'Active' AND real_estate.properties.bedrooms BETWEEN 3 AND 4 AND real_estate.properties.bathrooms >= 2.0 AND 500 > (SELECT m.crime_rate_per_100k FROM real_estate.cities c JOIN real_estate.municipalities m ON c.municipality_id = m.municipality_id AND c.city_id = real_estate.properties.city_id) AND 2 >= (SELECT MIN(stp.proximity_miles) FROM real_estate.school_to_property stp WHERE real_estate.properties.property_id = stp.property_id)",
"intent": "for starter family (between 3 and 4 bedrooms, 2+ bathrooms, low crime and close proximity to schools)",
"manifest": "for starter family",
"sql_snippet": "real_estate.properties.is_single_family = TRUE AND real_estate.properties.listing_status = 'Active' AND real_estate.properties.bedrooms BETWEEN 3 AND 4 AND real_estate.properties.bathrooms >= 2.0 AND 500 > (SELECT m.crime_rate_per_100k FROM real_estate.cities c JOIN real_estate.municipalities m ON c.municipality_id = m.municipality_id AND c.city_id = real_estate.properties.city_id)",
"intent": "for a starter family (active single-family home listings with 3 to 4 bedrooms, 2+ bathrooms, and a crime rate under 500 per 100,000 residents)",
"manifest": "for a starter family",
"parameterized": {
"parameterized_intent": "for starter family (between 3 and 4 bedrooms, 2+ bathrooms, low crime and close proximity to schools)",
"parameterized_sql_snippet": "real_estate.properties.is_condo = FALSE AND real_estate.properties.is_single_family = TRUE AND real_estate.properties.listing_status = 'Active' AND real_estate.properties.bedrooms BETWEEN 3 AND 4 AND real_estate.properties.bathrooms >= 2.0 AND 500 > (SELECT m.crime_rate_per_100k FROM real_estate.cities c JOIN real_estate.municipalities m ON c.municipality_id = m.municipality_id AND c.city_id = real_estate.properties.city_id) AND 2 >= (SELECT MIN(stp.proximity_miles) FROM real_estate.school_to_property stp WHERE real_estate.properties.property_id = stp.property_id)"
"parameterized_intent": "for a starter family (active single-family home listings with 3 to 4 bedrooms, 2+ bathrooms, and a crime rate under 500 per 100,000 residents)",
"parameterized_sql_snippet": "real_estate.properties.is_single_family = TRUE AND real_estate.properties.listing_status = 'Active' AND real_estate.properties.bedrooms BETWEEN 3 AND 4 AND real_estate.properties.bathrooms >= 2.0 AND 500 > (SELECT m.crime_rate_per_100k FROM real_estate.cities c JOIN real_estate.municipalities m ON c.municipality_id = m.municipality_id AND c.city_id = real_estate.properties.city_id)"
}
}
],
"templates": [
{
"nl_query": "Riverside houses close to good schools.",
"sql": "SELECT \"p\".\"address_street\", \"p\".\"address_postal_code\", \"s\".\"school_name\", \"stp\".\"proximity_miles\" FROM \"real_estate\".\"properties\" AS \"p\" JOIN \"real_estate\".\"cities\" AS \"c\" ON \"p\".\"city_id\" = \"c\".\"city_id\" JOIN \"real_estate\".\"school_to_property\" AS \"stp\" ON \"p\".\"property_id\" = \"stp\".\"property_id\" JOIN \"real_estate\".\"schools\" AS \"s\" ON \"stp\".\"school_id\" = \"s\".\"school_id\" WHERE \"c\".\"city_name\" = 'Riverside' AND \"s\".\"school_ranking\" <= 5 AND \"stp\".\"proximity_miles\" <= 2 ORDER BY 0.8 * \"s\".\"school_ranking\" + 0.2 * \"stp\".\"proximity_miles\"",
"intent": "Riverside houses close to good schools.",
"intent": "Houses in Riverside close to good schools (within 2 miles of schools with a rank of at least 5).",
"manifest": "A given city houses close to good schools.",
"parameterized": {
"parameterized_intent": "$1 houses close to good schools.",
"parameterized_intent": "Houses in $1 close to good schools (within 2 miles of schools with a rank of at least 5).",
"parameterized_sql": "SELECT \"p\".\"address_street\", \"p\".\"address_postal_code\", \"s\".\"school_name\", \"stp\".\"proximity_miles\" FROM \"real_estate\".\"properties\" AS \"p\" JOIN \"real_estate\".\"cities\" AS \"c\" ON \"p\".\"city_id\" = \"c\".\"city_id\" JOIN \"real_estate\".\"school_to_property\" AS \"stp\" ON \"p\".\"property_id\" = \"stp\".\"property_id\" JOIN \"real_estate\".\"schools\" AS \"s\" ON \"stp\".\"school_id\" = \"s\".\"school_id\" WHERE \"c\".\"city_name\" = $1 AND \"s\".\"school_ranking\" <= 5 AND \"stp\".\"proximity_miles\" <= 2 ORDER BY 0.8 * \"s\".\"school_ranking\" + 0.2 * \"stp\".\"proximity_miles\""
}
}
]
}
}
20 changes: 10 additions & 10 deletions alloydb-ai-nla/sixrecipe_context2_2.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
{
"facets": [
{
"sql_snippet": "real_estate.properties.is_condo = FALSE AND real_estate.properties.is_single_family = TRUE AND real_estate.properties.listing_status = 'Active' AND real_estate.properties.bedrooms BETWEEN 3 AND 4 AND real_estate.properties.bathrooms >= 2.0 AND 500 > (SELECT m.crime_rate_per_100k FROM real_estate.cities c JOIN real_estate.municipalities m ON c.municipality_id = m.municipality_id AND c.city_id = real_estate.properties.city_id) AND 2 >= (SELECT MIN(stp.proximity_miles) FROM real_estate.school_to_property stp WHERE real_estate.properties.property_id = stp.property_id)",
"intent": "for starter family (between 3 and 4 bedrooms, 2+ bathrooms, low crime and close proximity to schools)",
"manifest": "for starter family",
"sql_snippet": "real_estate.properties.is_single_family = TRUE AND real_estate.properties.listing_status = 'Active' AND real_estate.properties.bedrooms BETWEEN 3 AND 4 AND real_estate.properties.bathrooms >= 2.0 AND 500 > (SELECT m.crime_rate_per_100k FROM real_estate.cities c JOIN real_estate.municipalities m ON c.municipality_id = m.municipality_id AND c.city_id = real_estate.properties.city_id)",
"intent": "for a starter family (active single-family home listings with 3 to 4 bedrooms, 2+ bathrooms, and a crime rate under 500 per 100,000 residents)",
"manifest": "for a starter family",
"parameterized": {
"parameterized_intent": "for starter family (between 3 and 4 bedrooms, 2+ bathrooms, low crime and close proximity to schools)",
"parameterized_sql_snippet": "real_estate.properties.is_condo = FALSE AND real_estate.properties.is_single_family = TRUE AND real_estate.properties.listing_status = 'Active' AND real_estate.properties.bedrooms BETWEEN 3 AND 4 AND real_estate.properties.bathrooms >= 2.0 AND 500 > (SELECT m.crime_rate_per_100k FROM real_estate.cities c JOIN real_estate.municipalities m ON c.municipality_id = m.municipality_id AND c.city_id = real_estate.properties.city_id) AND 2 >= (SELECT MIN(stp.proximity_miles) FROM real_estate.school_to_property stp WHERE real_estate.properties.property_id = stp.property_id)"
"parameterized_intent": "for a starter family (active single-family home listings with 3 to 4 bedrooms, 2+ bathrooms, and a crime rate under 500 per 100,000 residents)",
"parameterized_sql_snippet": "real_estate.properties.is_single_family = TRUE AND real_estate.properties.listing_status = 'Active' AND real_estate.properties.bedrooms BETWEEN 3 AND 4 AND real_estate.properties.bathrooms >= 2.0 AND 500 > (SELECT m.crime_rate_per_100k FROM real_estate.cities c JOIN real_estate.municipalities m ON c.municipality_id = m.municipality_id AND c.city_id = real_estate.properties.city_id)"
}
},
{
"sql_snippet": "((p.description_embedding <=> google_ml.embedding('gemini-embedding-001', 'unobstructed, panoramic, ocean vista, vast Pacific, breathtaking, commanding view, deep blue horizon, massive, sweeping view')::vector) < (p.description_embedding <=> google_ml.embedding('gemini-embedding-001', 'The view is a small, fragmented window, not a big, panoramic expanse. The view is seasonal and highly dependent on external factors, The view is not enjoyed passively; it requires effort or an awkward angle, The view currently does not exist and is conditional on future, uncertain events')::vector))",
"sql_snippet": "((real_estate.properties.description_embedding <=> google_ml.embedding('gemini-embedding-001', 'unobstructed, panoramic, ocean vista, vast Pacific, breathtaking, commanding view, deep blue horizon, massive, sweeping view')::vector) < 0.4)",
"intent": "with ocean view",
"manifest": "with ocean view",
"parameterized": {
"parameterized_intent": "with ocean view",
"parameterized_sql_snippet": "((p.description_embedding <=> google_ml.embedding('gemini-embedding-001', 'unobstructed, panoramic, ocean vista, vast Pacific, breathtaking, commanding view, deep blue horizon, massive, sweeping view')::vector) < (p.description_embedding <=> google_ml.embedding('gemini-embedding-001', 'The view is a small, fragmented window, not a big, panoramic expanse. The view is seasonal and highly dependent on external factors, The view is not enjoyed passively; it requires effort or an awkward angle, The view currently does not exist and is conditional on future, uncertain events')::vector))"
"parameterized_sql_snippet": "((real_estate.properties.description_embedding <=> google_ml.embedding('gemini-embedding-001', 'unobstructed, panoramic, ocean vista, vast Pacific, breathtaking, commanding view, deep blue horizon, massive, sweeping view')::vector) < 0.4)"
}
}
],
"templates": [
{
"nl_query": "Riverside houses close to good schools.",
"sql": "SELECT \"p\".\"address_street\", \"p\".\"address_postal_code\", \"s\".\"school_name\", \"stp\".\"proximity_miles\" FROM \"real_estate\".\"properties\" AS \"p\" JOIN \"real_estate\".\"cities\" AS \"c\" ON \"p\".\"city_id\" = \"c\".\"city_id\" JOIN \"real_estate\".\"school_to_property\" AS \"stp\" ON \"p\".\"property_id\" = \"stp\".\"property_id\" JOIN \"real_estate\".\"schools\" AS \"s\" ON \"stp\".\"school_id\" = \"s\".\"school_id\" WHERE \"c\".\"city_name\" = 'Riverside' AND \"s\".\"school_ranking\" <= 5 AND \"stp\".\"proximity_miles\" <= 2 ORDER BY 0.8 * \"s\".\"school_ranking\" + 0.2 * \"stp\".\"proximity_miles\"",
"intent": "Riverside houses close to good schools.",
"intent": "Houses in Riverside close to good schools (within 2 miles of schools with a rank of at least 5).",
"manifest": "A given city houses close to good schools.",
"parameterized": {
"parameterized_intent": "$1 houses close to good schools.",
"parameterized_intent": "Houses in $1 close to good schools (within 2 miles of schools with a rank of at least 5).",
"parameterized_sql": "SELECT \"p\".\"address_street\", \"p\".\"address_postal_code\", \"s\".\"school_name\", \"stp\".\"proximity_miles\" FROM \"real_estate\".\"properties\" AS \"p\" JOIN \"real_estate\".\"cities\" AS \"c\" ON \"p\".\"city_id\" = \"c\".\"city_id\" JOIN \"real_estate\".\"school_to_property\" AS \"stp\" ON \"p\".\"property_id\" = \"stp\".\"property_id\" JOIN \"real_estate\".\"schools\" AS \"s\" ON \"stp\".\"school_id\" = \"s\".\"school_id\" WHERE \"c\".\"city_name\" = $1 AND \"s\".\"school_ranking\" <= 5 AND \"stp\".\"proximity_miles\" <= 2 ORDER BY 0.8 * \"s\".\"school_ranking\" + 0.2 * \"stp\".\"proximity_miles\""
}
}
]
}
}
Loading