Effortless data prep in BigQuery: A low coder's guide

Google Cloud TechAbout 4 min readSep 27, 2025Watch original
THE SUMMARYAI-generated

Key Concepts:

  • JSON flattening
  • Vector embeddings
  • BQML remote model
  • Cosine distance
  • Data preparation
  • Data enrichment
  • Vector search
  • BigQuery Data Pipeline

1. Data Preparation:

  • Source: CSV file in Google Cloud Storage containing data from the Metropolitan Art Museum.
  • Challenge: Parsing the nested "label details" JSON column.
  • Solution: Using BigQuery's data preparation UI and Gemini to automatically flatten the JSON column with a single click. The suggestions panel analyzes the column's content and suggests the appropriate transformation.
  • Process:
    1. Select the CSV file in Google Cloud Storage.
    2. Configure a staging table.
    3. Click on the "label details" JSON column.
    4. Apply the suggested transformation to flatten the column.
    5. Define a destination table (e.g., "met art flatten table").
    6. Run the job.
  • Benefit: Eliminates the need for Python scripts and ETL pipelines.

2. Data Enrichment with Vector Embeddings:

  • Problem: Computers cannot understand the meaning of words like "landscape" or "portrait."
  • Solution: Using vector embeddings to represent concepts as coordinates in a mathematical space, where similar concepts are located close to each other.
  • Process:
    1. Create a BQML Remote Model: This creates a remote control in BigQuery to use Google's pre-trained Gemini embedding model. It doesn't train a new model.
    2. Aggregate Text Descriptions: Combine all text descriptions for a single artwork into one comprehensive string, ordered by relevance, to provide context for the model.
    3. Generate Embeddings: Use the ML.GENERATE_TEXT_EMBEDDING function, pointing it to the BQML remote model, to generate vector embeddings for each artwork. BQML handles batching and API calls to Vertex AI.
  • Example: Instead of embedding single labels, combine all text descriptions for a single artwork into one comprehensive string ordered by their relevance.
  • Result: A new table with original IDs and a new column containing the vector embedding for each artwork.

3. Building a Recommendation Engine with Vector Search:

  • Goal: Find artworks that are thematically similar to a famous piece (e.g., Van Gogh's "Cypresses").
  • Methodology: Using a single SQL query to calculate the cosine distance between the vector of the target artwork and all other vectors in the table.
  • Process:
    1. Select Target Vector: Select the vector for the target artwork (e.g., "Cypresses").
    2. Calculate Cosine Distance: Use the ML.DISTANCE function to calculate the cosine distance between the target vector and all other vectors in the table.
    3. Rank Results: Order the results by cosine distance, with smaller distances indicating higher similarity.
  • Technical Term: Cosine distance is a standard way to measure the similarity between two vectors.
  • Validation: The top result should be the painting itself with a distance of zero, confirming the logic is working correctly.
  • Application: The SQL logic powers a recommendation feature in a real application, such as a demo app that displays similar artworks visually.

4. Real-World Application: Demo App

  • A demo application is built on top of the artwork embeddings table.
  • When a user searches for "Cypresses" and clicks it, the app runs the similarity query and displays the most similar artworks visually.
  • This demonstrates the power of vector search in a user-friendly interface.

5. Automation with BigQuery Data Pipeline:

  • The entire workflow (data preparation and SQL queries) can be automated using BigQuery Data Pipeline.
  • This allows you to take the concept from a one-time analysis to a production-ready automated system.

6. General Pattern: Prep, Enrich, Search

  • The "prep, enrich, search" pattern is incredibly powerful and can be applied to various use cases:
    • Product recommendation from user reviews
    • Finding similar legal documents
    • Analyzing customer feedback

7. Notable Quotes:

  • "Gemini in BigQuery identifies this structure and suggests the appropriate transformation flattening column label details JSON."
  • "Think of it as giving each concept a set of coordinations. So similar concepts are located close to each other in a mathematical space."

8. Conclusion:

The video demonstrates how to build an end-to-end AI pipeline within BigQuery using a low-code, SQL-first approach. It covers data preparation using Gemini to flatten JSON data, data enrichment using vector embeddings generated by a BQML remote model, and vector search to power a recommendation engine. The entire workflow can be automated using BigQuery Data Pipeline, making it suitable for production environments. The "prep, enrich, search" pattern is highlighted as a versatile approach applicable to various use cases.

AI summaries can miss context or contain errors. Check important details against the original video.

Go a little deeper.

Have a question about this video? Load its transcript to open the video chat.