Query indexes 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.

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.

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

./grpc_cli call  google.cloud.aiplatform.container.v1.MatchService.Match "deployed_index_id:'"test_index1"',embedding_id: '"606431"'"

You can also run these queries with the Python Cloud Client Library for Vertex AI.

To learn more, see Client libraries explained

What's next