-
Notifications
You must be signed in to change notification settings - Fork 33
feat: Support cross-database evaluation with SQLite ground truth #465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
IsmailMehdi
merged 6 commits into
GoogleCloudPlatform:main
from
arieljassan:feat/bird-xa-benchmark
Jul 7, 2026
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1c07b41
feat(scorers): add hybrid execution accuracy judging and SQLite groun…
arieljassan fcab2f9
Address code review feedback for specific files
arieljassan 7ee73d2
Address general code review feedback: add unit tests, documentation, …
arieljassan cfe0153
Merge branch 'main' into feat/bird-xa-benchmark
IsmailMehdi dc9aa95
Remove unnecessary ensure_database_exists method
arieljassan 8cfade6
Merge branch 'main' into feat/bird-xa-benchmark
IsmailMehdi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| ############################################################ | ||
| ### Dataset / Eval Items (Hybrid BigQuery -> SQLite Mode) | ||
| ############################################################ | ||
| # The JSON list of prompts / golden SQLs and eval attributes for the run | ||
| dataset_config: datasets/bird/prompts.json | ||
|
|
||
| # Database configs mapping to BigQuery (for executing generated SQL) | ||
| database_configs: | ||
| - datasets/bat/db_configs/bigquery.yaml | ||
|
|
||
| # Filter dialet to bigquery for query execution | ||
| dialects: | ||
| - bigquery | ||
| query_types: | ||
| - dql | ||
| dataset_format: bird-standard-format | ||
|
|
||
| ############################################################ | ||
| ### Prompt and Generation Modules | ||
| ############################################################ | ||
| # The YAML config for the model to be used for SQL generation | ||
| model_config: datasets/model_configs/gemini_2.5_pro_model.yaml | ||
| # The prompt generator module id | ||
| prompt_generator: 'SQLGenBasePromptGenerator' | ||
|
|
||
| ############################################################ | ||
| ### Scorer Related Configs | ||
| ############################################################ | ||
| scorers: | ||
| llmrater: | ||
| model_config: datasets/model_configs/gemini_2.5_pro_model.yaml | ||
| # Fallback to local SQLite database when golden query execution fails on BQ | ||
| hybrid_ground_truth: true | ||
| python_scorer: | ||
| # Isolated cross-database Execution Accuracy (XA) judge script | ||
| script_path: 'evalbench/scorers/judges/hybrid_xa_judge.py' | ||
| scorer_name: 'hybrid_cross_db' | ||
|
|
||
| ############################################################ | ||
| ### Reporting Related Configs | ||
| ############################################################ | ||
| reporting: | ||
| csv: | ||
| output_directory: 'results' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| """Hybrid Execution Accuracy (XA) Cross-Database Evaluator for EvalBench.""" | ||
|
arieljassan marked this conversation as resolved.
|
||
|
|
||
| from decimal import Decimal | ||
| import json | ||
| import os | ||
| import sqlite3 | ||
| import sys | ||
| from typing import List, Optional | ||
|
|
||
| import pandas as pd | ||
|
|
||
|
|
||
| def get_sqlite_ground_truth( | ||
| query: str, | ||
| database: str, | ||
| db_dir: str = "", | ||
| ) -> list: | ||
| """Resolves candidate SQLite database files and executes query.""" | ||
|
|
||
| sqlite_path = os.path.join(db_dir, f"{database}.sqlite") | ||
| if not os.path.exists(sqlite_path): | ||
| return [] | ||
| conn = sqlite3.connect(sqlite_path) | ||
| try: | ||
| return pd.read_sql_query(query, conn).to_dict(orient="records") | ||
| finally: | ||
| conn.close() | ||
|
|
||
|
|
||
| def compare_result_sets(df_bq: pd.DataFrame, df_sqlite: pd.DataFrame) -> bool: | ||
| """Compares two DataFrames ignoring column names and row order. | ||
|
|
||
| Normalization rules: | ||
| 1. Floats are rounded to 4 decimal places for cross-engine consistency. | ||
| 2. Rows are sorted lexicographically by string representation. | ||
| 3. Trailing '.0' suffixes are stripped from stringified numeric values. | ||
| """ | ||
| if df_bq is None or df_sqlite is None: | ||
| return False | ||
|
|
||
| if df_bq.empty and df_sqlite.empty: | ||
| return True | ||
|
|
||
| if df_bq.empty != df_sqlite.empty: | ||
| return False | ||
|
|
||
| def normalize_df(df: pd.DataFrame) -> list[tuple]: | ||
| rows = [] | ||
| for _, r in df.iterrows(): | ||
| normalized_row = [] | ||
| for val in r: | ||
| if pd.isna(val): | ||
| normalized_row.append(None) | ||
| elif isinstance(val, (int, float, Decimal)): | ||
| try: | ||
| normalized_row.append(round(float(val), 4)) | ||
|
arieljassan marked this conversation as resolved.
|
||
| except (ValueError, TypeError): | ||
| normalized_row.append(str(val)) | ||
| else: | ||
| s = str(val).strip().lower() | ||
| if s.endswith(".0"): | ||
| s = s[:-2] | ||
| normalized_row.append(s) | ||
| rows.append(tuple(normalized_row)) | ||
| rows.sort(key=lambda x: str(x)) | ||
| return rows | ||
|
|
||
| try: | ||
| bq_rows = normalize_df(df_bq) | ||
| sqlite_rows = normalize_df(df_sqlite) | ||
| except Exception: | ||
| return False | ||
|
|
||
| if len(bq_rows) != len(sqlite_rows): | ||
| return False | ||
|
|
||
| for r_bq, r_sqlite in zip(bq_rows, sqlite_rows): | ||
| if len(r_bq) != len(r_sqlite): | ||
| return False | ||
| for val_bq, val_sqlite in zip(r_bq, r_sqlite): | ||
| if val_bq != val_sqlite: | ||
| return False | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| def main(): | ||
| try: | ||
| input_data = json.load(sys.stdin) | ||
| database = input_data.get("database", "") | ||
| pred_rows = input_data.get("generated_execution_result") | ||
| ref_sql = input_data.get("golden_query", "") | ||
|
|
||
| sqlite_db_dir = input_data.get("sqlite_db_dir", "") | ||
| sqlite_records = get_sqlite_ground_truth( | ||
| ref_sql, database, sqlite_db_dir | ||
| ) | ||
| df_sqlite = pd.DataFrame(sqlite_records) | ||
| sqlite_res_str = json.dumps(sqlite_records) | ||
|
|
||
| gen_err = input_data.get("generated_error") | ||
| if pred_rows is None or isinstance(pred_rows, str) or gen_err: | ||
| err_msg = gen_err or "Invalid prediction object" | ||
| reason = ( | ||
| f"FAIL | BigQuery Error: {err_msg} | " | ||
| f"SQLite Ground Truth Result: {sqlite_res_str}" | ||
| ) | ||
| print(json.dumps({"score": 0.0, "reason": reason})) | ||
| return | ||
|
|
||
| if isinstance(pred_rows, list): | ||
| df_bq = pd.DataFrame(pred_rows) | ||
| else: | ||
| df_bq = pd.DataFrame() | ||
|
|
||
| match = compare_result_sets(df_bq, df_sqlite) | ||
| score = 100.0 if match else 0.0 | ||
| if match: | ||
| reason = f"PASS | SQLite Ground Truth Result: {sqlite_res_str}" | ||
| else: | ||
| bq_res_str = json.dumps(df_bq.to_dict(orient="records")) | ||
| reason = ( | ||
| f"FAIL | BQ Prediction: {bq_res_str} vs " | ||
| f"SQLite Ground Truth: {sqlite_res_str}" | ||
| ) | ||
| print(json.dumps({"score": score, "reason": reason})) | ||
|
|
||
| except Exception as e: | ||
| err_reason = f"FAIL: Exception in hybrid judge: {e}" | ||
| print(json.dumps({"score": 0.0, "reason": err_reason})) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dead code, see line 183.