I know I can use the API version https://discoveryengine.googleapis.com
but I want to try integration via the go package. Can anyone please help me solve the issue?
The package is in beta .. no example from the net yet
package gcp
import (
"context"
"fmt"
"log"
"virtual-idol-api/config"
"cloud.google.com/go/storage"
"google.golang.org/api/option"
discoveryengine "cloud.google.com/go/discoveryengine/apiv1beta"
discoveryenginepb "cloud.google.com/go/discoveryengine/apiv1beta/discoveryenginepb"
)
// NewGCPStorageClient creates a new GCPClient and initializes its dependencies based on the environment.
func NewGCPClient(cfg *config.Config) (*GCPClient, error) {
client := GCPClient{}
ctx := context.Background()
var discoveryClient *discoveryengine.SearchClient
var err error
discoveryClient, err = discoveryengine.NewSearchClient(ctx)
if err != nil {
log.Fatalf("failed to create Discovery client: %s", err)
return nil, err
}
client.DiscoveryClient = discoveryClient
defer discoveryClient.Close()
req := &discoveryenginepb.SearchRequest{
ServingConfig: "projects/12345/locations/global/collections/default_collection/dataStores/test-unstructured_12456/servingConfigs/default_search:search",
//Branch: "default_search",
Query: "who is the president of America",
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/discoveryengine/apiv1beta/discoveryenginepb#SearchRequest.
}
res := discoveryClient.Search(ctx, req)
if res == nil {
log.Println("Search result is nil")
} else {
fmt.Printf("%+v\n", *res)
}
return &client, nil
}
I always receive null value
NOTE: Generative AI App Builder is currently allowlist only, so make sure your project and account have the appropriate access.
First, ensure that you've created a search engine in your project as outlined in this guide:
https://cloud.google.com/generative-ai-app-builder/docs/try-enterprise-search
You'll need to follow the instructions at Gen App Builder client libraries to install and configure the
discoveryengine
client library for Go.The code sample that was on that page previously is autogenerated and doesn't include all of the parameters needed for the requests to be successful. Follow the comment listed in the code sample for the full list of parameters.
https://pkg.go.dev/cloud.google.com/go/discoveryengine/apiv1beta/discoveryenginepb#SearchRequest
A new go code sample was just added to the client library documentation page that includes more sample parameters. Here's what it is so you can follow it.