Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(samples): Recreate Vertex AI Search samples #4389

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions discoveryengine/datastore_management.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package discoveryengine

// [START genappbuilder_create_data_store]
import (
"context"
"fmt"

discoveryengine "cloud.google.com/go/discoveryengine/apiv1"
discoveryenginepb "cloud.google.com/go/discoveryengine/apiv1/discoveryenginepb"
"google.golang.org/api/option"
)

// search searches for a query in a search app given the Google Cloud Project ID,
// Location, and App ID.
func createDataStore(projectID, location, dataStoreID string) error {

ctx := context.Background()

// Create a client
endpoint := "discoveryengine.googleapis.com:443" // Default to global endpoint
if location != "global" {
endpoint = fmt.Sprintf("%s-%s", location, endpoint)
}
client, err := discoveryengine.NewDataStoreClient(ctx, option.WithEndpoint(endpoint))
if err != nil {
fmt.Println(fmt.Errorf("error creating Vertex AI Search client: %w", err))
}
defer client.Close()

// The full resource name of the collection.
// e.g. projects/project/locations/{location}/collections/default_collection
parent := fmt.Sprintf("projects/%s/locations/%s/collections/default_collection", projectID, location)

dataStore := &discoveryenginepb.DataStore{
DisplayName: "My Data Store",
// Options: GENERIC, MEDIA, HEALTHCARE_FHIR
IndustryVertical: discoveryenginepb.IndustryVertical_GENERIC,
// Options: SOLUTION_TYPE_RECOMMENDATION, SOLUTION_TYPE_SEARCH, SOLUTION_TYPE_CHAT, SOLUTION_TYPE_GENERATIVE_CHAT
SolutionTypes: []discoveryenginepb.SolutionType{discoveryenginepb.SolutionType_SOLUTION_TYPE_SEARCH},
// TODO(developer): Update content_config based on data store type.
// Options: NO_CONTENT, CONTENT_REQUIRED, PUBLIC_WEBSITE
ContentConfig: discoveryenginepb.DataStore_CONTENT_REQUIRED,
}

request := &discoveryenginepb.CreateDataStoreRequest{
Parent: parent,
DataStoreId: dataStoreID,
DataStore: dataStore,
}

// Make the request.
op, err := client.CreateDataStore(ctx, request)
if err != nil {
return fmt.Errorf("client.CreateDataStore: %w", err)
}

fmt.Printf("Waiting for operation to complete: %s\n", op.Name())
// After the operation is complete, get information from operation metadata.
_, err = op.Wait(ctx)
if err != nil {
return fmt.Errorf("op.Wait: %w", err)
}
return nil
}

// [END genappbuilder_create_data_store]
41 changes: 41 additions & 0 deletions discoveryengine/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module github.com/GoogleCloudPlatform/golang-samples/discoveryengine

go 1.21.1

require (
cloud.google.com/go/discoveryengine v1.14.0
google.golang.org/api v0.197.0
)

require (
cloud.google.com/go v0.115.1 // indirect
cloud.google.com/go/auth v0.9.3 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect
cloud.google.com/go/compute/metadata v0.5.0 // indirect
cloud.google.com/go/longrunning v0.6.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/time v0.6.0 // indirect
google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.66.1 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)
Loading
Loading