ייצוא של ערכי תכונות

ייצוא של ערכי מאפיינים לכל הישויות מסוג ישות יחיד לטבלה ב-BigQuery או לקטגוריה של Cloud Storage. אתם יכולים לבחור לקבל תמונת מצב או לייצא את ערכי המאפיינים באופן מלא. תמונת מצב מחזירה ערך אחד לכל תכונה, בהשוואה לייצוא מלא שיכול להחזיר כמה ערכים לכל תכונה. אי אפשר לבחור מזהי ישויות מסוימים או לכלול כמה סוגי ישויות כשמייצאים ערכי מאפיינים.

ייצוא של ערכי מאפיינים שימושי לצורך העברה לארכיון או לביצוע ניתוח אד-הוק של הנתונים. לדוגמה, אתם יכולים לאחסן תמונות מצב קבועות של מאגר הפיצ'רים כדי לשמור את המצב שלו בנקודות זמן שונות. אם אתם צריכים לקבל ערכי מאפיינים כדי ליצור מערך נתונים לאימון, השתמשו במקום זאת בשליפת נתונים ב-batch.

השוואה בין ייצוא של תמונת מצב לייצוא מלא

בשתי האפשרויות, ייצוא של תמונת מצב וייצוא מלא, אפשר לשלוח שאילתות על נתונים על ידי ציון חותמת זמן אחת (שעת ההתחלה או שעת הסיום) או שתי חותמות הזמן. בתמונות מצב, Vertex AI Feature Store (דור קודם) מחזיר את ערך המאפיין האחרון בטווח זמן נתון. בפלט, חותמת הזמן שמשויכת לכל ערך של מאפיין היא חותמת הזמן של תמונת המצב (ולא חותמת הזמן של ערך המאפיין).

בייצוא מלא, Vertex AI Feature Store (דור קודם) מחזיר את כל ערכי המאפיינים בטווח זמן נתון. בפלט, חותמת הזמן שמשויכת לכל ערך של מאפיין היא חותמת הזמן של המאפיין (חותמת הזמן שצוינה כשהערך של המאפיין הוטמע).

בטבלה הבאה מפורט מה Vertex AI Feature Store (דור קודם) מחזיר, בהתאם לאפשרות שבחרתם ולחותמות הזמן שסיפקתם.

אפשרות רק שעת ההתחלה (כולל) רק שעת סיום (כולל) שעת התחלה ושעת סיום (כולל)
תמונת מצב החל מהשעה הנוכחית (כשמתקבלת הבקשה), הפונקציה מחזירה את הערך האחרון, במבט לאחור עד שעת ההתחלה.
חותמת הזמן של תמונת המצב מוגדרת לשעה הנוכחית.
הפונקציה מחזירה את הערך האחרון, החל משעת הסיום, ומחפשת אחורה עד לערך הראשון של כל מאפיין.
חותמת הזמן של תמונת המצב מוגדרת לשעת הסיום שצוינה.
הפונקציה מחזירה את הערך האחרון בטווח התאריכים שצוין.
חותמת הזמן של תמונת המצב מוגדרת לשעת הסיום שצוינה.
ייצוא מלא הפונקציה מחזירה את כל הערכים משעת ההתחלה ועד לשעה הנוכחית (שבה נשלחה הבקשה). הפונקציה מחזירה את כל הערכים עד לזמן הסיום, החל מהערך הראשון של כל מאפיין. הפונקציה מחזירה את כל הערכים בטווח התאריכים שצוין.

ערכים ריקים

בתמונות מצב, אם ערך המאפיין האחרון הוא null בחותמת זמן נתונה, Vertex AI Feature Store (דור קודם) מחזיר את ערך המאפיין הקודם שאינו null. אם אין ערכים קודמים שאינם null, ‏ Vertex AI Feature Store (דור קודם) מחזיר null.

בייצוא מלא, אם ערך של מאפיין הוא null בחותמת זמן נתונה, Vertex AI Feature Store (דור קודם) מחזיר null לחותמת הזמן הזו.

דוגמאות

לדוגמה, נניח שיש לכם את הערכים הבאים במאגר פיצ'רים, שבהם הערכים של Feature_A ו-Feature_B חולקים את אותה חותמת זמן:

מזהה ישות חותמת הזמן של ערך המאפיין Feature_A Feature_B
123 T1 A_T1 B_T1
123 T2 A_T2 NULL
123 T3 A_T3 NULL
123 T4 A_T4 B_T4
123 T5 NULL B_T5

