Welcome to the Toy Store Search App repository! This application leverages advanced AI capabilities and cloud technologies to provide a seamless and personalized toy shopping experience. Users can search for toys using text or images, and even design their own custom creations.
The backend of the application is built using Spring Boot, and the Gen AI Toolbox for Databases is implemented in Python to facilitate AI-powered database interactions on Google Cloud.
The app utilizes AlloyDB, pgvector, Gemini 2.0 Flash, Imagen 3, and the Gen AI Toolbox for Databases to deliver these features.
This project was developed as part of Google Cloud's Code Vipassana Season 9
The application architecture consists of the following components:
-
AlloyDB: A fully managed, PostgreSQL-compatible database that stores toy data, including descriptions, images, and attributes.
-
pgvector: A PostgreSQL extension that enables storage and similarity search of vector embeddings, facilitating semantic search capabilities.
-
Gemini 2.0 Flash: An AI model used to analyze user-uploaded images and extract contextual information for accurate search results.
-
Imagen 3: A generative AI model that allows users to create custom toy designs based on text prompts.
-
Gen AI Toolbox for Databases: An open-source server that simplifies the development of AI tools interacting with databases, enhancing performance, security, and observability.
AlloyDB is a PostgreSQL-compatible database that offers high performance and scalability. Follow these steps to set up the database:
-
Create a Cluster and Instance: Navigate to the AlloyDB page in the Google Cloud Console and create a cluster named
vector-cluster
and an instance namedvector-instance
. Detailed instructions can be found in the [Toy Store Search App Codelab][codelab-toy-store-app]. -
Create the
toys
Table:CREATE TABLE toys ( id VARCHAR(25), name VARCHAR(25), description VARCHAR(20000), quantity INT, price FLOAT, image_url VARCHAR(200), text_embeddings vector(768) );
-
Insert Data: Populate the
toys
table with data. Sample insert scripts are available in thedata.sql
file in this repository. -
Enable Extensions:
CREATE EXTENSION vector; CREATE EXTENSION google_ml_integration;
-
Grant Permissions:
GRANT EXECUTE ON FUNCTION embedding TO postgres;
-
Grant Vertex AI User Role:
PROJECT_ID=$(gcloud config get-value project) gcloud projects add-iam-policy-binding $PROJECT_ID \ --member="serviceAccount:service-$(gcloud projects describe $PROJECT_ID --format="value(projectNumber)")@gcp-sa-alloydb.iam.gserviceaccount.com" \ --role="roles/aiplatform.user"
-
Update Text Embeddings:
UPDATE toys SET text_embeddings = embedding('text-embedding-005', description);
-
Create ScaNN Index:
CREATE EXTENSION IF NOT EXISTS alloydb_scann; CREATE INDEX toysearch_index ON toys USING scann (text_embeddings cosine) WITH (num_leaves=9);
The Gen AI Toolbox for Databases simplifies the integration of AI tools with databases. Follow these steps to install and configure the toolbox:
-
Clone the Toolbox Repository:
git clone https://github.com/googleapis/genai-toolbox cd genai-toolbox
-
Install Dependencies:
pip install -r requirements.txt
-
Configure Tools: Define your tools in the
tools.yaml
file. For example, to create a price prediction tool:tools: - name: price_prediction description: Predicts the price of a toy based on its description. source: alloydb parameters: query: | SELECT AVG(price) FROM ( SELECT price FROM toys ORDER BY text_embeddings <=> CAST(embedding('text-embedding-005', '{{description}}') AS vector(768)) LIMIT 5 ) AS price;
-
Deploy Toolbox on Cloud Run:
gcloud run deploy toolbox-service --source .
Detailed instructions are available in the [Gen AI Toolbox Codelab][codelab-genai-toolbox].
-
Clone the Application Repository:
git clone https://github.com/your-username/toy-store-search-app.git cd toy-store-search-app
-
Set Environment Variables:
export PROJECT_ID=your_project_id export GOOGLE_API_KEY=your_api_key
-
Build and Run Locally:
mvn package mvn spring-boot:run
-
Deploy on Cloud Run:
gcloud run deploy --source .
Below is a screenshot of the deployed app:
Utilizing AlloyDB and pgvector, the application performs semantic searches based on user input. By generating vector embeddings of toy descriptions and user queries, it identifies the most relevant matches using cosine similarity and ScaNN indexing.
Users can upload images of toys, and the application employs Gemini 2.0 Flash to extract descriptive features. These features are then used to perform a vector search, retrieving toys that closely match the uploaded image.
The application allows users to design custom toys by providing text descriptions. Imagen 3 generates images based on these descriptions, enabling users to visualize and create their desired toys.
By integrating the Gen AI Toolbox for Databases, the application predicts the price of custom-created toys. It analyzes similar existing toys in the database to provide an estimated price for the new creation.
Here are some useful links and references to help you understand and set up the project: