@@ -156,6 +156,14 @@ func TestBigQueryToolEndpoints(t *testing.T) {
156156 tmplSelectCombined , tmplSelectFilterCombined := getBigQueryTmplToolStatement ()
157157 toolsFile = tests .AddTemplateParamConfig (t , toolsFile , BigqueryToolType , tmplSelectCombined , tmplSelectFilterCombined , "" )
158158
159+ // Set up table for semantic search
160+ vectorTableName , teardownVectorTable := setupBigQueryVectorTable (t , ctx , client , datasetName )
161+ defer teardownVectorTable (t )
162+
163+ // Add semantic search tool config
164+ insertStmt , searchStmt := getBigQueryVectorSearchStmts (vectorTableName )
165+ toolsFile = tests .AddSemanticSearchConfig (t , toolsFile , BigqueryToolType , insertStmt , searchStmt )
166+
159167 cmd , cleanup , err := tests .StartCmd (ctx , toolsFile , args ... )
160168 if err != nil {
161169 t .Fatalf ("command initialization returned an error: %s" , err )
@@ -205,6 +213,7 @@ func TestBigQueryToolEndpoints(t *testing.T) {
205213 runBigQueryGetTableInfoToolInvokeTest (t , datasetName , tableName , tableInfoWant )
206214 runBigQueryConversationalAnalyticsInvokeTest (t , datasetName , tableName , dataInsightsWant )
207215 runBigQuerySearchCatalogToolInvokeTest (t , datasetName , tableName )
216+ tests .RunSemanticSearchToolInvokeTest (t , ddlWant , "" , "The quick brown fox" )
208217}
209218
210219func TestBigQueryToolWithDatasetRestriction (t * testing.T ) {
@@ -3259,3 +3268,24 @@ func runAnalyzeContributionWithRestriction(t *testing.T, allowedTableFullName, d
32593268 })
32603269 }
32613270}
3271+
3272+ // setupBigQueryVectorTable creates a vector table in BigQuery for semantic search testing
3273+ func setupBigQueryVectorTable (t * testing.T , ctx context.Context , client * bigqueryapi.Client , datasetName string ) (string , func (* testing.T )) {
3274+ tableName := fmt .Sprintf ("vector_table_%s" , strings .ReplaceAll (uuid .New ().String (), "-" , "" ))
3275+ fullTableName := fmt .Sprintf ("`%s.%s.%s`" , BigqueryProject , datasetName , tableName )
3276+ createStatement := fmt .Sprintf (`CREATE TABLE %s (
3277+ id INT64,
3278+ content STRING,
3279+ embedding ARRAY<FLOAT64>
3280+ )` , fullTableName )
3281+
3282+ teardownTable := setupBigQueryTable (t , ctx , client , createStatement , "" , datasetName , fullTableName , nil )
3283+ return fullTableName , teardownTable
3284+ }
3285+
3286+ // getBigQueryVectorSearchStmts returns statements for bigquery semantic search
3287+ func getBigQueryVectorSearchStmts (vectorTableName string ) (string , string ) {
3288+ insertStmt := fmt .Sprintf ("INSERT INTO %s (id, content, embedding) VALUES (1, @content, (SELECT ARRAY_AGG(CAST(x AS FLOAT64)) FROM UNNEST(JSON_VALUE_ARRAY(PARSE_JSON(@text_to_embed))) AS x))" , vectorTableName )
3289+ searchStmt := fmt .Sprintf ("SELECT id, content, ML.DISTANCE(embedding, (SELECT ARRAY_AGG(CAST(x AS FLOAT64)) FROM UNNEST(JSON_VALUE_ARRAY(PARSE_JSON(@query))) AS x), 'COSINE') AS distance FROM %s ORDER BY distance LIMIT 1" , vectorTableName )
3290+ return insertStmt , searchStmt
3291+ }
0 commit comments