תמונת מצב

בתמונות מצב, Vertex AI Feature Store (דור קודם) מחזיר את הערכים הבאים על סמך ערכי חותמות הזמן שצוינו:

  • אם רק שעת ההתחלה מוגדרת ל-T3, תמונת המצב מחזירה את הערכים הבאים:
מזהה ישות חותמת הזמן של תמונת המצב Feature_A Feature_B
123 CURRENT_TIME A_T4 B_T5
  • אם רק שעת הסיום מוגדרת לערך T3, תמונת המצב מחזירה את הערכים הבאים:
מזהה ישות חותמת הזמן של תמונת המצב Feature_A Feature_B
123 T3 A_T3 B_T1
  • אם זמני ההתחלה והסיום מוגדרים ל-T2 ול-T3, תמונת המצב מחזירה את הערכים הבאים:
מזהה ישות חותמת הזמן של תמונת המצב Feature_A Feature_B
123 T3 A_T3 NULL

ייצוא מלא

בייצוא מלא, Vertex AI Feature Store (דור קודם) מחזיר את הערכים הבאים על סמך ערכי חותמות הזמן שצוינו:

  • אם רק שעת ההתחלה מוגדרת ל-T3, הייצוא המלא מחזיר את הערכים הבאים:
מזהה ישות חותמת הזמן של ערך המאפיין Feature_A Feature_B
123 T3 A_T3 NULL
123 T4 A_T4 B_T4
123 T5 NULL B_T5
  • אם רק שעת הסיום מוגדרת ל-T3, הייצוא המלא מחזיר את הערכים הבאים:
מזהה ישות חותמת הזמן של ערך המאפיין Feature_A Feature_B
123 T1 A_T1 B_T1
123 T2 A_T2 NULL
123 T3 A_T3 NULL
  • אם שעות ההתחלה והסיום מוגדרות ל-T2 ו-T4, הייצוא המלא מחזיר את הערכים הבאים:
מזהה ישות חותמת הזמן של ערך המאפיין Feature_A Feature_B
123 T2 A_T2 NULL
123 T3 A_T3 NULL
123 T4 A_T4 B_T4

ייצוא ערכי מאפיינים

כשמייצאים ערכי מאפיינים, בוחרים אילו מאפיינים לשלוח בשאילתה, ואם לייצא תמונת מצב או ייצוא מלא. בקטעים הבאים מוצגת דוגמה לכל אפשרות.

בשתי האפשרויות, יעד הפלט צריך להיות באותו אזור שבו נמצא מאגר הפיצ'רים המקורי. לדוגמה, אם מאגר הפיצ'רים נמצא ב-us-central1, גם קטגוריית היעד של Cloud Storage או הטבלה ב-BigQuery צריכות להיות ב-us-central1.

תמונת מצב

ייצוא של ערכי המאפיינים העדכניים ביותר בטווח תאריכים נתון.

ממשק המשתמש באינטרנט

להשתמש בשיטה אחרת. אי אפשר לייצא ערכי מאפיינים ממסוףGoogle Cloud .

REST

כדי לייצא ערכי מאפיינים, שולחים בקשת POST באמצעות ה-method‏ entityTypes.exportFeatureValues.

הדוגמה הבאה מפיקה פלט של טבלה ב-BigQuery, אבל אפשר גם להפיק פלט לקטגוריה של Cloud Storage. יכול להיות שלכל יעד פלט יהיו דרישות מוקדמות שצריך לעמוד בהן לפני ששולחים בקשה. לדוגמה, אם מציינים שם טבלה בשדה bigqueryDestination, צריך שתהיה קבוצת נתונים קיימת. הדרישות האלה מתועדות במאמרי העזרה של ה-API.

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • ‫LOCATION_ID: האזור שבו נמצא מאגר הפיצ'רים. לדוגמה, us-central1.
  • ‫PROJECT_ID: מזהה הפרויקט.
  • ‫FEATURESTORE_ID: המזהה של מאגר הפיצ'רים.
  • ‫ENTITY_TYPE_ID: המזהה של סוג הישות.
  • ‫START_TIME ו-END_TIME: (אופציונלי) אם מציינים רק את שעת ההתחלה, מוחזר הערך האחרון החל מהשעה הנוכחית (כשנשלחת הבקשה) ועד שעת ההתחלה. אם מציינים רק את שעת הסיום, הפונקציה מחזירה את הערך האחרון החל משעת הסיום (כולל) ומחפשת אחורה עד לערך הראשון. אם מציינים שעת התחלה ושעת סיום, הפונקציה מחזירה את הערך האחרון בטווח הזמן שצוין (כולל). אם לא מציינים אף אחד מהם, הפונקציה מחזירה את הערכים האחרונים של כל מאפיין, החל מהשעה הנוכחית ועד לערך הראשון.
  • ‫DATASET_NAME: השם של מערך הנתונים ב-BigQuery שאליו מייצאים.
  • ‫TABLE_NAME: השם של טבלת היעד ב-BigQuery.
  • ‫FEATURE_ID: מזהה של תכונה אחת או יותר. כדי לבחור את כל התכונות, מציינים * (כוכבית) אחת.

