fix: complete BigQuery cutover for SEC search and query interface (#130)#149
Merged
Merged
Conversation
The warehouse migration left DuckDB/MotherDuck assumptions in registered code and docs while the resource returns a BigQuery client. This completes the cutover. SEC search (BigQuery-native): - semantic_search.py: rewrite vector/keyword/hybrid search to take the BigQueryWarehouseResource and emit Standard SQL — cosine similarity via ML.DISTANCE(embedding, @q, 'COSINE') over ARRAY<FLOAT64> embeddings, and keyword matching via SEARCH() ranked by CONTAINS_SUBSTR term overlap (BigQuery has no BM25). Replaces DuckDB list_cosine_similarity, match_bm25, ?::FLOAT[768] params, and conn.execute(...).pl(). - fts.py: drop INSTALL/LOAD fts and PRAGMA create/drop_fts_index; populate the denormalized FTS table and ensure a best-effort BigQuery SEARCH INDEX (SEARCH() still works via full scan if index creation is unavailable). - tables.py: add ensure_sec_filing_fts_content_table (BigQuery DDL). NL-to-SQL: - nl_to_sql_module.py: validate with sqlglot dialect="bigquery" and prompt the model for BigQuery Standard SQL instead of DuckDB. Cleanup: - Replace stale kinds={"duckdb"} with {"bigquery"} across 40 asset modules. - Remove the retired MotherDuck MCP server from .mcp.json (queries go through the dbt-index MCP warehouse tool). - README, .env.example, .env.dagster.example, macro_agents/.env.example: describe BigQuery instead of MotherDuck; fix stale BIGQUERY_PROJECT_ID -> BIGQUERY_PROJECT. Tests: - test_sec_search_queries.py: assert search builders emit valid BigQuery (run through the real prepare_query_parameters contract), hybrid RRF fuses both sources, and no DuckDB primitives remain in the SEC search modules. - test_nl_to_sql_bigquery.py: validator accepts BigQuery-only syntax and the prompt targets BigQuery. - Remove test_sec_search_functional.py (tested the retired in-memory DuckDB backend and imported a now-deleted helper). Live-BigQuery integration coverage for representative keyword/vector/hybrid searches remains (needs a warehouse target; cannot run in CI without creds). Closes #130 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The warehouse migration was incomplete: registered code and docs still assumed DuckDB/MotherDuck while
BigQueryWarehouseResourcereturns a BigQuery client. On BigQuery the SEC search assets failed outright (PRAGMA,list_cosine_similarity,match_bm25,?::FLOAT[768],conn.execute(...).pl()), NL-to-SQL emitted/validated DuckDB SQL, and a clean checkout advertised the retired MotherDuck interface. This completes the cutover.SEC search — BigQuery-native rewrite
semantic_search.py—vector_search/keyword_search/hybrid_searchnow take theBigQueryWarehouseResourceand emit Standard SQL:1 - ML.DISTANCE(embedding, @query_embedding, 'COSINE')over theARRAY<FLOAT64>embeddings already written bysec_filing_search_index(brute-force scan — exact, no VECTOR INDEX min-row/consistency constraints).SEARCH(content_text, @query_text)to match, ranked by distinct query-term overlap viaCONTAINS_SUBSTR(BigQuery exposes no BM25 score), recency tie-break.fts.py— dropsINSTALL/LOAD ftsandPRAGMA create/drop_fts_index; populates the denormalized FTS table and ensures a best-effort BigQuerySEARCH INDEX(SEARCH() still works via full scan if the index can't be created).tables.py— addsensure_sec_filing_fts_content_table(BigQuery DDL).NL-to-SQL
nl_to_sql_module.py—SQLValidatorparses withdialect="bigquery"; the DSPy output field now asks the model for BigQuery Standard SQL (not "DuckDB-compatible").Cleanup
kinds={"duckdb"}→{"bigquery"}across 40 asset modules (72 tags)..mcp.json; thedbt-indexMCP'swarehousetool is the clean-checkout BigQuery query path.README,.env.example,.env.dagster.example,macro_agents/.env.example: describe BigQuery instead of MotherDuck; corrected staleBIGQUERY_PROJECT_ID→BIGQUERY_PROJECT(the var the resource actually reads).Design validation (no live BQ in CI)
Every generated search statement is run through the same
prepare_query_parameterscontract the resource uses at runtime (sqlglot BigQuery parse + named-param matching), so the SQL is proven to be valid BigQuery and DML-safe at the unit level.Tests
test_sec_search_queries.py— builders emit valid BigQuery (contract-parsed), hybrid RRF fuses vector + keyword hits, and a guard asserts no DuckDB primitives remain in the SEC search modules.test_nl_to_sql_bigquery.py— validator accepts BigQuery-only syntax (backtick-quoted table, which DuckDB rejects) and the prompt targets BigQuery.test_sec_search_functional.py(tested the retired in-memory DuckDB backend; imported a now-deleted helper).479 tests collect; ruff check + format clean.Acceptance criteria
Closes #130
🤖 Generated with Claude Code