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

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

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

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

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

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

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

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

ערכי Null

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

בייצוא מלא, אם ערך של תכונה הוא null בחותמת זמן מסוימת,‏ Vertex AI Feature Store (Legacy) מחזיר 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 (Legacy) מחזיר את הערכים הבאים על סמך ערכי חותמת הזמן שצוינו:

  • אם רק שעת ההתחלה מוגדרת כ-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 (Legacy) מחזיר את הערכים הבאים על סמך ערכי חותמת הזמן שצוינו:

  • אם רק שעת ההתחלה מוגדרת ל-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 באמצעות השיטה 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 quickstart using client libraries. מידע נוסף מופיע במאמרי העזרה של 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 quickstart using client libraries. מידע נוסף מופיע במאמרי העזרה של 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 באמצעות השיטה 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 quickstart using client libraries. מידע נוסף מופיע במאמרי העזרה של 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 quickstart using client libraries. מידע נוסף מופיע במאמרי העזרה של 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.

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