Query VPC index to get nearest neighbors

Once you've created the index, you can run queries to get its nearest neighbors.

Each DeployedIndex has a DEPLOYED_INDEX_SERVER_IP, which you can retrieve by listing IndexEndpoints. To query a DeployedIndex, connect to its DEPLOYED_INDEX_SERVER_IP at port 10000 and call the Match or BatchMatch method. Additionally, you can query using DOC_ID.

The following examples use the open source tool grpc_cli to send grpc requests to the deployed index server.

gRPC

In the first example, you send a single query using the Match method.

./grpc_cli call ${DEPLOYED_INDEX_SERVER_IP}:10000 google.cloud.aiplatform.container.v1.MatchService.Match '{deployed_index_id: "${DEPLOYED_INDEX_ID}", float_val: [-0.1,..]}'

In the second example, you combine two separate queries into the same BatchMatch request.

./grpc_cli call ${DEPLOYED_INDEX_SERVER_IP}:10000 google.cloud.aiplatform.container.v1.MatchService.BatchMatch 'requests: [{deployed_index_id: "${DEPLOYED_INDEX_ID}", requests: [{deployed_index_id: "${DEPLOYED_INDEX_ID}", float_val: [-0.1,..]}, {deployed_index_id: "${DEPLOYED_INDEX_ID}", float_val: [-0.2,..]}]}]'

You must make calls to these APIs from a client running in the same [VPC that the service was peered with](#vpc-network-peering-setup).

To run a query using a DOC_ID, use the following example.

./grpc_cli call ${DEPLOYED_INDEX_SERVER_IP}:10000  google.cloud.aiplatform.container.v1.MatchService.Match "deployed_index_id:'"test_index1"',embedding_id: '"606431"'"

To learn more, see Client libraries explained.

Console

Use these instructions to query a VPC index from the console.

  1. In the Vertex AI section of the Google Cloud console, go to the Deploy and Use section. Select Vector Search

    Go to Vector Search

  2. Select the VPC index you want to query. The Index info page opens.
  3. Scroll down to the Deployed indexes section and select the deployed index you want to query. The Deployed index info page opens.
  4. From the Query index section, select your query parameters. You can choose to query by a vector, or a specific data point.
  5. Execute the query using the open source tool grpc_cli, or by using the Vertex AI SDK for Python.

What's next