Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Create a service account
/ 25
Create an Apigee API proxy
/ 25
Test the API proxy
/ 50
Create a service account
/ 25
Create an Apigee API proxy
/ 25
Test the API proxy
/ 50
Apigee is a platform for developing and managing APIs. Apigee can help you leverage Google Cloud services like Gemini Enterprise Agent Platform, Pub/Sub, Cloud Logging, or any other cloud service providing a REST API.
When using LLMs, it is highly beneficial to intelligently and efficiently serve identical or semantically similar prompts by minimizing API calls to backend models and reducing resource consumption. Apigee provides semantic caching policies that enable intelligent response reuse based on semantic similarity. By using these policies in your Apigee API proxy, you can minimize redundant backend API calls, reduce latency, and lower operational costs of your API.
In this lab, you develop an Apigee API proxy to perform a semantic similarity search of similar request prompts using Vector Search on Gemini Enterprise Agent Platform as an embeddings database. A semantic similarity search compares the vector proximity of the prompt to prior requests and uses a configurable similarity score threshold. If a similar prompt data point is found, the cached response is returned to the client. If no similar previous prompt is found in Vector Search, the request is sent to the backend, where the LLM generates a response. Apigee caches the model response and returns it to the client. Then, it updates the Vector Search index for future API requests.
In this lab, you learn how to perform the following tasks:
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the right is the Lab setup and access panel with the following:
Note that the lab timer is located near the top of the page, showing the remaining time.
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab setup and access panel.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab setup and access panel.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
Click Activate Cloud Shell at the top of the Google Cloud console.
Click through the following windows:
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Output:
gcloud, in Google Cloud, refer to the gcloud CLI overview guide.
In this task, you verify a service account to be used by the Apigee proxy.
apigee-gc-service-access service account and its project-level role (roles/aiplatform.user) have been pre-provisioned for you during lab startup. You can verify the service account in IAM & Admin > Service Accounts and click Check my progress.In Cloud Shell, set environment variables:
Verify that the service account is created:
Verify that the service account has the Agent Platform User (roles/aiplatform.user) role:
To enable the Apigee API proxy to authenticate with services on Google Cloud using Google access tokens, grant the Service Account Token Creator (roles/iam.serviceAccountTokenCreator) role to the Apigee Service Agent on the apigee-gc-service-access service account:
Click Check my progress to verify the objective.
The Apigee semantic caching policies use Vector Search to find similar prompts based on semantic similarity and update Vector Search with embeddings for new prompts.
Vector Search is a powerful vector search engine from Google that leverages the ScaNN (Scalable Nearest Neighbors) algorithm. It enables you to build next-generation search and recommendation systems and generative AI applications.
To use Vector Search, you create an index to quickly and efficiently find semantically related items. In this lab, you index text prompts submitted in requests to the Apigee API proxy.
An index consists of one or more files that contain embedding vectors. With Vector Search, you can create an index designed for batch updates or an index designed for streaming updates. In this subtask, you create an index for streaming updates. The API proxy will update the index when a submitted prompt is not found in the Vector Search database.
In the Google Cloud console, from the Navigation menu (), navigate to Agent Platform > Agents > Vector Search.
An index has been pre-created for this lab. To list the indexes for your region, on the Indexes tab, from the Region drop-down list, select
To view the index configuration, click the index name apigee-semantic-cache-index.
Some of the configuration properties are:
| Property | Value |
|---|---|
| Dimensions | 768 |
| Approximate Neighbors Count | 150 |
| Distance measure type | Dot product distance |
| Update method | Stream |
For more information, read the documentation on index configuration parameters.
Confirm that the Status indicates that the index is Ready. If not, wait until the index is Ready.
Before you can query the Vector Search index, you must first create an index endpoint and deploy the index to that endpoint.
An index endpoint is a dedicated network access point that hosts one or more deployed Vector Search indexes. It acts as the server instance that processes query requests against your indexes. An index endpoint has been pre-created for this lab.
On the Vector Search page for the apigee-semantic-cache-index, click the Deployed indexes tab.
To view the endpoint details, click the index endpoint name.
The Access type of Public enables the endpoint to be accessible over the internet with OAuth authentication. You can also create an index endpoint for private access using Private Service Connect or using VPC Network Peering.
The Public domain name is part of the unique URL used to send Vector Search queries to a deployed index.
To navigate back to the list of index endpoints, click Index endpoint list.
Confirm that the Status indicates the index endpoint is Ready. If not, wait until the endpoint is Ready.
The lab initiates the index deployment automatically. Under Deployed indexes, check for the deployment status.
The deployment might still be in progress. A green check mark is displayed when the deployment is complete.
Note: Initial deployment of an index to an endpoint can take between 20 and 30 minutes to complete. You can continue to the next task to create the Apigee API proxy while the index deployment is in progress.
In this task, you create the Apigee API proxy. The API proxy will use a specific proxy template that contains the semantic cache policies.
Before developing the API proxy, set a few environment variables that will be used to configure the proxy.
In Cloud Shell, retrieve and set the index ID environment variable:
Retrieve and set the index endpoint ID environment variable:
Retrieve and set the public endpoint domain name environment variable:
To open the Apigee console:
Apigee into the Search bar, then select Apigee from the Products & pages results.The Apigee console will open, where you can manage APIs, environments, proxies, and deployments.
From the Apigee navigation menu, click Proxy development > API proxies.
To create a new proxy using the proxy wizard, click Create.
For Proxy template, select AI template > Proxy with Semantic Cache.
For Proxy details, specify the following:
| Property | Value |
|---|---|
| Proxy name | cachellm-v1 |
| Base path | /cachellm/v1 |
| Target (Existing API) |
/cachellm/v1 for the base path, not /cachellm-v1.Under Semantic Cache URLs, for Generate Embeddings URL, append this value to the https:// prefix:
This URL points to the embeddings model that converts text input into numerical form for semantic analysis.
For Query Nearest Neighbour URL, execute the command in Cloud Shell, and append the command output to the https:// prefix:
This URL points to the Agent Platform service that uses the Vector Search index you created earlier to search for similar text prompts from previous requests to the API proxy.
For Upsert index URL, execute the command in Cloud Shell, and append the command output to the https:// prefix:
This URL points to the Agent Platform service that updates the Vector Search index with new or modified entries.
Click Next.
Leave the remaining settings as their defaults, and click Create.
The Apigee API proxy is created with two AI policies automatically added to the proxy:
The SemanticCacheLookup policy uses the Text embeddings API to generate embeddings for text, and Vector Search to find similar prompts based on semantic similarity, rather than exact matches.
In this subtask, you make a few updates to the policy.
First, set an environment variable for the deployed index ID:
DEPLOYED_INDEX_ID variable is empty, wait for the index to be deployed to the endpoint. You can verify this on the Agent Platform > Agents > Vector Search > Index Endpoints page in the console. After it is deployed, rerun the command to set the DEPLOYED_INDEX_ID environment variable.To update the policy, click the Develop tab in the Proxy Editor.
In the navigation menu in the Apigee UI, select Policies > Semantic Cache Lookup.
In the SCL-Semantic-Cache-Lookup.xml file, update the <DeployedIndexID> element with the value of the DEPLOYED_INDEX_ID variable from the earlier step.
Leave the remaining elements as their defaults. The updated XML file should look similar to:
The policy includes:
jsonPath() is a function in Apigee that is used to select or extract data from a JSON message payload or JSON variable. In this case, it returns the value of the text field in the last element of the parts[] array within the last element of the contents[] array from the request message sent to the API proxy. This JSON structure is required to extract the input prompt that is sent to the Gemini model.To save the changes to the policy, click Save.
The SemanticCachePopulate policy is used in conjunction with the SemanticCacheLookup policy.
The policy updates a Vector Search index and caches API responses based on semantic similarity of the text prompt in the input request.
Note that although the SemanticCacheLookup policy is added to the API proxy endpoint request, the SemanticCachePopulate policy is added to the API target endpoint response. To use the policy, you must provide the index ID of a Vector Search index.
To update the policy, click the Develop tab in the Proxy Editor.
In the navigation menu in the Apigee UI, select Policies > Semantic Cache Populate.
In the SCP-Semantic-Cache-Populate.xml file, update the time to live <TTLInSeconds> element to 600 seconds.
The SCP-Semantic-Cache-Populate.xml file should look similar to:
The policy includes:
upsertDatapoints operation inserts or updates the index with a vector embedding.To save the changes to the policy, click Save.
The <HTTPTargetConnection>/<Authentication> element in the API proxy TargetEndpoint is used to make authenticated calls to the model endpoint running on Google Cloud. Apigee uses the service account you created earlier in the lab to generate the necessary token required to securely call the endpoint.
Click the Develop tab in the Proxy Editor.
In the Navigator menu for the proxy, in the Target endpoints section, click default > PreFlow.
In the default.xml file, find the following code (your URL will be slightly different):
<HTTPTargetConnection> section, confirm that you clicked PreFlow in the Target endpoints section, and not in the Proxy endpoints section.Above the <URL> element, add this <Authentication> element:
Your TargetEndpoint code should now look similar to this:
The Authentication section specifies the authentication for the Google Cloud API. A Google OAuth access token is automatically added to the request to the target URL. The Scope specifies that the access token provides access to the model endpoint.
To save changes to the API proxy, click Save.
Click Check my progress to verify the objective.
In Cloud Shell, paste and run the following command:
This series of commands uses the Apigee API to determine when the Apigee runtime instance has been created and the eval environment has been attached.
Wait until the instance is ready.
When the text ***ORG IS READY TO USE*** is displayed, the instance is ready. The Apigee organization (org) may have been created before you started the lab, so you might not have to wait for the instance to be created.
If you are waiting for the org to be ready, you can explore the AI products and services on Google Cloud.
Before deploying and testing the Apigee API proxy, confirm that the Vector Search index has been deployed to the index endpoint.
In the Google Cloud console, from the Navigation menu (), navigate to Agent Platform > Agents > Vector Search.
Confirm that the index has been deployed. A green status check under Deployed indexes is visible indicating the index is deployed. If it is not yet visible, wait until the index is deployed.
After the index is deployed and the green check is displayed, expand the Deployed indexes list.
To view the details of the deployed index, click its name.
From the Navigation menu (), navigate to Apigee > API proxies.
In the Apigee UI, select the cachellm-v1 API proxy, and click the Develop tab.
Click Deploy.
For Environment, select eval.
For Service Account, specify the service account's email address:
Click Deploy.
In the confirmation dialog, click Confirm.
Click the Overview tab, and wait until the eval deployment status indicates that the proxy is deployed.
The eval environment in the Apigee organization can be called using the hostname eval.example.com. The DNS entry for this hostname has been created within your project, and it resolves to the IP address of the Apigee runtime instance. This DNS entry has been created in a private zone, which means it is only visible on the internal network.
Cloud Shell does not reside on the internal network, so Cloud Shell commands cannot resolve this DNS entry. A virtual machine (VM) within your project can access the private zone DNS. A virtual machine named apigeex-test-vm was automatically created. You can use this machine to call the API proxy.
In Cloud Shell, open an SSH connection to your test VM:
If asked Do you want to continue (Y/n)?, type Y.
For each question asked in Cloud Shell, press ENTER to specify the default input.
Your logged in identity is the owner of the project, so SSH to this machine is allowed.
Your Cloud Shell session is now running inside the VM.
In the Apigee proxy UI, click the Debug tab.
Click Start Debug Session.
In the Start debug session pane, from the Environment drop-down list, select eval.
The deployed revision number is also displayed in the drop-down list.
Click Start.
In the Cloud Shell SSH session on the test VM, call the deployed cachellm-v1 API proxy in the eval environment:
contents array contains the conversation or prompt in the text field of the parts array, and the generationConfig element requests that the model return only one generated response or candidate.The response from the API includes the model response.
In the Transactions pane on the left, select the transaction for the request to view the trace of the request and response through Apigee.
You should see a 200 Status if your backend URL was correctly set and you correctly sent the curl command.
The debug session transactions pane shows a list of transactions that have been received since the debug session was started.
In the main debug panel, hover over the policy and flow items to review their execution.
In this transaction, the SemanticCacheLookup policy was executed in the proxy request flow, the target endpoint (model) was invoked, and the SemanticCachePopulate policy was executed in the target response flow to cache the response from the model. Also note the elapsed time of the request, which in this case was 13708 milliseconds.
Send another similar prompt in the request to the API:
In the main debug panel, hover over the policy and flow items to review their execution.
In this transaction, the request was not sent to the target (model) endpoint, because a semantically similar prompt was found in Vector Search. The entire target endpoint was skipped, and the SemanticCacheLookup policy was executed to fetch the cached model response. This response was cached by the SemanticCachePopulate policy that was executed in the previous transaction. Also note the elapsed time of this request, which in this case was only 207 milliseconds, which is considerably less than that of the previous transaction.
Repeat the curl calls on the test VM with similar prompts:
All of these calls should result in the same cached model response from the API.
Note: The TTL configuration in the SemanticCachePopulate policy is set at 600 seconds (10 minutes). If this time has already elapsed, some of these calls might result in the API proxy calling the target (model) endpoint and re-caching the model response.
Finally, perform another test with a prompt that is close but different enough to confirm that the response is not served from the cache:
Click Check my progress to verify the objective.
In this lab, you:
Manual Last Updated on November 6, 2026
Manual last tested on October 30, 2026
Copyright 2026 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We can notify you via email when it becomes available
Great!
We can contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one