-
Make sure you've setup and initialized your Database.
-
Install Python 3.11+
-
Install dependencies. We recommend using a virtualenv:
pip install -r retrieval_service/requirements.txt -r langchain_tools_demo/requirements.txt
-
Install test dependencies:
pip install -r retrieval_service/requirements-test.txt -r langchain_tools_demo/requirements-test.txt
-
Change into the service directory:
cd retrieval_service
-
Open a local connection to your database by starting the Cloud SQL Auth Proxy or a SSH tunnel to your AlloyDB instance.
-
You should already have a
config.yml
created with your database config. Continue to usehost: 127.0.0.1
andport: 5432
, unless you instruct the proxy to listen or the SSH tunnel to forward to a different address. -
To run the app using uvicorn, execute the following:
python run_app.py
-
Change into the demo directory:
cd langchain_tools_demo
-
To use a live retrieval service on Cloud Run:
-
Set Google user credentials:
gcloud auth login
-
Set
BASE_URL
environment variable:export BASE_URL=$(gcloud run services describe retrieval-service --format 'value(status.url)')
-
Allow your account to invoke the Cloud Run service by granting the role Cloud Run invoker
-
-
[Optional] Turn on debugging by setting the
DEBUG
environment variable:export DEBUG=True
-
To run the app using uvicorn, execute the following:
python main.py
Note: for hot reloading of the app use:
uvicorn main:app --host 0.0.0.0 --reload
-
View app at
http://localhost:8081/
-
Change into the
retrieval_service
directory -
Open a local connection to your database by starting the Cloud SQL Auth Proxy or a SSH tunnel to your AlloyDB instance.
-
Set environment variables:
export DB_USER="" export DB_PASS="" export DB_NAME=""
-
Run pytest to automatically run all tests:
pytest
Cloud Build is used to run tests against Google Cloud resources in test project: extension-demo-testing. Each test has a corresponding Cloud Build trigger, see all triggers.
Create a Cloud Build trigger via the UI or gcloud
with the following specs:
- Event: Pull request
- Region:
- us-central1 - for AlloyDB to connect to private pool in VPC
- global - for default worker pools
- Source:
- Generation: 1st gen
- Repo: GoogleCloudPlatform/genai-databases-retrieval-app (GitHub App)
- Base branch:
^main$
- Comment control: Required except for owners and collaborators
- Filters: add directory filter
- Config: Cloud Build configuration file
- Location: Repository (add path to file)
- Substitution variables:
- Add
_DATABASE_HOST
for AlloyDB IP address
- Add
- Service account: set for demo service to enable ID token creation to use to authenticated services
- Follow instructions to setup the test project:
- Setup Cloud Build triggers (above)
- Create a Cloud Build private pool
- Enable Secret Manager API
- Create secret,
alloy_db_pass
, with your AlloyDB password - Create secret,
alloy_db_user
, with your AlloyDB user - Allow Cloud Build to access secret
- Add role Vertex AI User (roles/aiplatform.user) to Cloud Build Service account. Needed to run database init script.
- Add roles Cloud Run Admin, Service Account User, Log Writer, and Artifact Registry Admin to the demo service's Cloud Build trigger service account.
-
Run Demo Service integration test:
gcloud builds submit --config langchain_tools_demo/int.tests.cloudbuild.yaml
-
Run retrieval service unit tests:
gcloud builds submit --config retrieval_service/alloydb.tests.cloudbuild.yaml \ --substitutions _DATABASE_HOST=$DB_HOST,_DATABASE_NAME=$DB_NAME,_DATABASE_USER=$DB_USER
Where
$DB_HOST
,$DB_NAME
,$DB_USER
are environment variables with your database values.Note: Make sure to setup secrets describe in Setup for retrieval service
To run Cloud Build tests on GitHub from external contributors, ie RenovateBot, comment: /gcbrun
.