Once you've created a PSA or PSC index, you can run queries to get its nearest neighbors.
About querying PSC indexes
The created compute address from a PSC index can be used to send queries to it.
In the following example, replace TARGET_IP
with the created
compute address.
About querying PSA indexes
Each DeployedIndex
has a TARGET_IP
, which you can retrieve by
listing IndexEndpoints
.
Query an index
To query a DeployedIndex
, connect to its TARGET_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 ${TARGET_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 ${TARGET_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 ${TARGET_IP}:10000 google.cloud.aiplatform.container.v1.MatchService.Match "deployed_index_id:'"test_index1"',embedding_id: '"606431"'"
In this example, you send a query using token and numeric restricts.
./grpc_cli call ${TARGET_IP}:10000 google.cloud.aiplatform.container.v1.MatchService.Match 'deployed_index_id: "${DEPLOYED_INDEX_ID}", float_val: [1, 1], "sparse_embedding": {"values": [111.0,111.1,111.2], "dimensions": [10,20,30]}, numeric_restricts: [{name: "double-ns", value_double: 0.3, op: LESS_EQUAL}, {name: "double-ns", value_double: -1.2, op: GREATER}, {name: "double-ns", value_double: 0., op: NOT_EQUAL}], restricts: [{name: "color", allow_tokens: ["red"]}]'
To learn more, see Client libraries explained.
Console
Use these instructions to query a VPC index from the console.
- In the Vertex AI section of the Google Cloud console, go to the Deploy and Use section. Select Vector Search
- Select the VPC index you want to query. The Index info page opens.
- Scroll down to the Deployed indexes section and select the deployed index you want to query. The Deployed index info page opens.
- From the Query index section, select your query parameters. You can choose to query by a vector, or a specific data point.
- Execute the query using the open source tool grpc_cli, or by using the Vertex AI SDK for Python.
Query-time settings that impact performance
The following query-time parameters can affect latency, availability, and cost when using Vector Search. This guidance applies to most cases. However, always experiment with your configurations to make sure that they work for your use case.
For parameter definitions, see Index configuration parameters.
Parameter | About | Performance impact |
---|---|---|
approximateNeighborsCount |
Tells the algorithm the number of approximate results to retrieve from each shard.
The value of |
Increasing the value of
Decreasing the value of
|
setNeighborCount |
Specifies the number of results that you want the query to return. |
Values less than or equal to 300 remain performant in most use cases. For larger values, test for your specific use case. |
fractionLeafNodesToSearch |
Controls the percentage of leaf nodes to visit when searching for nearest
neighbors. This is related to the leafNodeEmbeddingCount in
that the more embeddings per leaf node, the more data examined per leaf.
|
Increasing the value of
Decreasing the value of
|
What's next
- Learn how to Update and rebuild your index
- Learn how to Filter vector matches
- Learn how to Monitor an index