Build a Smart Shopping Assistant with AlloyDB and Vertex AI Agent Builder - Part 1
Commands and Links -
Google Codelab link -
Codelab link - https://codelabs.developers.google.co...
pom.xml - https://github.com/AbiramiSukumaran/R...
HelloHttpFunction.java - https://github.com/AbiramiSukumaran/R...
insert_script.sql - https://github.com/AbiramiSukumaran/R...
gcloud services enable alloydb.googleapis.com \
compute.googleapis.com \
cloudresourcemanager.googleapis.com \
servicenetworking.googleapis.com \
run.googleapis.com \
cloudbuild.googleapis.com \
cloudfunctions.googleapis.com \
aiplatform.googleapis.com
Enable Extensions
CREATE EXTENSION IF NOT EXISTS google_ml_integration CASCADE;
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE
apparels ( id BIGINT,
category VARCHAR(100),
sub_category VARCHAR(50),
uri VARCHAR(200),
image VARCHAR(100),
content VARCHAR(2000),
pdt_desc VARCHAR(5000),
embedding vector(768) );
Grant Permission
Run the below statement to grant execute rights on the embedding function to the user postgres:
GRANT EXECUTE ON FUNCTION embedding TO postgres;
Grant Vertex AI User ROLE to the AlloyDB service account
Go to Cloud Shell terminal and give the following command:
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"
Context - Run the following statement from AlloyDB studio of your newly created instance. This will update the pdt_desc field with context data:
UPDATE
apparels
SET
pdt_desc = CONCAT('This product category is: ', category, ' and sub_category is: ', sub_category, '. The description of the product is as follows: ', content, '. The product image is stored at: ', uri)
WHERE
id IS NOT NULL;
Create embeddings for the context
UPDATE
apparels
SET
embedding = embedding( 'text-embedding-004',
pdt_desc)
WHERE
TRUE;
Perform Vector search
SELECT
id,
category,
sub_category,
content,
pdt_desc AS description
FROM
apparels
ORDER BY
embedding **barcket=bracket** embedding('text-embedding-004',
'I want womens tops, pink casual only pure cotton.')::vector
LIMIT
5;
MATCH VALIDATION WITH LLM
CALL
google_ml.create_model( model_id =***bracket 'gemini-1.5',
model_request_url =***bracket 'https://us-central1-aiplatform.google...,
model_provider =***bracket 'google',
model_auth_type =***bracket 'alloydb_service_agent_iam');
The Challenge: Modern retail customers expect instant answers and product recommendations that align with their unique preferences. Traditional search methods often fall short of providing this level of personalization.
The Solution: Our knowledge-driven chat application tackles this challenge head-on. It leverages a rich knowledge base derived from your retail data to understand customer intent, respond intelligently, and deliver hyper-relevant results.
What you'll build
As part of this lab (Part 1), you will:
Create an AlloyDB instance and load Ecommerce Dataset
Enable the pgvector and generative AI model extensions in AlloyDB
Generate embeddings from the product description
Perform real time Cosine similarity search for user search text
Deploy the solution in serverless Cloud Run Functions
The second part of the lab will cover the Agent Builder steps.
Requirements
A browser, such as Chrome or Firefox
A Google Cloud project with billing enabled.