Skip to content

Commit fb5c246

Browse files
authored
Merge branch 'main' into renovate/aws-sdk-go-monorepo
2 parents e6c4ad0 + 215aa7c commit fb5c246

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3491
-1141
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
/secretmanager/ @GoogleCloudPlatform/go-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers @GoogleCloudPlatform/cloud-secrets-team
4848
/securitycenter/ @GoogleCloudPlatform/go-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers @GoogleCloudPlatform/gcp-security-command-center
4949
/translate/ @GoogleCloudPlatform/go-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers @GoogleCloudPlatform/cloud-ml-translate-dev
50+
/connectgateway/ @GoogleCloudPlatform/go-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers @GoogleCloudPlatform/connectgateway
5051

5152
# Does not have owner
5253
/cdn/ @GoogleCloudPlatform/go-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers

.github/blunderbuss.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,8 @@ assign_prs_by:
103103
- labels:
104104
- "api: securitycenter"
105105
to:
106-
- GoogleCloudPlatform/gcp-security-command-center
106+
- GoogleCloudPlatform/gcp-security-command-center
107+
- labels:
108+
- "api: connectgateway"
109+
to:
110+
- GoogleCloudPlatform/connectgateway

aiplatform/snippets/embeddings.go

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ import (
2828
"google.golang.org/protobuf/types/known/structpb"
2929
)
3030