ה-method של ה-HTTP וכתובת ה-URL:

POST https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID:exportFeatureValues

גוף בקשת JSON:

{
  "snapshotExport": {
    "start_time": "START_TIME",
    "snapshot_time": "END_TIME"
  },
  "destination" : {
    "bigqueryDestination": {
      "outputUri": "bq://PROJECT_ID.DATASET_NAME.TABLE_NAME"
    }
  },
  "featureSelector": {
    "idMatcher": {
      "ids": ["FEATURE_ID", ...]
    }
  }
}

כדי לשלוח את הבקשה עליכם לבחור אחת מהאפשרויות הבאות:

curl

שומרים את גוף הבקשה בקובץ בשם request.json ומריצים את הפקודה הבאה:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID:exportFeatureValues"

PowerShell

שומרים את גוף הבקשה בקובץ בשם request.json ומריצים את הפקודה הבאה:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID:exportFeatureValues" | Select-Object -Expand Content

אתם אמורים לקבל תגובת JSON שדומה לזו:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.aiplatform.v1.ExportFeatureValuesOperationMetadata",
    "genericMetadata": {
      "createTime": "2021-12-03T22:55:25.974976Z",
      "updateTime": "2021-12-03T22:55:25.974976Z"
    }
  }
}

Java

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי Java הוראות ההגדרה במדריך למתחילים של Vertex AI באמצעות ספריות לקוח. למידע נוסף, קראו את מאמרי העזרה של Vertex AI Java API.

כדי לבצע אימות ב-Vertex AI, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.


import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.aiplatform.v1.BigQueryDestination;
import com.google.cloud.aiplatform.v1.EntityTypeName;
import com.google.cloud.aiplatform.v1.ExportFeatureValuesOperationMetadata;
import com.google.cloud.aiplatform.v1.ExportFeatureValuesRequest;
import com.google.cloud.aiplatform.v1.ExportFeatureValuesRequest.SnapshotExport;
import com.google.cloud.aiplatform.v1.ExportFeatureValuesResponse;
import com.google.cloud.aiplatform.v1.FeatureSelector;
import com.google.cloud.aiplatform.v1.FeatureValueDestination;
import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient;
import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings;
import com.google.cloud.aiplatform.v1.IdMatcher;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class ExportFeatureValuesSnapshotSample {

  public static void main(String[] args)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.
    String project = "YOUR_PROJECT_ID";
    String featurestoreId = "YOUR_FEATURESTORE_ID";
    String entityTypeId = "YOUR_ENTITY_TYPE_ID";
    String destinationTableUri = "YOUR_DESTINATION_TABLE_URI";
    List<String> featureSelectorIds = Arrays.asList("title", "genres", "average_rating");
    String location = "us-central1";
    String endpoint = "us-central1-aiplatform.googleapis.com:443";
    int timeout = 300;
    exportFeatureValuesSnapshotSample(
        project,
        featurestoreId,
        entityTypeId,
        destinationTableUri,
        featureSelectorIds,
        location,
        endpoint,
        timeout);
  }

  static void exportFeatureValuesSnapshotSample(
      String project,
      String featurestoreId,
      String entityTypeId,
      String destinationTableUri,
      List<String> featureSelectorIds,
      String location,
      String endpoint,
      int timeout)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    FeaturestoreServiceSettings featurestoreServiceSettings =
        FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build();

    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (FeaturestoreServiceClient featurestoreServiceClient =
        FeaturestoreServiceClient.create(featurestoreServiceSettings)) {

      FeatureSelector featureSelector =
          FeatureSelector.newBuilder()
              .setIdMatcher(IdMatcher.newBuilder().addAllIds(featureSelectorIds).build())
              .build();

      ExportFeatureValuesRequest exportFeatureValuesRequest =
          ExportFeatureValuesRequest.newBuilder()
              .setEntityType(
                  EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString())
              .setDestination(
                  FeatureValueDestination.newBuilder()
                      .setBigqueryDestination(
                          BigQueryDestination.newBuilder().setOutputUri(destinationTableUri)))
              .setFeatureSelector(featureSelector)
              .setSnapshotExport(SnapshotExport.newBuilder())
              .build();

      OperationFuture<ExportFeatureValuesResponse, ExportFeatureValuesOperationMetadata>
          exportFeatureValuesFuture =
              featurestoreServiceClient.exportFeatureValuesAsync(exportFeatureValuesRequest);
      System.out.format(
          "Operation name: %s%n", exportFeatureValuesFuture.getInitialFuture().get().getName());
      System.out.println("Waiting for operation to finish...");
      ExportFeatureValuesResponse exportFeatureValuesResponse =
          exportFeatureValuesFuture.get(timeout, TimeUnit.SECONDS);
      System.out.println("Snapshot Export Feature Values Response");
      System.out.println(exportFeatureValuesResponse);
      featurestoreServiceClient.close();
    }
  }
}

