Skip to content

Commit 92afe19

Browse files
fix: specify outputDimensionality. (#3732)
1 parent d28b3fd commit 92afe19

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

ai-platform/snippets/predict-text-embeddings-preview.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async function main(
2222
model = 'text-embedding-preview-0409',
2323
texts = 'banana bread?;banana muffins?',
2424
task = 'QUESTION_ANSWERING',
25-
outputDimensionality = 256,
25+
dimensionality = 256,
2626
apiEndpoint = 'us-central1-aiplatform.googleapis.com'
2727
) {
2828
const aiplatform = require('@google-cloud/aiplatform');
@@ -31,7 +31,9 @@ async function main(
3131
const clientOptions = {apiEndpoint: apiEndpoint};
3232
const location = 'us-central1';
3333
const endpoint = `projects/${project}/locations/${location}/publishers/google/models/${model}`;
34-
const parameters = helpers.toValue(outputDimensionality);
34+
const parameters = helpers.toValue({
35+
outputDimensionality: parseInt(dimensionality),
36+
});
3537

3638
async function callPredict() {
3739
const instances = texts

ai-platform/snippets/predict-text-embeddings.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async function main(
2222
model = 'text-embedding-004',
2323
texts = 'banana bread?;banana muffins?',
2424
task = 'QUESTION_ANSWERING',
25-
outputDimensionality = 0,
25+
dimensionality = 0,
2626
apiEndpoint = 'us-central1-aiplatform.googleapis.com'
2727
) {
2828
const aiplatform = require('@google-cloud/aiplatform');
@@ -31,15 +31,14 @@ async function main(
3131
const clientOptions = {apiEndpoint: apiEndpoint};
3232
const location = 'us-central1';
3333
const endpoint = `projects/${project}/locations/${location}/publishers/google/models/${model}`;
34-
const parameters =
35-
outputDimensionality > 0
36-
? helpers.toValue(outputDimensionality)
37-
: helpers.toValue(256);
3834

3935
async function callPredict() {
4036
const instances = texts
4137
.split(';')
4238
.map(e => helpers.toValue({content: e, task_type: task}));
39+
const parameters = helpers.toValue(
40+
dimensionality > 0 ? {outputDimensionality: parseInt(dimensionality)} : {}
41+
);
4342
const request = {endpoint, instances, parameters};
4443
const client = new PredictionServiceClient(clientOptions);
4544
const [response] = await client.predict(request);

0 commit comments

Comments
 (0)