31-
// embedTexts shows how embeddings are set for text-embedding-005 model
31+
// embedTexts shows how embeddings are set for gemini-embedding-001 model
3232
func embedTexts(w io.Writer, project, location string) error {
3333
// location := "us-central1"
3434
ctx := context.Background()
3535

3636
apiEndpoint := fmt.Sprintf("%s-aiplatform.googleapis.com:443", location)
37-
dimensionality := 5
38-
model := "text-embedding-005"
37+
dimensionality := 3072
38+
model := "gemini-embedding-001"
3939
texts := []string{"banana muffins? ", "banana bread? banana muffins?"}
4040

4141
client, err := aiplatform.NewPredictionClient(ctx, option.WithEndpoint(apiEndpoint))
@@ -45,41 +45,54 @@ func embedTexts(w io.Writer, project, location string) error {
4545
defer client.Close()
4646

4747
endpoint := fmt.Sprintf("projects/%s/locations/%s/publishers/google/models/%s", project, location, model)
48-
instances := make([]*structpb.Value, len(texts))
49-
for i, text := range texts {
50-
instances[i] = structpb.NewStructValue(&structpb.Struct{
48+
allEmbeddings := make([][]float32, 0, len(texts))
49+
// gemini-embedding-001 takes 1 input at a time
50+
for _, text := range texts {
51+
instances := make([]*structpb.Value, 1)
52+
instances[0] = structpb.NewStructValue(&structpb.Struct{
5153
Fields: map[string]*structpb.Value{
5254
"content": structpb.NewStringValue(text),
5355
"task_type": structpb.NewStringValue("QUESTION_ANSWERING"),
5456
},
5557
})
56-
}
5758

58-
params := structpb.NewStructValue(&structpb.Struct{
59-
Fields: map[string]*structpb.Value{
60-
"outputDimensionality": structpb.NewNumberValue(float64(dimensionality)),
61-
},
62-
})
59+
params := structpb.NewStructValue(&structpb.Struct{
60+
Fields: map[string]*structpb.Value{
61+
"outputDimensionality": structpb.NewNumberValue(float64(dimensionality)),
62+
},
63+
})
6364

64-
req := &aiplatformpb.PredictRequest{
65-
Endpoint: endpoint,
66-
Instances: instances,
67-
Parameters: params,
68-
}
69-
resp, err := client.Predict(ctx, req)
70-
if err != nil {
71-
return err
72-
}
73-
embeddings := make([][]float32, len(resp.Predictions))
74-
for i, prediction := range resp.Predictions {
75-
values := prediction.GetStructValue().Fields["embeddings"].GetStructValue().Fields["values"].GetListValue().Values
76-
embeddings[i] = make([]float32, len(values))
77-
for j, value := range values {
78-
embeddings[i][j] = float32(value.GetNumberValue())
65+
req := &aiplatformpb.PredictRequest{
66+
Endpoint: endpoint,
67+
Instances: instances,
68+
Parameters: params,
7969
}
70+
resp, err := client.Predict(ctx, req)
71+
if err != nil {
72+
return err
73+
}
74+
75+
// Process the prediction for the single text
76+
// The response will contain one prediction because we sent one instance.
77+
if len(resp.Predictions) == 0 {
78+
return fmt.Errorf("no predictions returned for text \"%s\"", text)
79+
}
80+
81+
prediction := resp.Predictions[0]
82+
embeddingValues := prediction.GetStructValue().Fields["embeddings"].GetStructValue().Fields["values"].GetListValue().Values
83+
84+
currentEmbedding := make([]float32, len(embeddingValues))
85+
for j, value := range embeddingValues {
86+
currentEmbedding[j] = float32(value.GetNumberValue())
87+
}
88+
allEmbeddings = append(allEmbeddings, currentEmbedding)
8089
}
8190

82-
fmt.Fprintf(w, "Dimensionality: %d. Embeddings length: %d", len(embeddings[0]), len(embeddings))
91+
if len(allEmbeddings) > 0 {
92+
fmt.Fprintf(w, "Dimensionality: %d. Embeddings length: %d", len(allEmbeddings[0]), len(allEmbeddings))
93+
} else {
94+
fmt.Fprintln(w, "No texts were processed.")
95+
}
8396
return nil
8497
}
8598

aiplatform/snippets/embeddings_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
func TestGenerateEmbeddings(t *testing.T) {
2626
tc := testutil.SystemTest(t)
2727
texts := []string{"banana muffins? ", "banana bread? banana muffins?"}
28-
dimensionality := 5
28+
dimensionality := 3072
2929
location := "us-central1"
3030
var buf bytes.Buffer
3131

badfiles_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ var allowList = []string{
130130
// document ai sample pdfs
131131
"documentai/**/*.pdf",
132132

133+
// Model Armor sample pdfs
134+
"modelarmor/test_sample.pdf",
135+
133136
// Speech-to-Text audio/video files
134137
"speech/resources/commercial_mono.wav",
135138

bigquery/go.mod

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,77 +3,80 @@ module github.com/GoogleCloudPlatform/golang-samples/bigquery
33
go 1.23.0
44

55
require (
6-
cloud.google.com/go v0.118.0
7-
cloud.google.com/go/bigquery v1.65.0
8-
cloud.google.com/go/iam v1.3.1
9-
cloud.google.com/go/storage v1.50.0
6+
cloud.google.com/go v0.121.0
7+
cloud.google.com/go/bigquery v1.69.0
8+
cloud.google.com/go/iam v1.5.2
9+
cloud.google.com/go/storage v1.53.0
1010
github.com/GoogleCloudPlatform/golang-samples v0.0.0-20240724083556-7f760db013b7
1111
github.com/apache/arrow/go/v10 v10.0.1
1212
github.com/gofrs/uuid v4.4.0+incompatible
1313
github.com/google/uuid v1.6.0
1414
github.com/googleapis/gax-go/v2 v2.14.1
1515
github.com/linkedin/goavro/v2 v2.13.0
16-
google.golang.org/api v0.217.0
17-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f
18-
google.golang.org/grpc v1.69.4
19-
google.golang.org/protobuf v1.36.3
16+
google.golang.org/api v0.232.0
17+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250505200425-f936aa4a68b2
18+
google.golang.org/grpc v1.72.0
19+
google.golang.org/protobuf v1.36.6
2020
)
2121

2222
require (
23-
cel.dev/expr v0.19.1 // indirect
24-
cloud.google.com/go/auth v0.14.0 // indirect
25-
cloud.google.com/go/auth/oauth2adapt v0.2.7 // indirect
23+
cel.dev/expr v0.20.0 // indirect
24+
cloud.google.com/go/auth v0.16.1 // indirect
25+
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
2626
cloud.google.com/go/compute/metadata v0.6.0 // indirect
27-
cloud.google.com/go/longrunning v0.6.4 // indirect
28-
cloud.google.com/go/monitoring v1.23.0 // indirect
29-
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.25.0 // indirect
30-
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.49.0 // indirect
31-
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.49.0 // indirect
27+
cloud.google.com/go/longrunning v0.6.7 // indirect
28+
cloud.google.com/go/monitoring v1.24.0 // indirect
29+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.27.0 // indirect
30+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.51.0 // indirect
31+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.51.0 // indirect
3232
github.com/andybalholm/brotli v1.0.5 // indirect
3333
github.com/apache/arrow/go/v15 v15.0.2 // indirect
3434
github.com/apache/thrift v0.17.0 // indirect
3535
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3636
github.com/cncf/xds/go v0.0.0-20250121191232-2f005788dc42 // indirect
37-
github.com/envoyproxy/go-control-plane/envoy v1.32.3 // indirect
38-
github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect
37+
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
38+
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
3939
github.com/felixge/httpsnoop v1.0.4 // indirect
40+
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
4041
github.com/go-logr/logr v1.4.2 // indirect
4142
github.com/go-logr/stdr v1.2.2 // indirect
4243
github.com/goccy/go-json v0.10.3 // indirect
4344
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
4445
github.com/golang/snappy v0.0.4 // indirect
4546
github.com/google/flatbuffers v23.5.26+incompatible // indirect
4647
github.com/google/s2a-go v0.1.9 // indirect
47-
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
48+
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
4849
github.com/klauspost/asmfmt v1.3.2 // indirect
4950
github.com/klauspost/compress v1.17.11 // indirect
5051
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
5152
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
5253
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
5354
github.com/pierrec/lz4/v4 v4.1.18 // indirect
5455
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
56+
github.com/spiffe/go-spiffe/v2 v2.5.0 // indirect
57+
github.com/zeebo/errs v1.4.0 // indirect
5558
github.com/zeebo/xxh3 v1.0.2 // indirect
5659
go.opencensus.io v0.24.0 // indirect
5760
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
58-
go.opentelemetry.io/contrib/detectors/gcp v1.34.0 // indirect
59-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0 // indirect
60-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 // indirect
61-
go.opentelemetry.io/otel v1.34.0 // indirect
62-
go.opentelemetry.io/otel/metric v1.34.0 // indirect
63-
go.opentelemetry.io/otel/sdk v1.34.0 // indirect
64-
go.opentelemetry.io/otel/sdk/metric v1.34.0 // indirect
65-
go.opentelemetry.io/otel/trace v1.34.0 // indirect
66-
golang.org/x/crypto v0.32.0 // indirect
67-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
68-
golang.org/x/mod v0.20.0 // indirect
69-
golang.org/x/net v0.34.0 // indirect
70-
golang.org/x/oauth2 v0.25.0 // indirect
71-
golang.org/x/sync v0.10.0 // indirect
72-
golang.org/x/sys v0.29.0 // indirect
73-
golang.org/x/text v0.21.0 // indirect
74-
golang.org/x/time v0.9.0 // indirect
75-
golang.org/x/tools v0.24.0 // indirect
61+
go.opentelemetry.io/contrib/detectors/gcp v1.35.0 // indirect
62+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0 // indirect
63+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect
64+
go.opentelemetry.io/otel v1.35.0 // indirect
65+
go.opentelemetry.io/otel/metric v1.35.0 // indirect
66+
go.opentelemetry.io/otel/sdk v1.35.0 // indirect
67+
go.opentelemetry.io/otel/sdk/metric v1.35.0 // indirect
68+
go.opentelemetry.io/otel/trace v1.35.0 // indirect
69+
golang.org/x/crypto v0.37.0 // indirect
70+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
71+
golang.org/x/mod v0.23.0 // indirect
72+
golang.org/x/net v0.39.0 // indirect
73+
golang.org/x/oauth2 v0.30.0 // indirect
74+
golang.org/x/sync v0.14.0 // indirect
75+
golang.org/x/sys v0.32.0 // indirect
76+
golang.org/x/text v0.24.0 // indirect
77+
golang.org/x/time v0.11.0 // indirect
78+
golang.org/x/tools v0.30.0 // indirect
7679
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
77-
google.golang.org/genproto v0.0.0-20250115164207-1a7da9e5054f // indirect
78-
google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f // indirect
80+
google.golang.org/genproto v0.0.0-20250303144028-a0af3efb3deb // indirect
81+
google.golang.org/genproto/googleapis/api v0.0.0-20250505200425-f936aa4a68b2 // indirect
7982
)

0 commit comments

Comments
 (0)