I am attempting to utilize the Go Vertex AI SDK in order to use some of the functionalities on Vertex AI. Specifically, I want to query from a deployed matching engine index via Go.
Here is my implementation:
package main
import (
"fmt"
"context"
"regexp"
aiplatformpb "cloud.google.com/go/aiplatform/apiv1/aiplatformpb"
aiplatform "cloud.google.com/go/aiplatform/apiv1"
"google.golang.org/api/option"
"google.golang.org/protobuf/types/known/structpb"
)
func embedTexts() {
...
}
func main() {
ctx := context.Background()
query_string_arr := []string{"Some text to be used as a query for nearest neighbors"}
var project_id = "<project id>"
var location = "us-central1"
// Get text embeddings for query
embeddings, err := embedTexts(project_id, location, query_string_arr)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println("The length of the embedding vector is:")
fmt.Println(len(embeddings[0]))
}
// ensure that we are hitting the correct API endpoint for vector search client
apiEndpoint := fmt.Sprintf("%s-aiplatform.googleapis.com:443", location)
// initialize matching engine client
c, err := aiplatform.NewMatchClient(ctx, option.WithEndpoint(apiEndpoint))
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println("Vector Search Client successfully initialized!")
}
// // initialize structs to create request body
//// 1. initialize the index datapoint restriction struct
restricts_params := &aiplatformpb.IndexDatapoint_Restriction{
Namespace: "<some namespace>",
AllowList: []string{"<some value to allow for namespace>"},
}
//// 2. initialize the index datapoint struct
query_datapoint := &aiplatformpb.IndexDatapoint{
DatapointId: "<Placeholder>",
FeatureVector: embeddings[0],
Restricts: []*aiplatformpb.IndexDatapoint_Restriction{restricts_params},
}
//// 3. initialize the query struct
find_nbrs_query := &aiplatformpb.FindNeighborsRequest_Query{
Datapoint: query_datapoint,
NeighborCount: 50,
}
//// 4. initialize the nearest neighbors request struct
req := &aiplatformpb.FindNeighborsRequest{
IndexEndpoint: "projects/<project number>/locations/us-central1/indexEndpoints/<vector search index endpoint id>",
DeployedIndexId: "<vector search index id>",
Queries: []*aiplatformpb.FindNeighborsRequest_Query{find_nbrs_query},
ReturnFullDatapoint: true,
}
// send request to vector search
resp, err := c.FindNeighbors(ctx, req)
if err != nil {
fmt.Println("Failing at vector search request time.")
fmt.Println(err.Error())
} else {
fmt.Println("Vector Search Request successfully sent!")
}
defer c.Close()
for _, neighbor := range resp.GetNearestNeighbors() {
fmt.Printf("Neighbor ID:%sn", neighbor.Id)
}
}
However, I’ve come across a particular error that I cannot seem to resolve.
rpc error: code = Unimplemented desc = Operation is not implemented, or supported, or enabled.
This is failing at the snippet of code where I am calling c.FindNeighbors
. This seems to indicate that:
- The endpoint I am using,
us-central1-aiplatform.googleapis.com:443
, is not the correct endpoint to be using for calling the vector search index endpoint. - The method I am using is incorrect somehow (although the compiler did not throw any errors at me).
In either of these cases, what methods should I be using? Or what endpoint should I be hitting? This is a rather open-ended question, but I am not sure how to proceed (I am also rather new to Go so please give some pointers as well if I seem to misunderstand something in my code snippet!)
Side note: I have also checked that I have full access to my GCP environment. In fact, my POST
requests from CLI work as intended. I am just struggling with making the gRPC call via Go.