Skip to content

Commit 8c13e2c

Browse files
committed
docs: document how to programatically configure vertex embeddings to use a service account
1 parent b3e7efd commit 8c13e2c

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/vertexai-embeddings-text.adoc

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ Next, create a `VertexAiTextEmbeddingModel` and use it for text generations:
144144

145145
[source,java]
146146
----
147-
VertexAiEmbeddigConnectionDetails connectionDetails =
148-
VertexAiEmbeddigConnectionDetails.builder()
147+
VertexAiEmbeddingConnectionDetails connectionDetails =
148+
VertexAiEmbeddingConnectionDetails.builder()
149149
.withProjectId(System.getenv(<VERTEX_AI_GEMINI_PROJECT_ID>))
150150
.withLocation(System.getenv(<VERTEX_AI_GEMINI_LOCATION>))
151151
.build();
@@ -160,3 +160,24 @@ EmbeddingResponse embeddingResponse = this.embeddingModel
160160
.embedForResponse(List.of("Hello World", "World is big and salvation is near"));
161161
----
162162

163+
=== Load credentials from a Google Service Account
164+
165+
To programmatically load the GoogleCredentials from a Service Account json file, you can use the following:
166+
167+
[source,java]
168+
----
169+
GoogleCredentials credentials = GoogleCredentials.fromStream(<INPUT_STREAM_TO_CREDENTIALS_JSON>)
170+
.createScoped("https://www.googleapis.com/auth/cloud-platform");
171+
credentials.refreshIfExpired();
172+
173+
VertexAiEmbeddingConnectionDetails connectionDetails =
174+
VertexAiEmbeddingConnectionDetails.builder()
175+
.withProjectId(System.getenv(<VERTEX_AI_GEMINI_PROJECT_ID>))
176+
.withLocation(System.getenv(<VERTEX_AI_GEMINI_LOCATION>))
177+
.withApiEndpoint(endpoint)
178+
.withPredictionServiceSettings(
179+
PredictionServiceSettings.newBuilder()
180+
.setEndpoint(endpoint)
181+
.setCredentialsProvider(FixedCredentialsProvider.create(credentials))
182+
.build());
183+
----

0 commit comments

Comments
 (0)