This is a sample Node.js and React.js application that demonstrates how to build generative AI application using Google Vertex AI and YugabyteDB.
The application provides lodging recommendations for travelers visiting San Francisco.
Using Google Vertex AI, text embeddings (a vectorized representation of the data) are generated for each listing description and stored in YugabyteDB, using the PostgreSQL pgvector
extension. The user's prompt is similarly converted to text embeddings using Google Vertex AI and subsequently used to execute a similarity search in YugabyteDB, finding properties with descriptions related to the user's prompt.
- A Google Cloud account with appropriate permissions
- A YugabyteDB cluster of version 2.19.2 or later
- Install Node.js v18+
- Install Docker
- Clone the repository.
git clone https://github.com/YugabyteDB-Samples/yugabytedb-google-vertexai-lodging-service.git
- Install the application dependencies.
cd {project_directory}/backend npm install cd {project_directory}/frontend npm install
- Configure the application environment variables in
{project_directory/backend/.env}
.
- Start a YugabyteDB isntance of version 2.19.2 or later:
mkdir ~/yb_docker_data
docker network create custom-network
docker run -d --name yugabytedb_node1 --net custom-network \
-p 15433:15433 -p 7001:7000 -p 9001:9000 -p 5433:5433 \
-v ~/yb_docker_data/node1:/home/yugabyte/yb_data --restart unless-stopped \
yugabytedb/yugabyte:2.19.2.0-b121 \
bin/yugabyted start \
--base_dir=/home/yugabyte/yb_data --daemon=false
docker run -d --name yugabytedb_node2 --net custom-network \
-p 15434:15433 -p 7002:7000 -p 9002:9000 -p 5434:5433 \
-v ~/yb_docker_data/node2:/home/yugabyte/yb_data --restart unless-stopped \
yugabytedb/yugabyte:2.19.2.0-b121 \
bin/yugabyted start --join=yugabytedb_node1 \
--base_dir=/home/yugabyte/yb_data --daemon=false
docker run -d --name yugabytedb_node3 --net custom-network \
-p 15435:15433 -p 7003:7000 -p 9003:9000 -p 5435:5433 \
-v ~/yb_docker_data/node3:/home/yugabyte/yb_data --restart unless-stopped \
yugabytedb/yugabyte:2.19.2.0-b121 \
bin/yugabyted start --join=yugabytedb_node1 \
--base_dir=/home/yugabyte/yb_data --daemon=false
The database connectivity settings are provided in the {project_dir}/backend/.env
file and do not need to be changed if you started the cluster with the command above.
-
Create the database schema.
psql -h 127.0.0.1 -p 5433 -U yugabyte -d yugabyte -f {project_dir}/sql/0_airbnb_listings.sql
-
Load the sample dataset with properties in San Francisco.
psql -h 127.0.0.1 -p 5433 -U yugabyte
\copy airbnb_listing from '{project_directory}/sql/sf_airbnb_listings.csv' DELIMITER ',' CSV HEADER;
-
Add the PostgreSQL
pgvector
extension anddescription_embedding
column of type vector.psql -h 127.0.0.1 -p 5433 -U yugabyte -d yugabyte -f {project_dir}/sql/1_airbnb_embeddings.sql
To start using Google Vertex AI in the application
- Create a project in Google Cloud.
- Enable the Vertex AI API.
- Install the (gcloud command-line utility)[https://cloud.google.com/sdk/docs/install].
- Log-in to Google Cloud via the CLI to run the application locally.
gcloud auth application-default login
- Update the Google Vertex AI environment variables in
{project_dir}/backend/.env
.
Airbnb properties come with detailed descriptions of of the accomodations, location, and various other features of the listing. By transforming the text in the description
column of our database into a vectorized representation, we can use pgvector
to execute a similarity search based on user prompts.
Execute the embeddingsGenerator.js
script to generate embeddings in Google Vertex AI for each property, and store them in the description_embedding
column in the database. This process can take over 10 minutes to complete.
node {project_directory}/backend/vertex/embeddingsGenerator.js
....
Processing rows starting from 34746755
Processed 7551 rows
Processing rows starting from 35291912
Finished generating embeddings for 7551 rows
-
Start the Node.js backend.
cd {project_dir}/backend npm start
-
Start the React UI.
npm run dev
-
Access the application UI at http://localhost:5173.
-
Test the application with relevant prompts. For instance:
We're traveling to San Francisco from February 21st through 28th. We need a place to stay with parking available.
I'm looking for an apartment near the Golden Gate Bridge with a nice view of the Bay.
Full house with ocean views for family of 6.
Room for 1 in downtown SF, walking distance to Moscone Center.