Node.js

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי Node.js הוראות ההגדרה במדריך למתחילים של Vertex AI באמצעות ספריות לקוח. למידע נוסף, קראו את מאמרי העזרה של Vertex AI Node.js API.

כדי לבצע אימות ב-Vertex AI, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

/**
 * TODO(developer): Uncomment these variables before running the sample.\
 * (Not necessary if passing values as arguments)
 */

// const project = 'YOUR_PROJECT_ID';
// const featurestoreId = 'YOUR_FEATURESTORE_ID';
// const entityTypeId = 'YOUR_ENTITY_TYPE_ID';
// const destinationTableUri = 'YOUR_BQ_DESTINATION_TABLE_URI';
// const timestamp = <STARTING_TIMESTAMP_OF_SNAPSHOT_IN_SECONDS>;
// const location = 'YOUR_PROJECT_LOCATION';
// const apiEndpoint = 'YOUR_API_ENDPOINT';
// const timeout = <TIMEOUT_IN_MILLI_SECONDS>;

// Imports the Google Cloud Featurestore Service Client library
const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1;

// Specifies the location of the api endpoint
const clientOptions = {
  apiEndpoint: apiEndpoint,
};

// Instantiates a client
const featurestoreServiceClient = new FeaturestoreServiceClient(
  clientOptions
);

