Skip to content

Latest commit

 

History

History
145 lines (119 loc) · 5.21 KB

File metadata and controls

145 lines (119 loc) · 5.21 KB

Shopping Assistant with RAG & AlloyDB

This demo adds a new service to Online Boutique called shoppingassistantservice which, alongside an Alloy-DB backed products catalog, adds a RAG-featured AI assistant to the frontned experience, helping users suggest products matching their home decor.

Setup instructions

Note: This demo requires a Google Cloud project where you to have the owner role, else you may be unable to enable APIs or modify VPC rules that are needed for this demo.

  1. Set some environment variables.

    export PROJECT_ID=<project_id>
    export PROJECT_NUMBER=<project_number>
    export PGPASSWORD=<pgpassword>

    Note: The project ID and project number of your Google Cloud project can be found in the Console. The PostgreSQL password can be set to anything you want, but make sure to note it down.

  2. Change your default Google Cloud project.

    gcloud auth login
    gcloud config set project $PROJECT_ID
  3. Enable the Google Kubernetes Engine (GKE) and Artifact Registry (AR) APIs.

    gcloud services enable container.googleapis.com
    gcloud services enable artifactregistry.googleapis.com
  4. Create a GKE Autopilot cluster. This may take a few minutes.

    gcloud container clusters create-auto cymbal-shops \
        --region=us-central1
  5. Change your Kubernetes context to your newly created GKE cluster.

    gcloud container clusters get-credentials cymbal-shops \
        --region us-central1
  6. Create an Artifact Registry container image repository.

    gcloud artifacts repositories create images \
        --repository-format=docker \
        --location=us-central1
  7. Clone the microservices-demo repository locally.

    git clone https:/GoogleCloudPlatform/microservices-demo \
        && cd microservices-demo/
  8. Run script #1. If it asks about policy bindings, select the option None. This may take a few minutes.

    ./kustomize/components/shopping-assistant/scripts/1_deploy_alloydb_infra.sh

    Note: If you are on macOS and use a non-GNU version of sed, you may have to tweak the script to use gsed instead.

  9. Create a Linux VM in Compute Engine (GCE).

    gcloud compute instances create gce-linux \
        --zone=us-central1-a \
        --machine-type=e2-micro \
        --image-family=debian-12 \
        --image-project=debian-cloud 
  10. SSH into the VM. From here until we exit, all steps happen in the VM.

    gcloud compute ssh gce-linux \
        --zone "us-central1-a"
  11. Install the Postgres client and set your default Google Cloud project.

    sudo apt-get install -y postgresql-client
    gcloud auth login
    gcloud config set project <PROJECT_ID>
  12. Copy script #2, the python script, and the products.json to the VM. Make sure the scripts are executable.

    nano 2_create_populate_alloydb_tables.sh # paste content
    nano generate_sql_from_products.py # paste content
    nano products.json # paste content
    chmod +x 2_create_populate_alloydb_tables.sh
    chmod +x generate_sql_from_products.py

    Note: You can find the files at the following places:

    • kustomize/components/shopping-assistant/scripts/2_create_populate_alloydb_tables.sh
    • kustomize/components/shopping-assistant/scripts/generate_sql_from_products.py
    • src/productcatalogservice/products.json
  13. Run script #2 in the VM. If it asks for a postgres password, it should be the same that you set in script #1 earlier. This may take a few minutes.

    ./2_create_populate_alloydb_tables.sh
  14. Exit SSH.

    exit
  15. Create an API key in the Credentials page with permissions for "Generative Language API", and make note of the secret key.

  16. Replace the Google API key placeholder in the shoppingassistant service.

    export GOOGLE_API_KEY=<google_api_key>
    sed -i "s/GOOGLE_API_KEY_VAL/${GOOGLE_API_KEY}/g" kustomize/components/shopping-assistant/shoppingassistantservice.yaml
  17. Edit the root Kustomize file to enable the alloydb and shopping-assistant components.

    nano kubernetes-manifests/kustomization.yaml # make the modifications below
    # ...head of the file
    components: # remove this comment
    # - ../kustomize/components/cymbal-branding
    # - ../kustomize/components/google-cloud-operations
    # - ../kustomize/components/memorystore
    # - ../kustomize/components/network-policies
     - ../kustomize/components/alloydb # remove this comment
     - ../kustomize/components/shopping-assistant # remove this comment
    # - ../kustomize/components/spanner
    # - ../kustomize/components/container-images-tag
    # - ../kustomize/components/container-images-tag-suffix
    # - ../kustomize/components/container-images-registry
  18. Deploy to the GKE cluster.

    skaffold run --default-repo=us-central1-docker.pkg.dev/$PROJECT_ID/images
  19. Wait for all the pods to be up and running. You can then find the external IP and navigate to it.

    kubectl get pods
    kubectl get services