Neszed-Mobile-header-logo
Wednesday, July 30, 2025
Newszed-Header-Logo
HomeAIA Deep Dive into Image Embeddings and Vector Search with BigQuery on...

A Deep Dive into Image Embeddings and Vector Search with BigQuery on Google Cloud

A Deep Dive into Image Embeddings and Vector Search with BigQuery on Google Cloud
Image by Editor | ChatGPT

 

Introduction

 
We’ve all been there: scrolling endlessly through online stores, trying to find that perfect item. In today’s lightning-fast e-commerce world, we expect instant results, and that’s exactly where AI is stepping in to shake things up.

At the heart of this revolution is image embedding. It’s a fancy term for a simple idea: letting you search for products not just by keywords, but by their visual similarity. Imagine finding that exact dress you saw on social media just by uploading a picture! This technology makes online shopping smarter, more intuitive, and ultimately, helps businesses make more sales. 

Ready to see how it works? We’ll show you how to harness the power of BigQuery’s machine learning capabilities to build your own AI-driven dress search using these incredible image embeddings. 

 

The Magic of Image Embeddings

 
In essence, image embedding is the process of converting images into numerical representations (vectors) in a high-dimensional space. Images that are semantically similar (e.g. a blue ball gown and a navy blue dress) will have vectors that are “closer” to each other in this space. This allows for powerful comparisons and searches that go beyond simple metadata. 

Here are a few dress images we will use in this demo to generate embeddings.

 
Here are a few dress images we will use in this demo to generate embeddings.
 

The demo will illustrate the process of creating a model for image embeddings on Google Cloud. 

The first step is to create a model: A model named image_embeddings_model is created which is leveraging the multimodalembedding@001 endpoint in image_embedding dataset.

CREATE OR REPLACE MODEL 
   `image_embedding.image_embeddings_model`
REMOTE WITH CONNECTION `[PROJECT_ID].us.llm-connection`
OPTIONS (
   ENDPOINT = 'multimodalembedding@001'
);

 

Creating an object table: To process the images in BigQuery, we will create an external table called external_images_table in the image_embedding dataset which will reference all the images stored in a Google Cloud Storage bucket.

CREATE OR REPLACE EXTERNAL TABLE 
   `image_embedding.external_images_table` 
WITH CONNECTION `[PROJECT_ID].us.llm-connection` 
OPTIONS( 
   object_metadata="SIMPLE", 
   uris = ['gs://[BUCKET_NAME]/*'], 
   max_staleness = INTERVAL 1 DAY, 
   metadata_cache_mode="AUTOMATIC"
);

 

Generating embeddings: Once the model and object table are in place, we will generate the embeddings for the dress images using the model we created above and store them in the table dress_embeddings.

CREATE OR REPLACE TABLE `image_embedding.dress_embeddings` AS SELECT * 
FROM ML.GENERATE_EMBEDDING( 
   MODEL `image_embedding.image_embeddings_model`, 
   TABLE `image_embedding.external_images_table`, 
   STRUCT(TRUE AS flatten_json_output, 
   512 AS output_dimensionality) 
);

 

Unleashing the Power of Vector Search

 
With image embeddings generated, we will use vector search to find the dress we are looking for. Unlike traditional search that relies on exact keyword matches, vector search finds items based on the similarity of their embeddings. This means you can search for images using either text descriptions or even other images.

 

// Dress Search via Text

Performing text search: Here we will use the VECTOR_SEARCH function within BigQuery to search for a “Blue dress” among all the dresses. The text “Blue dress” will be converted to a vector and then with the help of vector search we will retrieve similar vectors.

CREATE OR REPLACE TABLE `image_embedding.image_search_via_text` AS 
SELECT base.uri AS image_link, distance 
FROM 
VECTOR_SEARCH( 
   TABLE `image_embedding.dress_embeddings`, 
   'ml_generate_embedding_result', 
   ( 
      SELECT ml_generate_embedding_result AS embedding_col 
      FROM ML.GENERATE_EMBEDDING 
      ( 
         MODEL`image_embedding.image_embeddings_model` , 
            (
               SELECT "Blue dress" AS content
            ), 
            STRUCT 
         (
            TRUE AS flatten_json_output, 
            512 AS output_dimensionality
         ) 
      )
   ),
   top_k => 5 
)
ORDER BY distance ASC; 
SELECT * FROM `image_embedding.image_search_via_text`;

 

