A Vertex AI Search Demo
- Try it here -> https://www.cymbalsearch.com (Controlled access)
Speed up 1.5x for optimal experience:
Disclaimer: This is NOT an official Google project.
Created by elroylbj@
You need to set up a Google Cloud Project with a Vertex AI Search app (unstructured datastore) and a GCS bucket. With these set up, you can simply define the environment variables and run the Dockerfile anywhere to deploy your app.
- Create a Google Cloud project if you don't already have one.
Create a Vertex AI Search with unstructured datastore with defined metadata.
- Go to Search & Conversation page and enable the api if prompted
- Select
Search
- At Configuration,
- Enable all features
- Set your App Name
- Set location as global
- Click
CONTINUE
- Create a new data store - select
Cloud Storage
- At Data import, we will load a set of public PDFs using a JSON file:
- Select
FILE
- In the gs:// textbox, input
cymbalsearch-alphabet-public/metadata/metadata.json
- Select
JSON for unstructured documents with metadata
- Click
CONTINUE
- Select
- Give your data store a name and click
CREATE
(wait a few seconds for datastore to create) - Select your newly-created data store and click
CREATE
to create app - After around 10 minutes, the import status should show "Import completed".
- Congratulations! Play around with the app in the Preview and Configurations tabs in the console.
Create a bucket to be used for uploading of new documents using the UI.
- Create a GCS bucket either in console or run this gcloud command in Cloud Shell:
export BUCKET_FOR_UPLOAD=$BUCKET_NAME
gcloud storage buckets create gs://$BUCKET_FOR_UPLOAD
- Configure CORS for your bucket.
echo '[{"origin": ["*"], "method": ["GET"], "responseHeader": ["Content-Type"],"maxAgeSeconds": 3600}]' > cors.json
gsutil cors set cors.json gs://$BUCKET_FOR_UPLOAD
These instructions are suggested to be run in your GCP Project's Cloud Shell.
However, if you would like to run them locally, set up Application Default Credentials (ADC).
Follow this guide to create your personal access token. Then substitute the <token_name> and <token_value> below and run the command to clone the repository.
git clone https://<token_name>:<token_value>@gitlab.com/google-cloud-ce/googlers/elroylbj/cymbal-search.git
Please replace these with your project details:
- Add
ENGINE_2
andENGINE_3
if you want more apps. - Leave
MODEL_1
andMODEL_2
values unchanged if there are no changes to the PaLM models.
export PROJECT_ID="PROJECT_ID"
export BUCKET_FOR_UPLOAD="BUCKET_NAME"
export ENGINE_1="VERTEX_AI_SEARCH_DATASTORE_ID"
export MODEL_1="text-bison"
export MODEL_2="text-bison-32k"
Set deployment details (leave the default values at your convenience):
export APP_NAME=cymbalsearch
export SERVICE_ACC=cymbalsearch-sa
export REGION=asia-southeast1
export REPOSITORY=my-repo
export IMAGE=my-image
export TAG=1.0
REGION
is the regional or multi-regional location of the repository.REPOSITORY
is the name of the repository where the image is stored.IMAGE
is the name of the image in the repository.TAG
is the tag of the image version that you want to pull.
Firstly, ensure you are in the root directory of the repository.
cd cymbal-search/
Next, run the script below:
chmod +x deploy.sh
./deploy.sh
The deploy.sh
script does the following:
- Enable required APIs (requires the
roles/servicemanagement.serviceConsumer
role). - Create Service Account with required permissions (requires the
roles/iam.serviceAccountCreator
role). - Create Artifact Repository (requires the
roles/artifactregistry.admin
role). - Build image and push to Artifact Registry.
Visit the Artifact Registry console to view your Docker image. It will take around 10 minutes for the build to complete.
Option 1: Cloud Run
- If you are running in an Argolis Project, overwrite the Organization Policy as seen here to be able to
unauthenticated invocations
. - Deploy Cloud Run using the command below. Add ENGINE_2 and ENGINE_3 in the env vars if you want to.
gcloud run deploy $APP_NAME \ --image $REGION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$TAG \ --region $REGION \ --service-account=$SERVICE_ACC@$PROJECT_ID.iam.gserviceaccount.com \ --allow-unauthenticated \ --set-env-vars=PROJECT_ID=$PROJECT_ID,BUCKET_FOR_UPLOAD=$BUCKET_FOR_UPLOAD,ENGINE_1=$ENGINE_1,MODEL_1=$MODEL_1,MODEL_2=$MODEL_2
Option 2: App Engine
- Create a
app.yaml
file at the project root where the Dockerfile is located. See yaml reference for more configurations.Check that your env variables are reflected in the app.yaml:echo "runtime: custom env: flex env_variables: PROJECT_ID: $PROJECT_ID BUCKET_FOR_UPLOAD: $BUCKET_FOR_UPLOAD ENGINE_1: $ENGINE_1 MODEL_1: $MODEL_1 MODEL_2: $MODEL_2 " > app.yaml
cat app.yaml
- To deploy the app, run the following command from the directory where your app.yaml and Dockerfile are located:
gcloud app deploy --image-url=$REGION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$TAG
- To see your app running at
https://PROJECT_ID.REGION_ID.r.appspot.com
, run the following command to launch your browser:gcloud app browse
- If there are any permission errors, check which Service Account your app engine is using (likely App Engine default service account with Editor role).
Go to the IAM page at console to ensure the Service Account has the following roles (for convenience, Editor role will solve the issue):- Discovery Engine Admin
- Logs Writer
- Storage Object User
- Vertex AI User
All commands should be run at project root directory.
-
Download required software and set to PATH.
- Download Python (3.11.4)
- Download npm (9.7.1) and node (v18.16.1)
-
Set your GCP Project environment variables.
export PROJECT_ID="Project ID" export BUCKET_FOR_UPLOAD="GCS Bucket name for document upload" export ENGINE_1="Vertex AI Search Engine ID" export ENGINE_2="Vertex AI Search Engine ID of a 2nd app (if any)" export ENGINE_3="Vertex AI Search Engine ID of a 3rd app (if any)" export MODEL_1="text-bison" export MODEL_2="text-bison-32k"
-
Set up Application Default Credentials (ADC) for your local development environment.
- Install and initialize the gcloud CLI.
- Login with your Google Cloud user credentials:
gcloud auth application-default set-quota-project <PROJECT_ID> gcloud auth application-default login gcloud config set project <PROJECT_ID>
-
Install Python dependencies.
python -m venv env source env/bin/activate pip install -r backend/requirements.txt
-
Run Python backend.
python backend/app.py
-
Open another terminal and install the React dependencies.
npm install
-
Run the React app.
npm start
Open http://localhost:3000 to access your app with Hot Reload capabilities to develop your app dynamically.
This project was bootstrapped with Create React App, using the Redux and Redux Toolkit template.
You can learn more in the Create React App documentation.
To learn React, check out the React documentation.
Created by elroylbj@
Disclaimer: This is NOT an official Google project.