async function exportFeatureValuesSnapshot() {
  // Configure the entityType resource
  const entityType = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}`;

  const destination = {
    bigqueryDestination: {
      // # Output to BigQuery table created earlier
      outputUri: destinationTableUri,
    },
  };

  const featureSelector = {
    idMatcher: {
      ids: ['age', 'gender', 'liked_genres'],
    },
  };

  const snapshotExport = {
    startTime: {
      seconds: Number(timestamp),
    },
  };

  const request = {
    entityType: entityType,
    destination: destination,
    featureSelector: featureSelector,
    snapshotExport: snapshotExport,
  };

  // Export Feature Values Request
  const [operation] = await featurestoreServiceClient.exportFeatureValues(
    request,
    {timeout: Number(timeout)}
  );
  const [response] = await operation.promise();

  console.log('Export feature values snapshot response');
  console.log('Raw response:');
  console.log(JSON.stringify(response, null, 2));
}
exportFeatureValuesSnapshot();

שפות נוספות

במאמר שימוש ב-Vertex AI SDK ל-Python מוסבר איך להתקין את Vertex AI SDK ל-Python ולהשתמש בו. מידע נוסף מופיע במאמרי העזרה של Vertex AI SDK ל-Python API.

ייצוא מלא

ייצוא של כל ערכי המאפיינים בטווח תאריכים נתון.

ממשק המשתמש באינטרנט

להשתמש בשיטה אחרת. אי אפשר לייצא ערכי מאפיינים ממסוףGoogle Cloud .

REST

כדי לייצא ערכי מאפיינים, שולחים בקשת POST באמצעות ה-method‏ entityTypes.exportFeatureValues.

הדוגמה הבאה מפיקה פלט של טבלה ב-BigQuery, אבל אפשר גם להפיק פלט לקטגוריה של Cloud Storage. יכול להיות שלכל יעד פלט יהיו דרישות מוקדמות שצריך לעמוד בהן לפני ששולחים בקשה. לדוגמה, אם מציינים שם טבלה בשדה bigqueryDestination, צריך להיות לכם מערך נתונים קיים. הדרישות האלה מתועדות במאמרי העזרה של ה-API.

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • ‫LOCATION_ID: האזור שבו נמצא מאגר הפיצ'רים. לדוגמה, us-central1.
  • PROJECT_ID: .
  • ‫FEATURESTORE_ID: המזהה של מאגר הפיצ'רים.
  • ‫ENTITY_TYPE_ID: המזהה של סוג הישות.
  • ‫START_TIME ו-END_TIME: (אופציונלי) אם מציינים רק את שעת ההתחלה, המערכת מחזירה את כל הערכים בין השעה הנוכחית (כשנשלחת הבקשה) לבין שעת ההתחלה (כולל). אם מציינים רק את שעת הסיום, הפונקציה מחזירה את כל הערכים בין שעת הסיום (כולל) לבין חותמת הזמן של הערך הראשון (לכל מאפיין). אם מציינים שעת התחלה ושעת סיום, הפונקציה מחזירה את כל הערכים בטווח הזמן שצוין (כולל). אם לא מציינים אף אחד מהם, הפונקציה מחזירה את כל הערכים בין השעה הנוכחית לבין חותמת הזמן של הערך הראשון (לכל מאפיין).
  • ‫DATASET_NAME: השם של מערך הנתונים ב-BigQuery שאליו מייצאים.
  • ‫TABLE_NAME: השם של טבלת היעד ב-BigQuery.
  • ‫FEATURE_ID: מזהה של תכונה אחת או יותר. כדי לבחור את כל התכונות, מציינים * (כוכבית) אחת.

ה-method של ה-HTTP וכתובת ה-URL:

POST https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID:exportFeatureValues

גוף בקשת JSON:

{
  "fullExport": {
    "start_time": "START_TIME",
    "end_time": "END_TIME"
  },
  "destination" : {
    "bigqueryDestination": {
      "outputUri": "bq://PROJECT.DATASET_NAME.TABLE_NAME"
    }
  },
  "featureSelector": {
    "idMatcher": {
      "ids": ["FEATURE_ID", ...]
    }
  }
}

כדי לשלוח את הבקשה עליכם לבחור אחת מהאפשרויות הבאות:

curl

שומרים את גוף הבקשה בקובץ בשם request.json ומריצים את הפקודה הבאה:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID:exportFeatureValues"

PowerShell

שומרים את גוף הבקשה בקובץ בשם request.json ומריצים את הפקודה הבאה:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID:exportFeatureValues" | Select-Object -Expand Content

אתם אמורים לקבל תגובת JSON שדומה לזו:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.aiplatform.v1.ExportFeatureValuesOperationMetadata",
    "genericMetadata": {
      "createTime": "2021-12-03T22:55:25.974976Z",
      "updateTime": "2021-12-03T22:55:25.974976Z"
    }
  }
}

Java

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי Java הוראות ההגדרה במדריך למתחילים של Vertex AI באמצעות ספריות לקוח. למידע נוסף, קראו את מאמרי העזרה של Vertex AI Java API.

כדי לבצע אימות ב-Vertex AI, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.


import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.aiplatform.v1.BigQueryDestination;
import com.google.cloud.aiplatform.v1.EntityTypeName;
import com.google.cloud.aiplatform.v1.ExportFeatureValuesOperationMetadata;
import com.google.cloud.aiplatform.v1.ExportFeatureValuesRequest;
import com.google.cloud.aiplatform.v1.ExportFeatureValuesRequest.FullExport;
import com.google.cloud.aiplatform.v1.ExportFeatureValuesResponse;
import com.google.cloud.aiplatform.v1.FeatureSelector;
import com.google.cloud.aiplatform.v1.FeatureValueDestination;
import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient;
import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings;
import com.google.cloud.aiplatform.v1.IdMatcher;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class ExportFeatureValuesSample {

  public static void main(String[] args)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.
    String project = "YOUR_PROJECT_ID";
    String featurestoreId = "YOUR_FEATURESTORE_ID";
    String entityTypeId = "YOUR_ENTITY_TYPE_ID";
    String destinationTableUri = "YOUR_DESTINATION_TABLE_URI";
    List<String> featureSelectorIds = Arrays.asList("title", "genres", "average_rating");
    String location = "us-central1";
    String endpoint = "us-central1-aiplatform.googleapis.com:443";
    int timeout = 300;
    exportFeatureValuesSample(
        project,
        featurestoreId,
        entityTypeId,
        destinationTableUri,
        featureSelectorIds,
        location,
        endpoint,
        timeout);
  }

  static void exportFeatureValuesSample(
      String project,
      String featurestoreId,
      String entityTypeId,
      String destinationTableUri,
      List<String> featureSelectorIds,
      String location,
      String endpoint,
      int timeout)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    FeaturestoreServiceSettings featurestoreServiceSettings =
        FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build();

    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (FeaturestoreServiceClient featurestoreServiceClient =
        FeaturestoreServiceClient.create(featurestoreServiceSettings)) {

      FeatureSelector featureSelector =
          FeatureSelector.newBuilder()
              .setIdMatcher(IdMatcher.newBuilder().addAllIds(featureSelectorIds).build())
              .build();

      ExportFeatureValuesRequest exportFeatureValuesRequest =
          ExportFeatureValuesRequest.newBuilder()
              .setEntityType(
                  EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString())
              .setDestination(
                  FeatureValueDestination.newBuilder()
                      .setBigqueryDestination(
                          BigQueryDestination.newBuilder().setOutputUri(destinationTableUri)))
              .setFeatureSelector(featureSelector)
              .setFullExport(FullExport.newBuilder())
              .build();

      OperationFuture<ExportFeatureValuesResponse, ExportFeatureValuesOperationMetadata>
          exportFeatureValuesFuture =
              featurestoreServiceClient.exportFeatureValuesAsync(exportFeatureValuesRequest);
      System.out.format(
          "Operation name: %s%n", exportFeatureValuesFuture.getInitialFuture().get().getName());
      System.out.println("Waiting for operation to finish...");
      ExportFeatureValuesResponse exportFeatureValuesResponse =
          exportFeatureValuesFuture.get(timeout, TimeUnit.SECONDS);
      System.out.println("Export Feature Values Response");
      System.out.println(exportFeatureValuesResponse);
      featurestoreServiceClient.close();
    }
  }
}

Node.js

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי Node.js הוראות ההגדרה במדריך למתחילים של Vertex AI באמצעות ספריות לקוח. למידע נוסף, קראו את מאמרי העזרה של Vertex AI Node.js API.

כדי לבצע אימות ב-Vertex AI, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

/**
 * TODO(developer): Uncomment these variables before running the sample.\
 * (Not necessary if passing values as arguments)
 */

// const project = 'YOUR_PROJECT_ID';
// const featurestoreId = 'YOUR_FEATURESTORE_ID';
// const entityTypeId = 'YOUR_ENTITY_TYPE_ID';
// const destinationTableUri = 'YOUR_BQ_DESTINATION_TABLE_URI';
// const location = 'YOUR_PROJECT_LOCATION';
// const apiEndpoint = 'YOUR_API_ENDPOINT';
// const timeout = <TIMEOUT_IN_MILLI_SECONDS>;

// Imports the Google Cloud Featurestore Service Client library
const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1;

// Specifies the location of the api endpoint
const clientOptions = {
  apiEndpoint: apiEndpoint,
};

// Instantiates a client
const featurestoreServiceClient = new FeaturestoreServiceClient(
  clientOptions
);

async function exportFeatureValues() {
  // Configure the entityType resource
  const entityType = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}`;

  const destination = {
    bigqueryDestination: {
      // # Output to BigQuery table created earlier
      outputUri: destinationTableUri,
    },
  };

  const featureSelector = {
    idMatcher: {
      ids: ['age', 'gender', 'liked_genres'],
    },
  };

  const request = {
    entityType: entityType,
    destination: destination,
    featureSelector: featureSelector,
    fullExport: {},
  };

  // Export Feature Values Request
  const [operation] = await featurestoreServiceClient.exportFeatureValues(
    request,
    {timeout: Number(timeout)}
  );
  const [response] = await operation.promise();

  console.log('Export feature values response');
  console.log('Raw response:');
  console.log(JSON.stringify(response, null, 2));
}
exportFeatureValues();

שפות נוספות

במאמר שימוש ב-Vertex AI SDK ל-Python מוסבר איך להתקין את Vertex AI SDK ל-Python ולהשתמש בו. מידע נוסף מופיע במאמרי העזרה של Vertex AI SDK ל-Python API.

המאמרים הבאים