Results: The query results will provide an image_link and a distance for each result. You can see the results you will obtain will give you the closest match in regards to the search query and the dresses available.

 
Results

 

// Dress Search via Image

Now, we will look into how we can use an image to find similar images. Let’s try to find a dress that looks like the below image:

 

Let’s try to find a dress that looks like the below image

 

External table for test image: We will have to store the test image in the Google Cloud Storage Bucket and create an external table external_images_test_table, to store the test image used for the search.

CREATE OR REPLACE EXTERNAL TABLE 
   `image_embedding.external_images_test_table` 
WITH CONNECTION `[PROJECT_ID].us.llm-connection` 
OPTIONS( 
   object_metadata="SIMPLE", 
   uris = ['gs://[BUCKET_NAME]/test-image-for-dress/*'], 
   max_staleness = INTERVAL 1 DAY, 
   metadata_cache_mode="AUTOMATIC"
);

 

Generate embeddings for test image: Now, we will generate the embedding for this single test image using ML.GENERATE_EMBEDDING function.

CREATE OR REPLACE TABLE `image_embedding.test_dress_embeddings` AS 
SELECT * 
FROM ML.GENERATE_EMBEDDING
   ( 
      MODEL `image_embedding.image_embeddings_model`, 
      TABLE `image_embedding.external_images_test_table`, STRUCT(TRUE AS flatten_json_output, 
      512 AS output_dimensionality
   ) 
);

 

Vector search with image embedding: Finally, the embedding of the test image will be used to perform a vector search against the image_embedding.dress_embeddings table. The ml_generate_embedding_result from image_embedding.test_dress_embeddings will be used as the query embedding. 

SELECT base.uri AS image_link, distance 
FROM 
VECTOR_SEARCH( 
   TABLE `image_embedding.dress_embeddings`, 
   'ml_generate_embedding_result', 
   ( 
      SELECT * FROM `image_embedding.test_dress_embeddings`
   ),
   top_k => 5, 
   distance_type => 'COSINE', 
   options => '{"use_brute_force":true}' 
);

 

Results: The query results for the image search showed the most visually similar dresses. The top result was white-dress with a distance of 0.2243 , followed by sky-blue-dress with a distance of 0.3645 , and polka-dot-dress with a distance of 0.3828. 

 
These results clearly demonstrate the ability to find visually similar items based on an input image.
 

These results clearly demonstrate the ability to find visually similar items based on an input image. 

 

// The Impact

This demonstration effectively illustrates how image embeddings and vector search on Google Cloud can revolutionize how we interact with visual data. From e-commerce platforms enabling “shop similar” features to content management systems offering intelligent visual asset discovery, the applications are vast. By transforming images into searchable vectors, these technologies unlock a new dimension of search, making it more intuitive, powerful, and visually intelligent. 

These results can be presented to the user, enabling them to find the desired dress quickly.

 

Benefits of AI Dress Search

 

  1. Enhanced User Experience: Visual search provides a more intuitive and efficient way for users to find what they’re looking for
  2. Improved Accuracy: Image embeddings enable search based on visual similarity, delivering more relevant results than traditional keyword-based search
  3. Increased Sales: By making it easier for customers to find the products they want, AI dress search can boost conversions and drive revenue

 

Beyond Dress Search

 
By combining the power of image embeddings with BigQuery’s robust data processing capabilities, you can create innovative AI-driven solutions that transform the way we interact with visual content. From e-commerce to content moderation, the power of image embeddings and BigQuery extends beyond dress search. 

Here are some other potential applications: 

  • E-commerce: Product recommendations, visual search for other product categories
  • Fashion Design: Trend analysis, design inspiration
  • Content Moderation: Identifying inappropriate content
  • Copyright Infringement Detection: Finding visually similar images to protect intellectual property

Learn more about embeddings on BigQuery here and vector search here.
 
 

Nivedita Kumari is a seasoned Data Analytics and AI Professional with over 10 years of experience. In her current role, as a Data Analytics Customer Engineer at Google she constantly engages with C level executives and helps them architect data solutions and guides them on best practice to build Data and Machine learning solutions on Google Cloud. Nivedita has done her Masters in Technology Management with a focus on Data Analytics from the University of Illinois at Urbana-Champaign. She wants to democratize machine learning and AI, breaking down the technical barriers so everyone can be part of this transformative technology. She shares her knowledge and experience with the developer community by creating tutorials, guides, opinion pieces, and coding demonstrations.
Connect with Nivedita on LinkedIn.

Source link

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments