יצירה של מאגר נתוני חיפוש

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

כדי לסנכרן נתונים ממקור נתונים של צד שלישי, אפשר לעיין במאמר בנושא קישור של מקור נתונים של צד שלישי.

מידע לפתרון בעיות מופיע במאמר פתרון בעיות בהעברת נתונים.

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

יצירת מאגר נתונים באמצעות תוכן האתר

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

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

לפני שמתחילים

אם אתם משתמשים בקובץ robots.txt באתר, אתם צריכים לעדכן אותו. מידע נוסף זמין במאמר בנושא הכנת קובץ robots.txt של האתר.

התהליך

המסוף

כדי להשתמש במסוף Google Cloud כדי ליצור מאגר נתונים ולאנדקס אתרים, פועלים לפי השלבים הבאים:

  1. נכנסים לדף AI Applications במסוף Google Cloud .

    אפליקציות AI

  2. בתפריט הניווט, לוחצים על מאגרי נתונים.

  3. לוחצים על יצירת מאגר נתונים.

  4. בדף מקור, בוחרים באפשרות תוכן אתר.

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

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

  6. בשדה Sites to include (אתרים לכלול), מזינים את תבניות כתובות ה-URL שתואמות לאתרים שרוצים לכלול במאגר הנתונים. צריך לכלול תבנית URL אחת בכל שורה, בלי פסיקים להפרדה. לדוגמה, example.com/docs/*

  7. אופציונלי: בשדה Sites to exclude (אתרים להחרגה), מזינים תבניות של כתובות URL שרוצים להחריג ממאגר הנתונים.

    לאתרים מוחרגים יש עדיפות על פני אתרים כלולים. לכן, אם תכללו את example.com/docs/* אבל תחריגו את example.com, לא יתבצע אינדוקס של אתרים. מידע נוסף זמין במאמר בנושא נתונים של אתר.

  8. לוחצים על Continue.

  9. בוחרים מיקום למאגר הנתונים.

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

  11. לוחצים על יצירה. חיפוש מבוסס סוכנים יוצר את מאגר הנתונים ומציג את מאגרי הנתונים בדף מאגרי נתונים.

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

    • אם הפעלתם את האפשרות יצירת אינדקס מתקדם של אתרים, תוצג אזהרה שתבקש מכם לאמת את הדומיינים במאגר הנתונים.
    • אם יש לכם חוסר במכסה (מספר הדפים באתרים שציינתם חורג מהמכסה של 'מספר המסמכים לכל פרויקט' בפרויקט), תופיע אזהרה נוספת שתבקש מכם לשדרג את המכסה.
  13. כדי לאמת את הדומיינים של דפוסי כתובות ה-URL במאגר הנתונים, פועלים לפי ההוראות בדף אימות דומיינים של אתרים.

  14. כדי לשדרג את המכסה:

    1. לוחצים על שדרוג נפח האחסון. מופיע הדף IAM and Admin (ניהול הרשאות גישה וניהול) במסוף Google Cloud .
    2. פועלים לפי ההוראות שבקטע איך שולחים בקשה לשינוי המכסות במסמכי התיעוד של Google Cloud . המכסה שצריך להגדיל היא Number of documents בשירות Discovery Engine API.
    3. אחרי ששולחים את הבקשה להגדלת מכסת הנפח, חוזרים לדף יישומים מבוססי-AI ובתפריט הניווט לוחצים על מאגרי נתונים.
    4. בעמודה שם, לוחצים על השם של מאגר הנתונים. בעמודה סטטוס מצוין שהאתרים שחרגו מהמכסה נמצאים בתהליך של יצירת אינדקס. כאשר בעמודה סטטוס של כתובת URL מופיע הערך נוספה לאינדקס, התכונות של הוספה מתקדמת של אתרים לאינדקס זמינות לכתובת ה-URL או לתבנית כתובת ה-URL.

    מידע נוסף מופיע בקטע מכסת אינדוקס לדפי אינטרנט בדף 'מכסות ומגבלות'.

Python

מידע נוסף מופיע בתיעוד העזר של ה-API של חיפוש מבוסס סוכנים Python.

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

יצירת מאגר נתונים


from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"
# location = "YOUR_LOCATION" # Values: "global"
# data_store_id = "YOUR_DATA_STORE_ID"


def create_data_store_sample(
    project_id: str,
    location: str,
    data_store_id: str,
) -> str:
    #  For more information, refer to:
    # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
    client_options = (
        ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
        if location != "global"
        else None
    )

    # Create a client
    client = discoveryengine.DataStoreServiceClient(client_options=client_options)

    # The full resource name of the collection
    # e.g. projects/{project}/locations/{location}/collections/default_collection
    parent = client.collection_path(
        project=project_id,
        location=location,
        collection="default_collection",
    )

    data_store = discoveryengine.DataStore(
        display_name="My Data Store",
        # Options: GENERIC, MEDIA, HEALTHCARE_FHIR
        industry_vertical=discoveryengine.IndustryVertical.GENERIC,
        # Options: SOLUTION_TYPE_RECOMMENDATION, SOLUTION_TYPE_SEARCH, SOLUTION_TYPE_CHAT, SOLUTION_TYPE_GENERATIVE_CHAT
        solution_types=[discoveryengine.SolutionType.SOLUTION_TYPE_SEARCH],
        # TODO(developer): Update content_config based on data store type.
        # Options: NO_CONTENT, CONTENT_REQUIRED, PUBLIC_WEBSITE
        content_config=discoveryengine.DataStore.ContentConfig.CONTENT_REQUIRED,
    )

    request = discoveryengine.CreateDataStoreRequest(
        parent=parent,
        data_store_id=data_store_id,
        data_store=data_store,
        # Optional: For Advanced Site Search Only
        # create_advanced_site_search=True,
    )

    # Make the request
    operation = client.create_data_store(request=request)

    print(f"Waiting for operation to complete: {operation.operation.name}")
    response = operation.result()

    # After the operation is complete,
    # get information from operation metadata
    metadata = discoveryengine.CreateDataStoreMetadata(operation.metadata)

    # Handle the response
    print(response)
    print(metadata)

    return operation.operation.name

ייבוא אתרים

#     from google.api_core.client_options import ClientOptions
#
#     from google.cloud import discoveryengine_v1 as discoveryengine
#
#     # TODO(developer): Uncomment these variables before running the sample.
#     # project_id = "YOUR_PROJECT_ID"
#     # location = "YOUR_LOCATION" # Values: "global"
#     # data_store_id = "YOUR_DATA_STORE_ID"
#     # NOTE: Do not include http or https protocol in the URI pattern
#     # uri_pattern = "cloud.google.com/generative-ai-app-builder/docs/*"
#
#     #  For more information, refer to:
#     # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
#     client_options = (
#         ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
#         if location != "global"
#         else None
#     )
#
#     # Create a client
#     client = discoveryengine.SiteSearchEngineServiceClient(
#         client_options=client_options
#     )
#
#     # The full resource name of the data store
#     # e.g. projects/{project}/locations/{location}/dataStores/{data_store_id}
#     site_search_engine = client.site_search_engine_path(
#         project=project_id, location=location, data_store=data_store_id
#     )
#
#     # Target Site to index
#     target_site = discoveryengine.TargetSite(
#         provided_uri_pattern=uri_pattern,
#         # Options: INCLUDE, EXCLUDE
#         type_=discoveryengine.TargetSite.Type.INCLUDE,
#         exact_match=False,
#     )
#
#     # Make the request
#     operation = client.create_target_site(
#         parent=site_search_engine,
#         target_site=target_site,
#     )
#
#     print(f"Waiting for operation to complete: {operation.operation.name}")
#     response = operation.result()
#
#     # After the operation is complete,
#     # get information from operation metadata
#     metadata = discoveryengine.CreateTargetSiteMetadata(operation.metadata)
#
#     # Handle the response
#     print(response)
#     print(metadata)

השלבים הבאים

ייבוא מ-BigQuery

התכונה 'חיפוש באמצעות סוכן' תומכת בחיפוש בנתוני BigQuery.

יש שתי דרכים ליצור מאגרי נתונים מטבלאות BigQuery:

  • הטמעת נתונים חד-פעמית: מייבאים נתונים מטבלה ב-BigQuery למאגר נתונים. הנתונים במאגר הנתונים לא משתנים אלא אם מרעננים את הנתונים באופן ידני.

  • הטמעה תקופתית: מייבאים נתונים מטבלה אחת או יותר ב-BigQuery ומגדירים תדירות סנכרון שקובעת כמה פעמים מאגרי הנתונים מתעדכנים בנתונים העדכניים ביותר ממערך הנתונים ב-BigQuery.

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

הוספה חד-פעמית הטמעה תקופתית
צריך לרענן את הנתונים באופן ידני. הנתונים מתעדכנים אוטומטית כל יום, כל 3 ימים או כל 5 ימים. אי אפשר לרענן את הנתונים באופן ידני.
חיפוש מבוסס סוכנים יוצר מאגר נתונים יחיד מטבלה אחת ב-BigQuery. התכונה 'חיפוש מבוסס סוכנים' יוצרת מחבר נתונים לקבוצת נתונים של BigQuery ומאגר נתונים (שנקרא מאגר נתונים של ישויות) לכל טבלה שצוינה. לכל מחבר נתונים, הטבלאות צריכות להיות מאותו סוג נתונים (לדוגמה, מובנה) ולהיות באותו מערך נתונים של BigQuery.
אפשר לשלב נתונים מכמה טבלאות במאגר נתונים אחד. לשם כך, קודם מייבאים נתונים מטבלה אחת ואז מייבאים עוד נתונים ממקור אחר או מטבלה ב-BigQuery. מכיוון שאין תמיכה בייבוא נתונים ידני, אפשר להשתמש בנתונים במאגר נתונים של ישות רק מטבלה אחת ב-BigQuery.
יש תמיכה בבקרת גישה למקורות נתונים. אין תמיכה בבקרת גישה למקור הנתונים. הנתונים המיובאים יכולים לכלול אמצעי בקרה לגישה, אבל המערכת לא תתחשב בהם.
אפשר ליצור מאגר נתונים באמצעותGoogle Cloud המסוף או ה-API. צריך להשתמש במסוף כדי ליצור מחברי נתונים ומאגרי נתונים של ישויות.
תואם ל-CMEK. תואם ל-CMEK.

לפני שמתחילים

כדי לייבא נתונים מ Google Cloud פרויקט מקור ששונה מהפרויקט עם מאגר הנתונים של חיפוש מבוסס סוכנים, צריך להקצות לחשבון השירות בפרויקט שמכיל את מאגר הנתונים של חיפוש מבוסס סוכנים את תפקידי ניהול הזהויות והרשאות הגישה (IAM) הבאים:service-PROJECT_NUMBER@gcp-sa-discoveryengine.iam.gserviceaccount.comGoogle Cloud

ייבוא חד-פעמי מ-BigQuery

כדי להטמיע נתונים מטבלה ב-BigQuery, צריך ליצור מאגר נתונים ולהטמיע נתונים באמצעות המסוף Google Cloud או API.

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

המסוף

כדי להשתמש במסוף להטמעת נתונים מ-BigQuery, פועלים לפי השלבים הבאים: Google Cloud

  1. נכנסים לדף AI Applications במסוף Google Cloud .

    אפליקציות AI

  2. עוברים לדף מאגרי נתונים.

  3. לוחצים על יצירת מאגר נתונים.

  4. בדף מקור, בוחרים באפשרות BigQuery.

  5. בקטע איזה סוג נתונים מייבאים?, בוחרים את סוג הנתונים שרוצים לייבא.

  6. בקטע תדירות הסנכרון, בוחרים באפשרות פעם אחת.

  7. בשדה BigQuery path (נתיב BigQuery), לוחצים על Browse (עיון), בוחרים טבלה שהכנתם להעברה ואז לוחצים על Select (בחירה). אפשר גם להזין את מיקום הטבלה ישירות בשדה נתיב BigQuery.

  8. לוחצים על Continue.

  9. אם אתם מבצעים ייבוא חד-פעמי של נתונים מובְנים:

    1. מיפוי שדות למאפייני מפתח.

    2. אם חסרים בסכימה שדות חשובים, משתמשים באפשרות הוספת שדה חדש כדי להוסיף אותם.

      מידע נוסף זמין במאמר מידע על זיהוי ועריכה אוטומטיים.

    3. לוחצים על Continue.

  10. בוחרים אזור למאגר הנתונים.

  11. מזינים שם למאגר הנתונים.

  12. לוחצים על יצירה.

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

    בהתאם לגודל הנתונים, תהליך ההטמעה יכול להימשך כמה דקות עד כמה שעות.

REST

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

  1. יוצרים מאגר נתונים.

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    -H "X-Goog-User-Project: PROJECT_ID" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores?dataStoreId=DATA_STORE_ID" \
    -d '{
      "displayName": "DATA_STORE_DISPLAY_NAME",
      "industryVertical": "GENERIC",
      "solutionTypes": ["SOLUTION_TYPE_SEARCH"]
    }'
    

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

    • PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
    • DATA_STORE_ID: המזהה של מאגר הנתונים של חיפוש מבוסס סוכנים שרוצים ליצור. המזהה יכול להכיל רק אותיות קטנות, ספרות, קווים תחתונים ומקפים.
    • DATA_STORE_DISPLAY_NAME: השם המוצג של מאגר הנתונים של חיפוש מבוסס סוכנים שרוצים ליצור.

    אופציונלי: אם אתם מעלים נתונים לא מובנים ורוצים להגדיר ניתוח של מסמכים או להפעיל חלוקה של מסמכים לחלקים עבור RAG, צריך לציין את אובייקט documentProcessingConfig ולכלול אותו בבקשה ליצירת מאגר נתונים. מומלץ להגדיר מנתח OCR לקובצי PDF אם אתם מבצעים המרה של קובצי PDF סרוקים. במאמר ניתוח מסמכים ופיצול שלהם לחלקים מוסבר איך מגדירים את האפשרויות של ניתוח או פיצול.

  2. ייבוא נתונים מ-BigQuery.

    אם הגדרתם סכימה, ודאו שהנתונים תואמים לסכימה הזו.

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/branches/0/documents:import" \
    -d '{
      "bigquerySource": {
        "projectId": "PROJECT_ID",
        "datasetId":"DATASET_ID",
        "tableId": "TABLE_ID",
        "dataSchema": "DATA_SCHEMA",
        "aclEnabled": "BOOLEAN"
      },
      "reconciliationMode": "RECONCILIATION_MODE",
      "autoGenerateIds": "AUTO_GENERATE_IDS",
      "idField": "ID_FIELD",
      "errorConfig": {
        "gcsPrefix": "ERROR_DIRECTORY"
      }
    }'
    

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

    • PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
    • DATA_STORE_ID: המזהה של מאגר הנתונים של חיפוש מבוסס סוכנים.
    • DATASET_ID: המזהה של מערך הנתונים ב-BigQuery.
    • TABLE_ID: המזהה של הטבלה ב-BigQuery.
      • אם הטבלה ב-BigQuery לא נמצאת ב-PROJECT_ID, צריך לתת לחשבון השירות service-<project number>@gcp-sa-discoveryengine.iam.gserviceaccount.com הרשאה מסוג 'BigQuery Data Viewer' לטבלה ב-BigQuery. לדוגמה, אם מייבאים טבלה מ-BigQuery מפרויקט המקור '123' לפרויקט היעד '456', צריך לתת ל-service-456@gcp-sa-discoveryengine.iam.gserviceaccount.com הרשאות לטבלה ב-BigQuery בפרויקט '123'.
    • DATA_SCHEMA: אופציונלי. הערכים הם document ו-custom. ערך ברירת המחדל הוא document.
      • document: הטבלה ב-BigQuery שבה אתם משתמשים צריכה להתאים לסכימת ברירת המחדל של BigQuery שמופיעה במאמר הכנת נתונים להוספה. אתם יכולים להגדיר את המזהה של כל מסמך בעצמכם, כשכל הנתונים עטופים במחרוזת jsonData.
      • custom: כל סכימת טבלה ב-BigQuery מתקבלת, וחיפוש מבוסס סוכנים יוצר באופן אוטומטי את המזהים לכל מסמך שמייבאים.
    • ERROR_DIRECTORY: אופציונלי. ספרייה ב-Cloud Storage למידע על שגיאות בייבוא – לדוגמה, gs://<your-gcs-bucket>/directory/import_errors. ‫Google ממליצה להשאיר את השדה הזה ריק כדי שהתכונה 'חיפוש באמצעות סוכן' תיצור באופן אוטומטי ספריה זמנית.
    • RECONCILIATION_MODE: אופציונלי. הערכים האפשריים הם FULL ו-INCREMENTAL. ערך ברירת המחדל הוא INCREMENTAL. הגדרה של INCREMENTAL גורמת לרענון מצטבר של הנתונים מ-BigQuery למאגר הנתונים. הפעולה הזו היא upsert, שמוסיפה מסמכים חדשים ומחליפה מסמכים קיימים במסמכים מעודכנים עם אותו מזהה. ציון FULL גורם לשינוי בסיס מלא של המסמכים במאגר הנתונים. במילים אחרות, מסמכים חדשים ומעודכנים מתווספים למאגר הנתונים, ומסמכים שלא נמצאים ב-BigQuery מוסרים ממנו. מצב FULL שימושי אם רוצים למחוק באופן אוטומטי מסמכים שכבר לא צריכים.
    • AUTO_GENERATE_IDS: אופציונלי. ההגדרה קובעת אם מזהי המסמכים ייווצרו באופן אוטומטי. אם הערך הוא true, מזהי המסמכים נוצרים על סמך גיבוב של מטען הייעודי (payload). שימו לב שמזהי המסמכים שנוצרו עשויים להשתנות בין ייבוא לייבוא. אם אתם יוצרים מזהים באופן אוטומטי בכמה ייבואים, מומלץ מאוד להגדיר את reconciliationMode לערך FULL כדי לשמור על מזהי מסמכים עקביים.

      מציינים את autoGenerateIds רק כשbigquerySource.dataSchema מוגדר לערך custom. אחרת, מוחזרת שגיאה INVALID_ARGUMENT. אם לא מציינים את autoGenerateIds או מגדירים אותו ל-false, צריך לציין את idField. אחרת, הייבוא של המסמכים ייכשל.

    • ID_FIELD: אופציונלי. מציין אילו שדות הם מזהי המסמכים. בקבצים של מקורות BigQuery, ‏idField מציין את שם העמודה בטבלת BigQuery שמכילה את מזהי המסמכים.

      מציינים את idField רק אם: (1) הערך של bigquerySource.dataSchema הוא custom, וגם (2) הערך של auto_generate_ids הוא false או שלא צוין ערך. אחרת, מוחזרת שגיאת INVALID_ARGUMENT.

      הערך של שם העמודה ב-BigQuery צריך להיות מסוג string, להכיל בין 1 ל-63 תווים ולעמוד בדרישות של RFC-1034. אחרת, ייבוא המסמכים ייכשל.

C#

מידע נוסף מופיע בתיעוד העזר של ה-API של חיפוש מבוסס סוכנים C#.

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

יצירת מאגר נתונים

using Google.Cloud.DiscoveryEngine.V1;
using Google.LongRunning;

public sealed partial class GeneratedDataStoreServiceClientSnippets
{
    /// <summary>Snippet for CreateDataStore</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void CreateDataStoreRequestObject()
    {
        // Create client
        DataStoreServiceClient dataStoreServiceClient = DataStoreServiceClient.Create();
        // Initialize request argument(s)
        CreateDataStoreRequest request = new CreateDataStoreRequest
        {
            ParentAsCollectionName = CollectionName.FromProjectLocationCollection("[PROJECT]", "[LOCATION]", "[COLLECTION]"),
            DataStore = new DataStore(),
            DataStoreId = "",
            CreateAdvancedSiteSearch = false,
            CmekConfigNameAsCmekConfigName = CmekConfigName.FromProjectLocation("[PROJECT]", "[LOCATION]"),
            SkipDefaultSchemaCreation = false,
        };
        // Make the request
        Operation<DataStore, CreateDataStoreMetadata> response = dataStoreServiceClient.CreateDataStore(request);

        // Poll until the returned long-running operation is complete
        Operation<DataStore, CreateDataStoreMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        DataStore result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<DataStore, CreateDataStoreMetadata> retrievedResponse = dataStoreServiceClient.PollOnceCreateDataStore(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            DataStore retrievedResult = retrievedResponse.Result;
        }
    }
}

ייבוא מסמכים

using Google.Cloud.DiscoveryEngine.V1;
using Google.LongRunning;
using Google.Protobuf.WellKnownTypes;

public sealed partial class GeneratedDocumentServiceClientSnippets
{
    /// <summary>Snippet for ImportDocuments</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void ImportDocumentsRequestObject()
    {
        // Create client
        DocumentServiceClient documentServiceClient = DocumentServiceClient.Create();
        // Initialize request argument(s)
        ImportDocumentsRequest request = new ImportDocumentsRequest
        {
            ParentAsBranchName = BranchName.FromProjectLocationDataStoreBranch("[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[BRANCH]"),
            InlineSource = new ImportDocumentsRequest.Types.InlineSource(),
            ErrorConfig = new ImportErrorConfig(),
            ReconciliationMode = ImportDocumentsRequest.Types.ReconciliationMode.Unspecified,
            UpdateMask = new FieldMask(),
            AutoGenerateIds = false,
            IdField = "",
            ForceRefreshContent = false,
        };
        // Make the request
        Operation<ImportDocumentsResponse, ImportDocumentsMetadata> response = documentServiceClient.ImportDocuments(request);

        // Poll until the returned long-running operation is complete
        Operation<ImportDocumentsResponse, ImportDocumentsMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        ImportDocumentsResponse result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<ImportDocumentsResponse, ImportDocumentsMetadata> retrievedResponse = documentServiceClient.PollOnceImportDocuments(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            ImportDocumentsResponse retrievedResult = retrievedResponse.Result;
        }
    }
}

Go

מידע נוסף מופיע בתיעוד העזר של ה-API של חיפוש מבוסס סוכנים Go.

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

יצירת מאגר נתונים


//go:build examples

package main

import (
	"context"

	discoveryengine "cloud.google.com/go/discoveryengine/apiv1"
	discoveryenginepb "cloud.google.com/go/discoveryengine/apiv1/discoveryenginepb"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := discoveryengine.NewDataStoreClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &discoveryenginepb.CreateDataStoreRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/discoveryengine/apiv1/discoveryenginepb#CreateDataStoreRequest.
	}
	op, err := c.CreateDataStore(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

	resp, err := op.Wait(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

ייבוא מסמכים


//go:build examples

package main

import (
	"context"

	discoveryengine "cloud.google.com/go/discoveryengine/apiv1"
	discoveryenginepb "cloud.google.com/go/discoveryengine/apiv1/discoveryenginepb"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := discoveryengine.NewDocumentClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &discoveryenginepb.ImportDocumentsRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/discoveryengine/apiv1/discoveryenginepb#ImportDocumentsRequest.
	}
	op, err := c.ImportDocuments(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

	resp, err := op.Wait(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

Java

מידע נוסף מופיע בתיעוד העזר של ה-API של חיפוש מבוסס סוכנים Java.

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

יצירת מאגר נתונים

import com.google.cloud.discoveryengine.v1.CollectionName;
import com.google.cloud.discoveryengine.v1.CreateDataStoreRequest;
import com.google.cloud.discoveryengine.v1.DataStore;
import com.google.cloud.discoveryengine.v1.DataStoreServiceClient;

public class SyncCreateDataStore {

  public static void main(String[] args) throws Exception {
    syncCreateDataStore();
  }

  public static void syncCreateDataStore() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (DataStoreServiceClient dataStoreServiceClient = DataStoreServiceClient.create()) {
      CreateDataStoreRequest request =
          CreateDataStoreRequest.newBuilder()
              .setParent(CollectionName.of("[PROJECT]", "[LOCATION]", "[COLLECTION]").toString())
              .setDataStore(DataStore.newBuilder().build())
              .setDataStoreId("dataStoreId929489618")
              .setCreateAdvancedSiteSearch(true)
              .setSkipDefaultSchemaCreation(true)
              .build();
      DataStore response = dataStoreServiceClient.createDataStoreAsync(request).get();
    }
  }
}

ייבוא מסמכים

import com.google.cloud.discoveryengine.v1.BranchName;
import com.google.cloud.discoveryengine.v1.DocumentServiceClient;
import com.google.cloud.discoveryengine.v1.ImportDocumentsRequest;
import com.google.cloud.discoveryengine.v1.ImportDocumentsResponse;
import com.google.cloud.discoveryengine.v1.ImportErrorConfig;
import com.google.protobuf.FieldMask;

public class SyncImportDocuments {

  public static void main(String[] args) throws Exception {
    syncImportDocuments();
  }

  public static void syncImportDocuments() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (DocumentServiceClient documentServiceClient = DocumentServiceClient.create()) {
      ImportDocumentsRequest request =
          ImportDocumentsRequest.newBuilder()
              .setParent(
                  BranchName.ofProjectLocationDataStoreBranchName(
                          "[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[BRANCH]")
                      .toString())
              .setErrorConfig(ImportErrorConfig.newBuilder().build())
              .setUpdateMask(FieldMask.newBuilder().build())
              .setAutoGenerateIds(true)
              .setIdField("idField1629396127")
              .setForceRefreshContent(true)
              .build();
      ImportDocumentsResponse response = documentServiceClient.importDocumentsAsync(request).get();
    }
  }
}

Node.js

מידע נוסף מופיע בתיעוד העזר של ה-API של חיפוש מבוסס סוכנים Node.js.

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

יצירת מאגר נתונים

/**
 * This snippet has been automatically generated and should be regarded as a code template only.
 * It will require modifications to work.
 * It may require correct/in-range values for request initialization.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Resource name of the CmekConfig to use for protecting this DataStore.
 */
// const cmekConfigName = 'abc123'
/**
 *  DataStore without CMEK protections. If a default CmekConfig is set for
 *  the project, setting this field will override the default CmekConfig as
 *  well.
 */
// const disableCmek = true
/**
 *  Required. The parent resource name, such as
 *  `projects/{project}/locations/{location}/collections/{collection}`.
 */
// const parent = 'abc123'
/**
 *  Required. The DataStore google.cloud.discoveryengine.v1.DataStore  to
 *  create.
 */
// const dataStore = {}
/**
 *  Required. The ID to use for the
 *  DataStore google.cloud.discoveryengine.v1.DataStore, which will become
 *  the final component of the
 *  DataStore google.cloud.discoveryengine.v1.DataStore's resource name.
 *  This field must conform to RFC-1034 (https://tools.ietf.org/html/rfc1034)
 *  standard with a length limit of 63 characters. Otherwise, an
 *  INVALID_ARGUMENT error is returned.
 */
// const dataStoreId = 'abc123'
/**
 *  A boolean flag indicating whether user want to directly create an advanced
 *  data store for site search.
 *  If the data store is not configured as site
 *  search (GENERIC vertical and PUBLIC_WEBSITE content_config), this flag will
 *  be ignored.
 */
// const createAdvancedSiteSearch = true
/**
 *  A boolean flag indicating whether to skip the default schema creation for
 *  the data store. Only enable this flag if you are certain that the default
 *  schema is incompatible with your use case.
 *  If set to true, you must manually create a schema for the data store before
 *  any documents can be ingested.
 *  This flag cannot be specified if `data_store.starting_schema` is specified.
 */
// const skipDefaultSchemaCreation = true

// Imports the Discoveryengine library
const {DataStoreServiceClient} = require('@google-cloud/discoveryengine').v1;

// Instantiates a client
const discoveryengineClient = new DataStoreServiceClient();

async function callCreateDataStore() {
  // Construct request
  const request = {
    parent,
    dataStore,
    dataStoreId,
  };

  // Run request
  const [operation] = await discoveryengineClient.createDataStore(request);
  const [response] = await operation.promise();
  console.log(response);
}

callCreateDataStore();

ייבוא מסמכים

/**
 * This snippet has been automatically generated and should be regarded as a code template only.
 * It will require modifications to work.
 * It may require correct/in-range values for request initialization.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  The Inline source for the input content for documents.
 */
// const inlineSource = {}
/**
 *  Cloud Storage location for the input content.
 */
// const gcsSource = {}
/**
 *  BigQuery input source.
 */
// const bigquerySource = {}
/**
 *  FhirStore input source.
 */
// const fhirStoreSource = {}
/**
 *  Spanner input source.
 */
// const spannerSource = {}
/**
 *  Cloud SQL input source.
 */
// const cloudSqlSource = {}
/**
 *  Firestore input source.
 */
// const firestoreSource = {}
/**
 *  AlloyDB input source.
 */
// const alloyDbSource = {}
/**
 *  Cloud Bigtable input source.
 */
// const bigtableSource = {}
/**
 *  Required. The parent branch resource name, such as
 *  `projects/{project}/locations/{location}/collections/{collection}/dataStores/{data_store}/branches/{branch}`.
 *  Requires create/update permission.
 */
// const parent = 'abc123'
/**
 *  The desired location of errors incurred during the Import.
 */
// const errorConfig = {}
/**
 *  The mode of reconciliation between existing documents and the documents to
 *  be imported. Defaults to
 *  ReconciliationMode.INCREMENTAL google.cloud.discoveryengine.v1.ImportDocumentsRequest.ReconciliationMode.INCREMENTAL.
 */
// const reconciliationMode = {}
/**
 *  Indicates which fields in the provided imported documents to update. If
 *  not set, the default is to update all fields.
 */
// const updateMask = {}
/**
 *  Whether to automatically generate IDs for the documents if absent.
 *  If set to `true`,
 *  Document.id google.cloud.discoveryengine.v1.Document.id s are
 *  automatically generated based on the hash of the payload, where IDs may not
 *  be consistent during multiple imports. In which case
 *  ReconciliationMode.FULL google.cloud.discoveryengine.v1.ImportDocumentsRequest.ReconciliationMode.FULL 
 *  is highly recommended to avoid duplicate contents. If unset or set to
 *  `false`, Document.id google.cloud.discoveryengine.v1.Document.id s have
 *  to be specified using
 *  id_field google.cloud.discoveryengine.v1.ImportDocumentsRequest.id_field,
 *  otherwise, documents without IDs fail to be imported.
 *  Supported data sources:
 *  * GcsSource google.cloud.discoveryengine.v1.GcsSource.
 *  GcsSource.data_schema google.cloud.discoveryengine.v1.GcsSource.data_schema 
 *  must be `custom` or `csv`. Otherwise, an INVALID_ARGUMENT error is thrown.
 *  * BigQuerySource google.cloud.discoveryengine.v1.BigQuerySource.
 *  BigQuerySource.data_schema google.cloud.discoveryengine.v1.BigQuerySource.data_schema 
 *  must be `custom` or `csv`. Otherwise, an INVALID_ARGUMENT error is thrown.
 *  * SpannerSource google.cloud.discoveryengine.v1.SpannerSource.
 *  * CloudSqlSource google.cloud.discoveryengine.v1.CloudSqlSource.
 *  * FirestoreSource google.cloud.discoveryengine.v1.FirestoreSource.
 *  * BigtableSource google.cloud.discoveryengine.v1.BigtableSource.
 */
// const autoGenerateIds = true
/**
 *  The field indicates the ID field or column to be used as unique IDs of
 *  the documents.
 *  For GcsSource google.cloud.discoveryengine.v1.GcsSource  it is the key of
 *  the JSON field. For instance, `my_id` for JSON `{"my_id": "some_uuid"}`.
 *  For others, it may be the column name of the table where the unique ids are
 *  stored.
 *  The values of the JSON field or the table column are used as the
 *  Document.id google.cloud.discoveryengine.v1.Document.id s. The JSON field
 *  or the table column must be of string type, and the values must be set as
 *  valid strings conform to RFC-1034 (https://tools.ietf.org/html/rfc1034)
 *  with 1-63 characters. Otherwise, documents without valid IDs fail to be
 *  imported.
 *  Only set this field when
 *  auto_generate_ids google.cloud.discoveryengine.v1.ImportDocumentsRequest.auto_generate_ids 
 *  is unset or set as `false`. Otherwise, an INVALID_ARGUMENT error is thrown.
 *  If it is unset, a default value `_id` is used when importing from the
 *  allowed data sources.
 *  Supported data sources:
 *  * GcsSource google.cloud.discoveryengine.v1.GcsSource.
 *  GcsSource.data_schema google.cloud.discoveryengine.v1.GcsSource.data_schema 
 *  must be `custom` or `csv`. Otherwise, an INVALID_ARGUMENT error is thrown.
 *  * BigQuerySource google.cloud.discoveryengine.v1.BigQuerySource.
 *  BigQuerySource.data_schema google.cloud.discoveryengine.v1.BigQuerySource.data_schema 
 *  must be `custom` or `csv`. Otherwise, an INVALID_ARGUMENT error is thrown.
 *  * SpannerSource google.cloud.discoveryengine.v1.SpannerSource.
 *  * CloudSqlSource google.cloud.discoveryengine.v1.CloudSqlSource.
 *  * FirestoreSource google.cloud.discoveryengine.v1.FirestoreSource.
 *  * BigtableSource google.cloud.discoveryengine.v1.BigtableSource.
 */
// const idField = 'abc123'
/**
 *  Optional. Whether to force refresh the unstructured content of the
 *  documents.
 *  If set to `true`, the content part of the documents will be refreshed
 *  regardless of the update status of the referencing content.
 */
// const forceRefreshContent = true

// Imports the Discoveryengine library
const {DocumentServiceClient} = require('@google-cloud/discoveryengine').v1;

// Instantiates a client
const discoveryengineClient = new DocumentServiceClient();

async function callImportDocuments() {
  // Construct request
  const request = {
    parent,
  };

  // Run request
  const [operation] = await discoveryengineClient.importDocuments(request);
  const [response] = await operation.promise();
  console.log(response);
}

callImportDocuments();

Python

מידע נוסף מופיע בתיעוד העזר של ה-API של חיפוש מבוסס סוכנים Python.

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

יצירת מאגר נתונים


from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"
# location = "YOUR_LOCATION" # Values: "global"
# data_store_id = "YOUR_DATA_STORE_ID"


def create_data_store_sample(
    project_id: str,
    location: str,
    data_store_id: str,
) -> str:
    #  For more information, refer to:
    # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
    client_options = (
        ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
        if location != "global"
        else None
    )

    # Create a client
    client = discoveryengine.DataStoreServiceClient(client_options=client_options)

    # The full resource name of the collection
    # e.g. projects/{project}/locations/{location}/collections/default_collection
    parent = client.collection_path(
        project=project_id,
        location=location,
        collection="default_collection",
    )

    data_store = discoveryengine.DataStore(
        display_name="My Data Store",
        # Options: GENERIC, MEDIA, HEALTHCARE_FHIR
        industry_vertical=discoveryengine.IndustryVertical.GENERIC,
        # Options: SOLUTION_TYPE_RECOMMENDATION, SOLUTION_TYPE_SEARCH, SOLUTION_TYPE_CHAT, SOLUTION_TYPE_GENERATIVE_CHAT
        solution_types=[discoveryengine.SolutionType.SOLUTION_TYPE_SEARCH],
        # TODO(developer): Update content_config based on data store type.
        # Options: NO_CONTENT, CONTENT_REQUIRED, PUBLIC_WEBSITE
        content_config=discoveryengine.DataStore.ContentConfig.CONTENT_REQUIRED,
    )

    request = discoveryengine.CreateDataStoreRequest(
        parent=parent,
        data_store_id=data_store_id,
        data_store=data_store,
        # Optional: For Advanced Site Search Only
        # create_advanced_site_search=True,
    )

    # Make the request
    operation = client.create_data_store(request=request)

    print(f"Waiting for operation to complete: {operation.operation.name}")
    response = operation.result()

    # After the operation is complete,
    # get information from operation metadata
    metadata = discoveryengine.CreateDataStoreMetadata(operation.metadata)

    # Handle the response
    print(response)
    print(metadata)

    return operation.operation.name

ייבוא מסמכים


from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"
# location = "YOUR_LOCATION" # Values: "global"
# data_store_id = "YOUR_DATA_STORE_ID"
# bigquery_dataset = "YOUR_BIGQUERY_DATASET"
# bigquery_table = "YOUR_BIGQUERY_TABLE"

#  For more information, refer to:
# https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
client_options = (
    ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
    if location != "global"
    else None
)

# Create a client
client = discoveryengine.DocumentServiceClient(client_options=client_options)

# The full resource name of the search engine branch.
# e.g. projects/{project}/locations/{location}/dataStores/{data_store_id}/branches/{branch}
parent = client.branch_path(
    project=project_id,
    location=location,
    data_store=data_store_id,
    branch="default_branch",
)

request = discoveryengine.ImportDocumentsRequest(
    parent=parent,
    bigquery_source=discoveryengine.BigQuerySource(
        project_id=project_id,
        dataset_id=bigquery_dataset,
        table_id=bigquery_table,
        data_schema="custom",
    ),
    # Options: `FULL`, `INCREMENTAL`
    reconciliation_mode=discoveryengine.ImportDocumentsRequest.ReconciliationMode.INCREMENTAL,
)

# Make the request
operation = client.import_documents(request=request)

print(f"Waiting for operation to complete: {operation.operation.name}")
response = operation.result()

# After the operation is complete,
# get information from operation metadata
metadata = discoveryengine.ImportDocumentsMetadata(operation.metadata)

# Handle the response
print(response)
print(metadata)

Ruby

מידע נוסף מופיע בתיעוד העזר של ה-API של חיפוש מבוסס סוכנים Ruby.

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

יצירת מאגר נתונים

require "google/cloud/discovery_engine/v1"

##
# Snippet for the create_data_store call in the DataStoreService service
#
# This snippet has been automatically generated and should be regarded as a code
# template only. It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in https://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::DiscoveryEngine::V1::DataStoreService::Client#create_data_store.
#
def create_data_store
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::DiscoveryEngine::V1::DataStoreService::Client.new

  # Create a request. To set request fields, pass in keyword arguments.
  request = Google::Cloud::DiscoveryEngine::V1::CreateDataStoreRequest.new

  # Call the create_data_store method.
  result = client.create_data_store request

  # The returned object is of type Gapic::Operation. You can use it to
  # check the status of an operation, cancel it, or wait for results.
  # Here is how to wait for a response.
  result.wait_until_done! timeout: 60
  if result.response?
    p result.response
  else
    puts "No response received."
  end
end

ייבוא מסמכים

require "google/cloud/discovery_engine/v1"

##
# Snippet for the import_documents call in the DocumentService service
#
# This snippet has been automatically generated and should be regarded as a code
# template only. It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in https://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::DiscoveryEngine::V1::DocumentService::Client#import_documents.
#
def import_documents
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::DiscoveryEngine::V1::DocumentService::Client.new

  # Create a request. To set request fields, pass in keyword arguments.
  request = Google::Cloud::DiscoveryEngine::V1::ImportDocumentsRequest.new

  # Call the import_documents method.
  result = client.import_documents request

  # The returned object is of type Gapic::Operation. You can use it to
  # check the status of an operation, cancel it, or wait for results.
  # Here is how to wait for a response.
  result.wait_until_done! timeout: 60
  if result.response?
    p result.response
  else
    puts "No response received."
  end
end

התחברות ל-BigQuery עם סנכרון תקופתי

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

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

הנתונים ממערך הנתונים מסונכרנים מעת לעת עם מאגרי הנתונים של הישויות. אפשר לציין סנכרון יומי, כל שלושה ימים או כל חמישה ימים.

המסוף

כדי להשתמש במסוף Google Cloud כדי ליצור מחבר שמסנכרן נתונים ממערך נתונים ב-BigQuery לחיפוש מבוסס סוכנים באופן תקופתי, פועלים לפי השלבים הבאים:

  1. נכנסים לדף AI Applications במסוף Google Cloud .

    אפליקציות AI

  2. בתפריט הניווט, לוחצים על מאגרי נתונים.

  3. לוחצים על יצירת מאגר נתונים.

  4. בדף מקור, בוחרים באפשרות BigQuery.

  5. בוחרים את סוג הנתונים שמייבאים.

  6. לוחצים על תקופתי.

  7. בוחרים את תדירות הסנכרון, כלומר כמה פעמים רוצים שמחבר Agent Search יסנכרן עם מערך הנתונים של BigQuery. אפשר לשנות את התדירות בהמשך.

  8. בשדה נתיב למערך הנתונים ב-BigQuery, לוחצים על עיון, בוחרים את מערך הנתונים שמכיל את הטבלאות שהכנתם להעלאה. אפשרות אחרת היא להזין את מיקום הטבלה ישירות בשדה נתיב BigQuery. הפורמט של הנתיב הוא projectname.datasetname.

  9. בשדה Tables to sync, לוחצים על Browse ובוחרים טבלה שמכילה את הנתונים שרוצים לאחסן במאגר הנתונים.

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

  11. לוחצים על Continue.

  12. בוחרים אזור לאחסון הנתונים, מזינים שם למחבר הנתונים ולוחצים על יצירה.

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

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

    בהתאם לגודל הנתונים, תהליך ההטמעה יכול להימשך כמה דקות עד כמה שעות.

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

השלבים הבאים

ייבוא מ-Cloud Storage

.

יש שתי דרכים ליצור מאגרי נתונים מטבלאות ב-Cloud Storage:

  • העברה חד-פעמית: מייבאים נתונים מתיקייה או מקובץ ב-Cloud Storage למאגר נתונים. הנתונים במאגר הנתונים לא משתנים אלא אם מרעננים את הנתונים באופן ידני.

  • הטמעה תקופתית: אתם מייבאים נתונים מתיקייה או מקובץ ב-Cloud Storage, ומגדירים תדירות סנכרון שקובעת כמה פעמים מאגר הנתונים מתעדכן בנתונים העדכניים ביותר ממיקום Cloud Storage הזה.

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

הוספה חד-פעמית הטמעה תקופתית
צריך לרענן את הנתונים באופן ידני. הנתונים מתעדכנים אוטומטית כל יום, כל שלושה ימים או כל חמישה ימים. אי אפשר לרענן את הנתונים באופן ידני.
חיפוש מבוסס סוכנים יוצר מאגר נתונים יחיד מתיקייה או מקובץ אחד ב-Cloud Storage. התכונה 'חיפוש מבוסס סוכנים' יוצרת מחבר נתונים, ומקשרת אליו מאגר נתונים (שנקרא מאגר נתונים של ישויות) עבור הקובץ או התיקייה שצוינו. לכל מחבר נתונים של Cloud Storage יכול להיות מאגר נתונים של ישות אחת.
אפשר לשלב נתונים מכמה קבצים, תיקיות וקטגוריות במאגר נתונים אחד. לשם כך, קודם צריך להטמיע נתונים ממיקום אחד ב-Cloud Storage, ואז להטמיע עוד נתונים ממיקום אחר. מכיוון שייבוא נתונים ידני לא אפשרי, אפשר להשתמש בנתונים במאגר נתונים של ישות רק מקובץ או מתיקייה אחת ב-Cloud Storage.
יש תמיכה בבקרת גישה למקורות נתונים. מידע נוסף מופיע במאמר בנושא בקרת גישה למקורות נתונים. אין תמיכה בבקרת גישה למקור הנתונים. הנתונים המיובאים יכולים לכלול אמצעי בקרה לגישה, אבל המערכת לא תתחשב בהם.
אפשר ליצור מאגר נתונים באמצעותGoogle Cloud המסוף או ה-API. צריך להשתמש במסוף כדי ליצור מחברי נתונים ומאגרי נתונים של ישויות.
תואם ל-CMEK. תואם ל-CMEK.

לפני שמתחילים

כדי לייבא נתונים מ Google Cloud פרויקט מקור ששונה מהפרויקט עם מאגר הנתונים של חיפוש מבוסס סוכנים, צריך להקצות לחשבון השירות בפרויקט שמכיל את מאגר הנתונים של חיפוש מבוסס סוכנים את תפקידי ניהול הזהויות והרשאות הגישה (IAM) הבאים:service-PROJECT_NUMBER@gcp-sa-discoveryengine.iam.gserviceaccount.comGoogle Cloud

ייבוא חד-פעמי מ-Cloud Storage

כדי להטמיע נתונים מ-Cloud Storage, צריך ליצור מאגר נתונים ולהטמיע נתונים באמצעות Google Cloud המסוף או ה-API.

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

המסוף

כדי להשתמש במסוף להטמעת נתונים מקטגוריה של Cloud Storage, פועלים לפי השלבים הבאים:

  1. נכנסים לדף AI Applications במסוף Google Cloud .

    אפליקציות AI

  2. עוברים לדף מאגרי נתונים.

  3. לוחצים על יצירת מאגר נתונים.

  4. בדף מקור, בוחרים באפשרות Cloud Storage.

  5. בקטע בחירת תיקייה או קובץ לייבוא, בוחרים באפשרות תיקייה או קובץ.

  6. לוחצים על עיון, בוחרים את הנתונים שהכנתם להעלאה ולוחצים על בחירה. אפשר גם להזין את המיקום ישירות בשדה gs://.

  7. בוחרים את סוג הנתונים שמייבאים.

  8. לוחצים על Continue.

  9. אם אתם מבצעים ייבוא חד-פעמי של נתונים מובְנים:

    1. מיפוי שדות למאפייני מפתח.

    2. אם חסרים בסכימה שדות חשובים, משתמשים באפשרות הוספת שדה חדש כדי להוסיף אותם.

      מידע נוסף זמין במאמר מידע על זיהוי ועריכה אוטומטיים.

    3. לוחצים על Continue.

  10. בוחרים אזור למאגר הנתונים.

  11. מזינים שם למאגר הנתונים.

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

    שימוש בכלי לניתוח OCR ובכלי לניתוח פריסה עלול לגרור עלויות נוספות. מידע על התמחור של התכונות ב-Document AI

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

  13. לוחצים על יצירה.

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

    בהתאם לגודל הנתונים, תהליך ההטמעה יכול להימשך כמה דקות או כמה שעות.

REST

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

  1. יוצרים מאגר נתונים.

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    -H "X-Goog-User-Project: PROJECT_ID" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores?dataStoreId=DATA_STORE_ID" \
    -d '{
      "displayName": "DATA_STORE_DISPLAY_NAME",
      "industryVertical": "GENERIC",
      "solutionTypes": ["SOLUTION_TYPE_SEARCH"]
    }'
    

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

    • PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
    • DATA_STORE_ID: המזהה של מאגר הנתונים של חיפוש מבוסס סוכנים שרוצים ליצור. המזהה יכול להכיל רק אותיות קטנות, ספרות, קווים תחתונים ומקפים.
    • DATA_STORE_DISPLAY_NAME: השם המוצג של מאגר הנתונים של חיפוש מבוסס סוכנים שרוצים ליצור.

    אופציונלי: אם אתם מעלים נתונים לא מובנים ורוצים להגדיר ניתוח של מסמכים או להפעיל חלוקה של מסמכים לחלקים עבור RAG, צריך לציין את אובייקט documentProcessingConfig ולכלול אותו בבקשה ליצירת מאגר נתונים. מומלץ להגדיר מנתח OCR לקובצי PDF אם אתם מבצעים המרה של קובצי PDF סרוקים. במאמר ניתוח מסמכים ופיצול שלהם לחלקים מוסבר איך מגדירים את האפשרויות של ניתוח או פיצול.

  2. ייבוא נתונים מ-Cloud Storage.

      curl -X POST \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/branches/0/documents:import" \
      -d '{
        "gcsSource": {
          "inputUris": ["INPUT_FILE_PATTERN_1", "INPUT_FILE_PATTERN_2"],
          "dataSchema": "DATA_SCHEMA",
        },
        "reconciliationMode": "RECONCILIATION_MODE",
        "autoGenerateIds": "AUTO_GENERATE_IDS",
        "idField": "ID_FIELD",
        "errorConfig": {
          "gcsPrefix": "ERROR_DIRECTORY"
        }
      }'
    

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

    • PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
    • DATA_STORE_ID: המזהה של מאגר הנתונים של חיפוש מבוסס סוכנים.
    • INPUT_FILE_PATTERN: תבנית קובץ ב-Cloud Storage שמכילה את המסמכים שלכם.

      לנתונים מובְנים או לנתונים לא מובְנים עם מטא-נתונים, דוגמה לתבנית של קובץ קלט היא gs://<your-gcs-bucket>/directory/object.jsonודוגמה להתאמת תבנית לקובץ אחד או יותר היא gs://<your-gcs-bucket>/directory/*.json.

      דוגמה למסמך לא מובנה היא gs://<your-gcs-bucket>/directory/*.pdf. כל קובץ שתואם לתבנית הופך למסמך.

      אם <your-gcs-bucket> לא מופיע בקטע PROJECT_ID, צריך לתת לחשבון השירות service-<project number>@gcp-sa-discoveryengine.iam.gserviceaccount.com הרשאות 'צפייה באובייקט אחסון' לקטגוריה של Cloud Storage. לדוגמה, אם מייבאים קטגוריה של Cloud Storage מפרויקט המקור '123' לפרויקט היעד '456', צריך לתת הרשאות service-456@gcp-sa-discoveryengine.iam.gserviceaccount.com בקטגוריה של Cloud Storage בפרויקט '123'.

    • DATA_SCHEMA: אופציונלי. הערכים הם document,‏ custom,‏ csv ו-content. ערך ברירת המחדל הוא document.

      • document: העלאת נתונים לא מובנים עם מטא-נתונים עבור מסמכים לא מובנים. כל שורה בקובץ צריכה להיות באחד מהפורמטים הבאים. אפשר להגדיר את המזהה של כל מסמך:

        • { "id": "<your-id>", "jsonData": "<JSON string>", "content": { "mimeType": "<application/pdf or text/html>", "uri": "gs://<your-gcs-bucket>/directory/filename.pdf" } }
        • { "id": "<your-id>", "structData": <JSON object>, "content": { "mimeType": "<application/pdf or text/html>", "uri": "gs://<your-gcs-bucket>/directory/filename.pdf" } }
      • custom: העלאת JSON למסמכים מובנים. הנתונים מאורגנים לפי סכימה. אפשר לציין את הסכימה, אחרת המערכת תזהה אותה באופן אוטומטי. אפשר להזין את מחרוזת ה-JSON של המסמך בפורמט עקבי ישירות בכל שורה, ו'חיפוש מבוסס סוכנים' ייצור באופן אוטומטי את המזהים לכל מסמך שיובא.

      • content: העלאת מסמכים לא מובנים (PDF, ‏ HTML, ‏ DOC, ‏ TXT,‏ PPTX). המזהה של כל מסמך נוצר אוטומטית בתור 128 הביטים הראשונים של SHA256(GCS_URI) שמקודדים כמחרוזת הקסדצימלית. אפשר לציין כמה תבניות של קובצי קלט, כל עוד מספר הקבצים התואמים לא חורג מהמגבלה של 100,000 קבצים.

      • csv: כוללים שורת כותרת בקובץ ה-CSV, כשכל כותרת ממופה לשדה במסמך. מציינים את הנתיב לקובץ ה-CSV באמצעות השדה inputUris.

    • ERROR_DIRECTORY: אופציונלי. ספרייה ב-Cloud Storage למידע על שגיאות בייבוא – לדוגמה, gs://<your-gcs-bucket>/directory/import_errors. ‫Google ממליצה להשאיר את השדה הזה ריק כדי ש'חיפוש מבוסס סוכנים' ייצור באופן אוטומטי ספרייה זמנית.

    • RECONCILIATION_MODE: אופציונלי. הערכים הם FULL ו-INCREMENTAL. ערך ברירת המחדל הוא INCREMENTAL. הגדרה של INCREMENTAL גורמת לרענון מצטבר של נתונים מ-Cloud Storage למאגר הנתונים. הפעולה הזו מבצעת upsert, שמוסיף מסמכים חדשים ומחליף מסמכים קיימים במסמכים מעודכנים עם אותו מזהה. הגדרת FULL גורמת לשינוי בסיס מלא של המסמכים במאגר הנתונים. כלומר, מסמכים חדשים ומעודכנים מתווספים למאגר הנתונים, ומסמכים שלא נמצאים ב-Cloud Storage מוסרים ממנו. מצב FULL שימושי אם רוצים למחוק באופן אוטומטי מסמכים שכבר לא צריכים.

    • AUTO_GENERATE_IDS: אופציונלי. ההגדרה קובעת אם מזהי המסמכים ייווצרו באופן אוטומטי. אם המדיניות מוגדרת לערך true, מזהי המסמכים נוצרים על סמך גיבוב (hash) של מטען הייעודי. חשוב לדעת שמזהי מסמכים שנוצרו יכולים להשתנות בין ייבוא לייבוא. אם אתם יוצרים מזהים באופן אוטומטי בכמה ייבואים, מומלץ מאוד להגדיר את reconciliationMode ל-FULL כדי לשמור על מזהי מסמכים עקביים.

      מציינים את autoGenerateIds רק אם הערך של gcsSource.dataSchema הוא custom או csv. אחרת, מוחזרת שגיאת INVALID_ARGUMENT. אם לא מציינים את autoGenerateIds או מגדירים אותו ל-false, צריך לציין את idField. אחרת, ייבוא המסמכים ייכשל.

    • ID_FIELD: אופציונלי. מציינים אילו שדות הם מזהי המסמכים. במסמכי מקור של Cloud Storage, ‏ idField מציין את השם בשדות ה-JSON שהם מזהי מסמכים. לדוגמה, אם {"my_id":"some_uuid"} הוא שדה מזהה המסמך באחד מהמסמכים, מציינים "idField":"my_id". השדה הזה מזהה את כל שדות ה-JSON עם השם "my_id" כמזהי מסמכים.

      מציינים את השדה הזה רק אם: (1) הערך של gcsSource.dataSchema הוא custom או csv, ו-(2) הערך של auto_generate_ids הוא false או שלא צוין ערך. אחרת, מוחזרת שגיאת INVALID_ARGUMENT.

      שימו לב: הערך של שדה ה-JSON ב-Cloud Storage חייב להיות מסוג מחרוזת, להכיל בין 1 ל-63 תווים ולעמוד בדרישות של RFC-1034. אחרת, ייבוא המסמכים ייכשל.

      שימו לב ששם השדה ב-JSON שצוין על ידי id_field חייב להיות מסוג מחרוזת, להכיל בין 1 ל-63 תווים ולעמוד בדרישות של RFC-1034. אחרת, ייבוא המסמכים ייכשל.

C#

מידע נוסף מופיע בתיעוד העזר של ה-API של חיפוש מבוסס סוכנים C#.

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

יצירת מאגר נתונים

using Google.Cloud.DiscoveryEngine.V1;
using Google.LongRunning;

public sealed partial class GeneratedDataStoreServiceClientSnippets
{
    /// <summary>Snippet for CreateDataStore</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void CreateDataStoreRequestObject()
    {
        // Create client
        DataStoreServiceClient dataStoreServiceClient = DataStoreServiceClient.Create();
        // Initialize request argument(s)
        CreateDataStoreRequest request = new CreateDataStoreRequest
        {
            ParentAsCollectionName = CollectionName.FromProjectLocationCollection("[PROJECT]", "[LOCATION]", "[COLLECTION]"),
            DataStore = new DataStore(),
            DataStoreId = "",
            CreateAdvancedSiteSearch = false,
            CmekConfigNameAsCmekConfigName = CmekConfigName.FromProjectLocation("[PROJECT]", "[LOCATION]"),
            SkipDefaultSchemaCreation = false,
        };
        // Make the request
        Operation<DataStore, CreateDataStoreMetadata> response = dataStoreServiceClient.CreateDataStore(request);

        // Poll until the returned long-running operation is complete
        Operation<DataStore, CreateDataStoreMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        DataStore result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<DataStore, CreateDataStoreMetadata> retrievedResponse = dataStoreServiceClient.PollOnceCreateDataStore(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            DataStore retrievedResult = retrievedResponse.Result;
        }
    }
}

ייבוא מסמכים

using Google.Cloud.DiscoveryEngine.V1;
using Google.LongRunning;
using Google.Protobuf.WellKnownTypes;

public sealed partial class GeneratedDocumentServiceClientSnippets
{
    /// <summary>Snippet for ImportDocuments</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void ImportDocumentsRequestObject()
    {
        // Create client
        DocumentServiceClient documentServiceClient = DocumentServiceClient.Create();
        // Initialize request argument(s)
        ImportDocumentsRequest request = new ImportDocumentsRequest
        {
            ParentAsBranchName = BranchName.FromProjectLocationDataStoreBranch("[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[BRANCH]"),
            InlineSource = new ImportDocumentsRequest.Types.InlineSource(),
            ErrorConfig = new ImportErrorConfig(),
            ReconciliationMode = ImportDocumentsRequest.Types.ReconciliationMode.Unspecified,
            UpdateMask = new FieldMask(),
            AutoGenerateIds = false,
            IdField = "",
            ForceRefreshContent = false,
        };
        // Make the request
        Operation<ImportDocumentsResponse, ImportDocumentsMetadata> response = documentServiceClient.ImportDocuments(request);

        // Poll until the returned long-running operation is complete
        Operation<ImportDocumentsResponse, ImportDocumentsMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        ImportDocumentsResponse result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<ImportDocumentsResponse, ImportDocumentsMetadata> retrievedResponse = documentServiceClient.PollOnceImportDocuments(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            ImportDocumentsResponse retrievedResult = retrievedResponse.Result;
        }
    }
}

Go

מידע נוסף מופיע בתיעוד העזר של ה-API של חיפוש מבוסס סוכנים Go.

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

יצירת מאגר נתונים


//go:build examples

package main

import (
	"context"

	discoveryengine "cloud.google.com/go/discoveryengine/apiv1"
	discoveryenginepb "cloud.google.com/go/discoveryengine/apiv1/discoveryenginepb"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := discoveryengine.NewDataStoreClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &discoveryenginepb.CreateDataStoreRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/discoveryengine/apiv1/discoveryenginepb#CreateDataStoreRequest.
	}
	op, err := c.CreateDataStore(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

	resp, err := op.Wait(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

ייבוא מסמכים


//go:build examples

package main

import (
	"context"

	discoveryengine "cloud.google.com/go/discoveryengine/apiv1"
	discoveryenginepb "cloud.google.com/go/discoveryengine/apiv1/discoveryenginepb"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := discoveryengine.NewDocumentClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &discoveryenginepb.ImportDocumentsRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/discoveryengine/apiv1/discoveryenginepb#ImportDocumentsRequest.
	}
	op, err := c.ImportDocuments(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

	resp, err := op.Wait(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

Java

מידע נוסף מופיע בתיעוד העזר של ה-API של חיפוש מבוסס סוכנים Java.

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

יצירת מאגר נתונים

import com.google.cloud.discoveryengine.v1.CollectionName;
import com.google.cloud.discoveryengine.v1.CreateDataStoreRequest;
import com.google.cloud.discoveryengine.v1.DataStore;
import com.google.cloud.discoveryengine.v1.DataStoreServiceClient;

public class SyncCreateDataStore {

  public static void main(String[] args) throws Exception {
    syncCreateDataStore();
  }

  public static void syncCreateDataStore() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (DataStoreServiceClient dataStoreServiceClient = DataStoreServiceClient.create()) {
      CreateDataStoreRequest request =
          CreateDataStoreRequest.newBuilder()
              .setParent(CollectionName.of("[PROJECT]", "[LOCATION]", "[COLLECTION]").toString())
              .setDataStore(DataStore.newBuilder().build())
              .setDataStoreId("dataStoreId929489618")
              .setCreateAdvancedSiteSearch(true)
              .setSkipDefaultSchemaCreation(true)
              .build();
      DataStore response = dataStoreServiceClient.createDataStoreAsync(request).get();
    }
  }
}

ייבוא מסמכים

import com.google.cloud.discoveryengine.v1.BranchName;
import com.google.cloud.discoveryengine.v1.DocumentServiceClient;
import com.google.cloud.discoveryengine.v1.ImportDocumentsRequest;
import com.google.cloud.discoveryengine.v1.ImportDocumentsResponse;
import com.google.cloud.discoveryengine.v1.ImportErrorConfig;
import com.google.protobuf.FieldMask;

public class SyncImportDocuments {

  public static void main(String[] args) throws Exception {
    syncImportDocuments();
  }

  public static void syncImportDocuments() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (DocumentServiceClient documentServiceClient = DocumentServiceClient.create()) {
      ImportDocumentsRequest request =
          ImportDocumentsRequest.newBuilder()
              .setParent(
                  BranchName.ofProjectLocationDataStoreBranchName(
                          "[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[BRANCH]")
                      .toString())
              .setErrorConfig(ImportErrorConfig.newBuilder().build())
              .setUpdateMask(FieldMask.newBuilder().build())
              .setAutoGenerateIds(true)
              .setIdField("idField1629396127")
              .setForceRefreshContent(true)
              .build();
      ImportDocumentsResponse response = documentServiceClient.importDocumentsAsync(request).get();
    }
  }
}

Node.js

מידע נוסף מופיע בתיעוד העזר של ה-API של חיפוש מבוסס סוכנים Node.js.

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

יצירת מאגר נתונים

/**
 * This snippet has been automatically generated and should be regarded as a code template only.
 * It will require modifications to work.
 * It may require correct/in-range values for request initialization.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Resource name of the CmekConfig to use for protecting this DataStore.
 */
// const cmekConfigName = 'abc123'
/**
 *  DataStore without CMEK protections. If a default CmekConfig is set for
 *  the project, setting this field will override the default CmekConfig as
 *  well.
 */
// const disableCmek = true
/**
 *  Required. The parent resource name, such as
 *  `projects/{project}/locations/{location}/collections/{collection}`.
 */
// const parent = 'abc123'
/**
 *  Required. The DataStore google.cloud.discoveryengine.v1.DataStore  to
 *  create.
 */
// const dataStore = {}
/**
 *  Required. The ID to use for the
 *  DataStore google.cloud.discoveryengine.v1.DataStore, which will become
 *  the final component of the
 *  DataStore google.cloud.discoveryengine.v1.DataStore's resource name.
 *  This field must conform to RFC-1034 (https://tools.ietf.org/html/rfc1034)
 *  standard with a length limit of 63 characters. Otherwise, an
 *  INVALID_ARGUMENT error is returned.
 */
// const dataStoreId = 'abc123'
/**
 *  A boolean flag indicating whether user want to directly create an advanced
 *  data store for site search.
 *  If the data store is not configured as site
 *  search (GENERIC vertical and PUBLIC_WEBSITE content_config), this flag will
 *  be ignored.
 */
// const createAdvancedSiteSearch = true
/**
 *  A boolean flag indicating whether to skip the default schema creation for
 *  the data store. Only enable this flag if you are certain that the default
 *  schema is incompatible with your use case.
 *  If set to true, you must manually create a schema for the data store before
 *  any documents can be ingested.
 *  This flag cannot be specified if `data_store.starting_schema` is specified.
 */
// const skipDefaultSchemaCreation = true

// Imports the Discoveryengine library
const {DataStoreServiceClient} = require('@google-cloud/discoveryengine').v1;

// Instantiates a client
const discoveryengineClient = new DataStoreServiceClient();

async function callCreateDataStore() {
  // Construct request
  const request = {
    parent,
    dataStore,
    dataStoreId,
  };

  // Run request
  const [operation] = await discoveryengineClient.createDataStore(request);
  const [response] = await operation.promise();
  console.log(response);
}

callCreateDataStore();

ייבוא מסמכים

/**
 * This snippet has been automatically generated and should be regarded as a code template only.
 * It will require modifications to work.
 * It may require correct/in-range values for request initialization.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  The Inline source for the input content for documents.
 */
// const inlineSource = {}
/**
 *  Cloud Storage location for the input content.
 */
// const gcsSource = {}
/**
 *  BigQuery input source.
 */
// const bigquerySource = {}
/**
 *  FhirStore input source.
 */
// const fhirStoreSource = {}
/**
 *  Spanner input source.
 */
// const spannerSource = {}
/**
 *  Cloud SQL input source.
 */
// const cloudSqlSource = {}
/**
 *  Firestore input source.
 */
// const firestoreSource = {}
/**
 *  AlloyDB input source.
 */
// const alloyDbSource = {}
/**
 *  Cloud Bigtable input source.
 */
// const bigtableSource = {}
/**
 *  Required. The parent branch resource name, such as
 *  `projects/{project}/locations/{location}/collections/{collection}/dataStores/{data_store}/branches/{branch}`.
 *  Requires create/update permission.
 */
// const parent = 'abc123'
/**
 *  The desired location of errors incurred during the Import.
 */
// const errorConfig = {}
/**
 *  The mode of reconciliation between existing documents and the documents to
 *  be imported. Defaults to
 *  ReconciliationMode.INCREMENTAL google.cloud.discoveryengine.v1.ImportDocumentsRequest.ReconciliationMode.INCREMENTAL.
 */
// const reconciliationMode = {}
/**
 *  Indicates which fields in the provided imported documents to update. If
 *  not set, the default is to update all fields.
 */
// const updateMask = {}
/**
 *  Whether to automatically generate IDs for the documents if absent.
 *  If set to `true`,
 *  Document.id google.cloud.discoveryengine.v1.Document.id s are
 *  automatically generated based on the hash of the payload, where IDs may not
 *  be consistent during multiple imports. In which case
 *  ReconciliationMode.FULL google.cloud.discoveryengine.v1.ImportDocumentsRequest.ReconciliationMode.FULL 
 *  is highly recommended to avoid duplicate contents. If unset or set to
 *  `false`, Document.id google.cloud.discoveryengine.v1.Document.id s have
 *  to be specified using
 *  id_field google.cloud.discoveryengine.v1.ImportDocumentsRequest.id_field,
 *  otherwise, documents without IDs fail to be imported.
 *  Supported data sources:
 *  * GcsSource google.cloud.discoveryengine.v1.GcsSource.
 *  GcsSource.data_schema google.cloud.discoveryengine.v1.GcsSource.data_schema 
 *  must be `custom` or `csv`. Otherwise, an INVALID_ARGUMENT error is thrown.
 *  * BigQuerySource google.cloud.discoveryengine.v1.BigQuerySource.
 *  BigQuerySource.data_schema google.cloud.discoveryengine.v1.BigQuerySource.data_schema 
 *  must be `custom` or `csv`. Otherwise, an INVALID_ARGUMENT error is thrown.
 *  * SpannerSource google.cloud.discoveryengine.v1.SpannerSource.
 *  * CloudSqlSource google.cloud.discoveryengine.v1.CloudSqlSource.
 *  * FirestoreSource google.cloud.discoveryengine.v1.FirestoreSource.
 *  * BigtableSource google.cloud.discoveryengine.v1.BigtableSource.
 */
// const autoGenerateIds = true
/**
 *  The field indicates the ID field or column to be used as unique IDs of
 *  the documents.
 *  For GcsSource google.cloud.discoveryengine.v1.GcsSource  it is the key of
 *  the JSON field. For instance, `my_id` for JSON `{"my_id": "some_uuid"}`.
 *  For others, it may be the column name of the table where the unique ids are
 *  stored.
 *  The values of the JSON field or the table column are used as the
 *  Document.id google.cloud.discoveryengine.v1.Document.id s. The JSON field
 *  or the table column must be of string type, and the values must be set as
 *  valid strings conform to RFC-1034 (https://tools.ietf.org/html/rfc1034)
 *  with 1-63 characters. Otherwise, documents without valid IDs fail to be
 *  imported.
 *  Only set this field when
 *  auto_generate_ids google.cloud.discoveryengine.v1.ImportDocumentsRequest.auto_generate_ids 
 *  is unset or set as `false`. Otherwise, an INVALID_ARGUMENT error is thrown.
 *  If it is unset, a default value `_id` is used when importing from the
 *  allowed data sources.
 *  Supported data sources:
 *  * GcsSource google.cloud.discoveryengine.v1.GcsSource.
 *  GcsSource.data_schema google.cloud.discoveryengine.v1.GcsSource.data_schema 
 *  must be `custom` or `csv`. Otherwise, an INVALID_ARGUMENT error is thrown.
 *  * BigQuerySource google.cloud.discoveryengine.v1.BigQuerySource.
 *  BigQuerySource.data_schema google.cloud.discoveryengine.v1.BigQuerySource.data_schema 
 *  must be `custom` or `csv`. Otherwise, an INVALID_ARGUMENT error is thrown.
 *  * SpannerSource google.cloud.discoveryengine.v1.SpannerSource.
 *  * CloudSqlSource google.cloud.discoveryengine.v1.CloudSqlSource.
 *  * FirestoreSource google.cloud.discoveryengine.v1.FirestoreSource.
 *  * BigtableSource google.cloud.discoveryengine.v1.BigtableSource.
 */
// const idField = 'abc123'
/**
 *  Optional. Whether to force refresh the unstructured content of the
 *  documents.
 *  If set to `true`, the content part of the documents will be refreshed
 *  regardless of the update status of the referencing content.
 */
// const forceRefreshContent = true

// Imports the Discoveryengine library
const {DocumentServiceClient} = require('@google-cloud/discoveryengine').v1;

// Instantiates a client
const discoveryengineClient = new DocumentServiceClient();

async function callImportDocuments() {
  // Construct request
  const request = {
    parent,
  };

  // Run request
  const [operation] = await discoveryengineClient.importDocuments(request);
  const [response] = await operation.promise();
  console.log(response);
}

callImportDocuments();

Python

מידע נוסף מופיע בתיעוד העזר של ה-API של חיפוש מבוסס סוכנים Python.

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

יצירת מאגר נתונים


from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"
# location = "YOUR_LOCATION" # Values: "global"
# data_store_id = "YOUR_DATA_STORE_ID"


def create_data_store_sample(
    project_id: str,
    location: str,
    data_store_id: str,
) -> str:
    #  For more information, refer to:
    # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
    client_options = (
        ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
        if location != "global"
        else None
    )

    # Create a client
    client = discoveryengine.DataStoreServiceClient(client_options=client_options)

    # The full resource name of the collection
    # e.g. projects/{project}/locations/{location}/collections/default_collection
    parent = client.collection_path(
        project=project_id,
        location=location,
        collection="default_collection",
    )

    data_store = discoveryengine.DataStore(
        display_name="My Data Store",
        # Options: GENERIC, MEDIA, HEALTHCARE_FHIR
        industry_vertical=discoveryengine.IndustryVertical.GENERIC,
        # Options: SOLUTION_TYPE_RECOMMENDATION, SOLUTION_TYPE_SEARCH, SOLUTION_TYPE_CHAT, SOLUTION_TYPE_GENERATIVE_CHAT
        solution_types=[discoveryengine.SolutionType.SOLUTION_TYPE_SEARCH],
        # TODO(developer): Update content_config based on data store type.
        # Options: NO_CONTENT, CONTENT_REQUIRED, PUBLIC_WEBSITE
        content_config=discoveryengine.DataStore.ContentConfig.CONTENT_REQUIRED,
    )

    request = discoveryengine.CreateDataStoreRequest(
        parent=parent,
        data_store_id=data_store_id,
        data_store=data_store,
        # Optional: For Advanced Site Search Only
        # create_advanced_site_search=True,
    )

    # Make the request
    operation = client.create_data_store(request=request)

    print(f"Waiting for operation to complete: {operation.operation.name}")
    response = operation.result()

    # After the operation is complete,
    # get information from operation metadata
    metadata = discoveryengine.CreateDataStoreMetadata(operation.metadata)

    # Handle the response
    print(response)
    print(metadata)

    return operation.operation.name

ייבוא מסמכים

from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"
# location = "YOUR_LOCATION" # Values: "global"
# data_store_id = "YOUR_DATA_STORE_ID"

# Examples:
# - Unstructured documents
#   - `gs://bucket/directory/file.pdf`
#   - `gs://bucket/directory/*.pdf`
# - Unstructured documents with JSONL Metadata
#   - `gs://bucket/directory/file.json`
# - Unstructured documents with CSV Metadata
#   - `gs://bucket/directory/file.csv`
# gcs_uri = "YOUR_GCS_PATH"

#  For more information, refer to:
# https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
client_options = (
    ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
    if location != "global"
    else None
)

# Create a client
client = discoveryengine.DocumentServiceClient(client_options=client_options)

# The full resource name of the search engine branch.
# e.g. projects/{project}/locations/{location}/dataStores/{data_store_id}/branches/{branch}
parent = client.branch_path(
    project=project_id,
    location=location,
    data_store=data_store_id,
    branch="default_branch",
)

request = discoveryengine.ImportDocumentsRequest(
    parent=parent,
    gcs_source=discoveryengine.GcsSource(
        # Multiple URIs are supported
        input_uris=[gcs_uri],
        # Options:
        # - `content` - Unstructured documents (PDF, HTML, DOC, TXT, PPTX)
        # - `custom` - Unstructured documents with custom JSONL metadata
        # - `document` - Structured documents in the discoveryengine.Document format.
        # - `csv` - Unstructured documents with CSV metadata
        data_schema="content",
    ),
    # Options: `FULL`, `INCREMENTAL`
    reconciliation_mode=discoveryengine.ImportDocumentsRequest.ReconciliationMode.INCREMENTAL,
)

# Make the request
operation = client.import_documents(request=request)

print(f"Waiting for operation to complete: {operation.operation.name}")
response = operation.result()

# After the operation is complete,
# get information from operation metadata
metadata = discoveryengine.ImportDocumentsMetadata(operation.metadata)

# Handle the response
print(response)
print(metadata)

Ruby

מידע נוסף מופיע בתיעוד העזר של ה-API של חיפוש מבוסס סוכנים Ruby.

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

יצירת מאגר נתונים

require "google/cloud/discovery_engine/v1"

##
# Snippet for the create_data_store call in the DataStoreService service
#
# This snippet has been automatically generated and should be regarded as a code
# template only. It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in https://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::DiscoveryEngine::V1::DataStoreService::Client#create_data_store.
#
def create_data_store
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::DiscoveryEngine::V1::DataStoreService::Client.new

  # Create a request. To set request fields, pass in keyword arguments.
  request = Google::Cloud::DiscoveryEngine::V1::CreateDataStoreRequest.new

  # Call the create_data_store method.
  result = client.create_data_store request

  # The returned object is of type Gapic::Operation. You can use it to
  # check the status of an operation, cancel it, or wait for results.
  # Here is how to wait for a response.
  result.wait_until_done! timeout: 60
  if result.response?
    p result.response
  else
    puts "No response received."
  end
end

ייבוא מסמכים

require "google/cloud/discovery_engine/v1"

##
# Snippet for the import_documents call in the DocumentService service
#
# This snippet has been automatically generated and should be regarded as a code
# template only. It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in https://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::DiscoveryEngine::V1::DocumentService::Client#import_documents.
#
def import_documents
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::DiscoveryEngine::V1::DocumentService::Client.new

  # Create a request. To set request fields, pass in keyword arguments.
  request = Google::Cloud::DiscoveryEngine::V1::ImportDocumentsRequest.new

  # Call the import_documents method.
  result = client.import_documents request

  # The returned object is of type Gapic::Operation. You can use it to
  # check the status of an operation, cancel it, or wait for results.
  # Here is how to wait for a response.
  result.wait_until_done! timeout: 60
  if result.response?
    p result.response
  else
    puts "No response received."
  end
end

חיבור ל-Cloud Storage עם סנכרון תקופתי

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

בקטע הבא מוסבר איך ליצור מחבר נתונים שמקשר בין מיקום ב-Cloud Storage לבין מחבר נתונים של Agent Search, ואיך לציין תיקייה או קובץ במיקום הזה בשביל מאגר הנתונים שרוצים ליצור. מאגרי נתונים שהם צאצאים של מחברי נתונים נקראים מאגרי נתונים של ישויות.

הנתונים מסתנכרנים מעת לעת עם מאגר נתוני הישות. אפשר לציין סנכרון יומי, כל שלושה ימים או כל חמישה ימים.

המסוף

  1. נכנסים לדף AI Applications במסוף Google Cloud .

    אפליקציות AI

  2. עוברים לדף מאגרי נתונים.

  3. לוחצים על יצירת מאגר נתונים.

  4. בדף מקור, בוחרים באפשרות Cloud Storage.

  5. בוחרים את סוג הנתונים שמייבאים.

  6. לוחצים על תקופתי.

  7. בוחרים את תדירות הסנכרון, כלומר באיזו תדירות מחבר Agent Search יסנכרן עם המיקום ב-Cloud Storage. אפשר לשנות את התדירות בהמשך.

  8. בקטע בחירת תיקייה או קובץ לייבוא, בוחרים באפשרות תיקייה או קובץ.

  9. לוחצים על עיון, בוחרים את הנתונים שהכנתם להעלאה ולוחצים על בחירה. אפשר גם להזין את המיקום ישירות בשדה gs://.

  10. לוחצים על Continue.

  11. בוחרים אזור למחבר הנתונים.

  12. מזינים שם למחבר הנתונים.

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

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

    שימוש בכלי לניתוח OCR ובכלי לניתוח פריסה עלול לגרור עלויות נוספות. מידע על התמחור של התכונות ב-Document AI

  14. לוחצים על יצירה.

    יצרתם עכשיו מחבר נתונים, שיסנכרן נתונים באופן תקופתי עם המיקום ב-Cloud Storage. יצרתם גם מאגר נתוני ישויות בשם gcs_store.

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

    הכרטיסייה פעילות של הטמעת נתונים. כשהסטטוס בעמודה Data ingestion activity (פעילות של הכנסת נתונים) משתנה מ-In progress (בתהליך) ל-succeeded (הושלם), ההכנסה הראשונה של הנתונים מסתיימת.

    בהתאם לגודל הנתונים, תהליך ההטמעה יכול להימשך כמה דקות עד כמה שעות.

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

השלבים הבאים

התחברות ל-Google Drive

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

לפני שמתחילים

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

  • כדי לקשר את נתוני Google Drive לחיפוש מבוסס סוכנים, צריך להפעיל את התכונות החכמות של Google Workspace במוצרים אחרים של Google. מידע נוסף זמין במאמר הפעלה או השבתה של תכונות חכמות ב-Google Workspace.

מגבלה

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

יצירת מאגר נתונים ב-Google Drive

המסוף

כדי להשתמש במסוף כדי לאפשר חיפוש של נתונים ב-Google Drive, פועלים לפי השלבים הבאים:

  1. נכנסים לדף AI Applications במסוף Google Cloud .

    אפליקציות AI

  2. בתפריט הניווט, לוחצים על מאגרי נתונים.

  3. לוחצים על יצירת מאגר נתונים.

  4. בדף Select a data source (בחירת מקור נתונים), בוחרים באפשרות Google Drive (Google Drive).

  5. מציינים את מקור הנתונים ב-Drive.

    • הכול: כדי להוסיף את כל הכוננים בסביבת העבודה למאגר הנתונים.
    • תיקיות אחסון שיתופי מסוימות: מוסיפים את מזהה התיקייה של האחסון השיתופי.
    • תיקיות משותפות ספציפיות: מוסיפים את המזהה של התיקיות המשותפות.

    כדי למצוא את מזהה התיקייה באחסון השיתופי או מזהה של תיקייה ספציפית, עוברים לתיקיית האחסון השיתופי או לתיקייה ומעתיקים את המזהה מכתובת ה-URL. כתובת ה-URL היא בפורמט הבא: https://drive.google.com/corp/drive/folders/ID.

    לדוגמה, https://drive.google.com/corp/drive/folders/123456789012345678901.

  6. לוחצים על Continue.

  7. בוחרים אזור למאגר הנתונים.

  8. מזינים שם למאגר הנתונים.

  9. אופציונלי: כדי להחריג את הנתונים במאגר הנתונים הזה משימוש בתוכן מבוסס-AI גנרטיבי כשמבצעים שאילתות על נתונים באמצעות האפליקציה, לוחצים על אפשרויות AI גנרטיבי ובוחרים באפשרות החרגה מתכונות מבוססות-AI גנרטיבי.

  10. לוחצים על יצירה.

הודעות שגיאה

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

קוד שגיאה הודעת השגיאה תיאור פתרון בעיות
‫403 (ההרשאה נדחתה) אין תמיכה בחיפוש באמצעות פרטי כניסה של חשבון שירות במאגרי נתונים של Google Workspace. מנוע החיפוש מכיל מאגרי נתונים של Google Workspace, והאישורים שמועברים הם של חשבון שירות. אין תמיכה בחיפוש באמצעות פרטי כניסה של חשבון שירות במאגרי נתונים של Google Workspace. להתקשר לחיפוש באמצעות פרטי הכניסה של המשתמש, או להסיר מאגרי נתונים של Google Workspace מהמנוע.
‫403 (ההרשאה נדחתה) מאגרי נתונים של Google Workspace לא תומכים בחשבונות לשימוש אישי. החיפוש מופעל באמצעות פרטי כניסה של חשבון אישי (‎@gmail.com), שלא נתמכים במאגרי נתונים של Google Workspace. להסיר את מאגרי הנתונים של Google Workspace מהמנוע או להשתמש בחשבון Google מנוהל.
‫403 (ההרשאה נדחתה) מספר הלקוח לא תואם למאגר הנתונים החיפוש מותר רק למשתמשים ששייכים לאותו ארגון כמו מאגרי הנתונים של Google Workspace. מסירים את מאגרי הנתונים של Google Workspace מהמנוע או פונים לתמיכה אם המשתמש ומאגרי הנתונים של Google Workspace אמורים להיות בארגונים שונים.
‫403 (ההרשאה נדחתה) האדמין של הארגון השבית את הגישה של Agentspace ל-Workspace. אדמין ב-Google Workspace השבית את הגישה לנתונים ב-Google Workspace עבור חיפוש מבוסס סוכנים. כדי לקבל גישה, צריך לפנות לאדמין ב-Google Workspace.
‫400 (ארגומנט לא תקין) מנוע לא יכול להכיל גם מאגרי נתונים שמוגדרים כברירת מחדל וגם מאגרי נתונים משותפים ב-Google Drive. אי אפשר לקשר לאותה אפליקציה מאגר נתונים שמכיל את כל הכוננים שלכם (ברירת מחדל) ומאגר נתונים שמכיל תיקיות אחסון שיתופי ספציפיות. כדי לקשר מקור נתונים חדש ב-Google Drive לאפליקציה, קודם צריך לבטל את הקישור של מאגר הנתונים שלא צריך, ואז להוסיף את מאגר הנתונים החדש שרוצים להשתמש בו.

פתרון בעיות

אם החיפוש לא מחזיר את הקובץ שחיפשתם, יכול להיות שזה בגלל אחת מהמגבלות הבאות של אינדקס החיפוש ב-Google Drive:

  • ‫Google Drive מחלץ רק נתונים של טקסט ועיצוב מהקובץ שלכם, עד גודל של 1MB, כדי לאפשר חיפוש בו. אי אפשר לחפש מילות מפתח שחורגות ממגבלת האינדקס של 1MB.

  • ברוב סוגי הקבצים, הגודל המרבי הוא 10MB. אלה החריגים:

    • קבצי XLSX ‏ (.xlsx) לא יכולים לחרוג מ-20MB.

    • קבצי PDF ‏ (.pdf) לא יכולים להיות גדולים מ-30MB.

    • הגודל המקסימלי של קובצי טקסט (‎.txt) הוא 100MB.

  • זיהוי תווים אופטי (OCR) בקובצי PDF מוגבל ל-80 עמודים. ‫Google Drive לא מוסיף לאינדקס קובצי PDF שגדולים מ-50MB או מכילים יותר מ-80 דפים.

השלבים הבאים

התחברות לחשבון Gmail

כדי ליצור מאגר נתונים שמתחבר ל-Gmail ב Google Cloud מסוף: אחרי שמקשרים את מאגר הנתונים, אפשר לצרף אותו לאפליקציית החיפוש ולחפש בנתונים מ-Gmail.

לפני שמתחילים

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

מגבלות

יצירת מאגר נתונים ב-Gmail

המסוף

כדי להשתמש במסוף כדי לאפשר חיפוש בנתוני Gmail, צריך לבצע את השלבים הבאים:

  1. נכנסים לדף AI Applications במסוף Google Cloud .

    אפליקציות AI

  2. בתפריט הניווט, לוחצים על מאגרי נתונים.

  3. לוחצים על יצירת מאגר נתונים.

  4. בדף Select a data source (בחירת מקור נתונים), בוחרים באפשרות Google Gmail (גוגל Gmail).

  5. בוחרים אזור למאגר הנתונים.

  6. מזינים שם למאגר הנתונים.

  7. לוחצים על יצירה.

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

הודעות שגיאה

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

קוד שגיאה הודעת השגיאה תיאור פתרון בעיות
‫403 (ההרשאה נדחתה) אין תמיכה בחיפוש באמצעות פרטי כניסה של חשבון שירות במאגרי נתונים של Google Workspace. מנוע החיפוש מכיל מאגרי נתונים של Google Workspace, והאישורים שמועברים הם של חשבון שירות. אין תמיכה בחיפוש באמצעות פרטי כניסה של חשבון שירות במאגרי נתונים של Google Workspace. להתקשר לחיפוש באמצעות פרטי הכניסה של המשתמש, או להסיר מאגרי נתונים של Google Workspace מהמנוע.
‫403 (ההרשאה נדחתה) מאגרי נתונים של Google Workspace לא תומכים בחשבונות לשימוש אישי. החיפוש מופעל באמצעות פרטי כניסה של חשבון אישי (‎@gmail.com), שלא נתמכים במאגרי נתונים של Google Workspace. להסיר את מאגרי הנתונים של Google Workspace מהמנוע או להשתמש בחשבון Google מנוהל.
‫403 (ההרשאה נדחתה) מספר הלקוח לא תואם למאגר הנתונים החיפוש מותר רק למשתמשים ששייכים לאותו ארגון כמו מאגרי הנתונים של Google Workspace. מסירים את מאגרי הנתונים של Google Workspace מהמנוע או פונים לתמיכה אם המשתמש ומאגרי הנתונים של Google Workspace אמורים להיות בארגונים שונים.
‫403 (ההרשאה נדחתה) האדמין של הארגון השבית את הגישה של Agentspace ל-Workspace. אדמין ב-Google Workspace השבית את הגישה לנתונים ב-Google Workspace עבור חיפוש מבוסס סוכנים. כדי לקבל גישה, צריך לפנות לאדמין ב-Google Workspace.
‫400 (ארגומנט לא תקין) מנוע לא יכול להכיל גם מאגרי נתונים שמוגדרים כברירת מחדל וגם מאגרי נתונים משותפים ב-Google Drive. אי אפשר לקשר לאותה אפליקציה מאגר נתונים שמכיל את כל הכוננים שלכם (ברירת מחדל) ומאגר נתונים שמכיל תיקיות אחסון שיתופי ספציפיות. כדי לקשר מקור נתונים חדש ב-Google Drive לאפליקציה, קודם צריך לבטל את הקישור של מאגר הנתונים שלא צריך, ואז להוסיף את מאגר הנתונים החדש שרוצים להשתמש בו.

השלבים הבאים

קישור ל-Google Sites

כדי לחפש נתונים מ-Google Sites, צריך ליצור מחבר באמצעות מסוף Google Cloud .

לפני שמתחילים:

  • אתם צריכים להיכנס למסוף Google Cloud באמצעות אותו חשבון שבו אתם משתמשים במופע של Google Workspace שאתם מתכננים לחבר. חיפוש מבוסס סוכנים משתמש במזהה הלקוח שלכם ב-Google Workspace כדי להתחבר ל-Google Sites.

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

המסוף

כדי להשתמש במסוף כדי לאפשר חיפוש של נתונים ב-Google Sites, פועלים לפי השלבים הבאים:

  1. נכנסים לדף AI Applications במסוף Google Cloud .

    אפליקציות AI

  2. עוברים לדף מאגרי נתונים.

  3. לוחצים על מאגר נתונים חדש.

  4. בדף מקור, בוחרים באפשרות Google Sites.

  5. בוחרים אזור למאגר הנתונים.

  6. מזינים שם למאגר הנתונים.

  7. לוחצים על יצירה.

השלבים הבאים

קישור ליומן Google

כדי לחפש נתונים מיומן Google, צריך ליצור מאגר נתונים באמצעות מסוף Google Cloud .

לפני שמתחילים

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

יצירת מאגר נתונים ביומן Google

כדי להשתמש במסוף כדי לאפשר חיפוש של נתונים ביומן Google, פועלים לפי השלבים הבאים:

  1. נכנסים לדף AI Applications במסוף Google Cloud .

    אפליקציות AI

  2. בתפריט הניווט, לוחצים על מאגרי נתונים.

  3. לוחצים על יצירת מאגר נתונים.

  4. בדף Select a data source, בוחרים באפשרות יומן Google.

  5. בוחרים אזור למאגר הנתונים.

  6. מזינים שם למאגר הנתונים.

  7. לוחצים על יצירה.

הודעות שגיאה

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

קוד שגיאה הודעת השגיאה תיאור פתרון בעיות
‫403 (ההרשאה נדחתה) אין תמיכה בחיפוש באמצעות פרטי כניסה של חשבון שירות במאגרי נתונים של Google Workspace. מנוע החיפוש מכיל מאגרי נתונים של Google Workspace, והאישורים שמועברים הם של חשבון שירות. אין תמיכה בחיפוש באמצעות פרטי כניסה של חשבון שירות במאגרי נתונים של Google Workspace. להתקשר לחיפוש באמצעות פרטי הכניסה של המשתמש, או להסיר מאגרי נתונים של Google Workspace מהמנוע.
‫403 (ההרשאה נדחתה) מאגרי נתונים של Google Workspace לא תומכים בחשבונות לשימוש אישי. החיפוש מופעל באמצעות פרטי כניסה של חשבון אישי (‎@gmail.com), שלא נתמכים במאגרי נתונים של Google Workspace. להסיר את מאגרי הנתונים של Google Workspace מהמנוע או להשתמש בחשבון Google מנוהל.
‫403 (ההרשאה נדחתה) מספר הלקוח לא תואם למאגר הנתונים החיפוש מותר רק למשתמשים ששייכים לאותו ארגון כמו מאגרי הנתונים של Google Workspace. מסירים את מאגרי הנתונים של Google Workspace מהמנוע או פונים לתמיכה אם המשתמש ומאגרי הנתונים של Google Workspace אמורים להיות בארגונים שונים.
‫403 (ההרשאה נדחתה) האדמין של הארגון השבית את הגישה של Agentspace ל-Workspace. אדמין ב-Google Workspace השבית את הגישה לנתונים ב-Google Workspace עבור חיפוש מבוסס סוכנים. כדי לקבל גישה, צריך לפנות לאדמין ב-Google Workspace.
‫400 (ארגומנט לא תקין) מנוע לא יכול להכיל גם מאגרי נתונים שמוגדרים כברירת מחדל וגם מאגרי נתונים משותפים ב-Google Drive. אי אפשר לקשר לאותה אפליקציה מאגר נתונים שמכיל את כל הכוננים שלכם (ברירת מחדל) ומאגר נתונים שמכיל תיקיות אחסון שיתופי ספציפיות. כדי לקשר מקור נתונים חדש ב-Google Drive לאפליקציה, קודם צריך לבטל את הקישור של מאגר הנתונים שלא צריך, ואז להוסיף את מאגר הנתונים החדש שרוצים להשתמש בו.

השלבים הבאים

חיבור לקבוצות Google

כדי לחפש נתונים מ-Google Groups, צריך ליצור מחבר באמצעות מסוף Google Cloud .

לפני שמתחילים:

  • אתם צריכים להיכנס למסוף Google Cloud באמצעות אותו חשבון שבו אתם משתמשים במופע של Google Workspace שאתם מתכננים לחבר. חיפוש מבוסס סוכנים משתמש במזהה הלקוח שלכם ב-Google Workspace כדי להתחבר לקבוצות Google.

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

המסוף

כדי להשתמש במסוף כדי לאפשר חיפוש של נתונים בקבוצות Google, פועלים לפי השלבים הבאים:

  1. נכנסים לדף AI Applications במסוף Google Cloud .

    אפליקציות AI

  2. עוברים לדף מאגרי נתונים.

  3. לוחצים על מאגר נתונים חדש.

  4. בדף מקור, בוחרים באפשרות קבוצות Google.

  5. בוחרים אזור למאגר הנתונים.

  6. מזינים שם למאגר הנתונים.

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

השלבים הבאים

ייבוא מ-Cloud SQL

כדי להטמיע נתונים מ-Cloud SQL, צריך לבצע את השלבים הבאים כדי להגדיר גישה ל-Cloud SQL, ליצור מאגר נתונים ולהטמיע נתונים.

הגדרת גישה לקטגוריית אחסון זמנית למופעים של Cloud SQL

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

  1. נכנסים לדף SQL במסוף Google Cloud .

    SQL

  2. לוחצים על המכונה של Cloud SQL שממנה רוצים לייבא.

  3. מעתיקים את המזהה של חשבון השירות של המופע, שנראה כמו כתובת אימייל – לדוגמה, p9876-abcd33f@gcp-sa-cloud-sql.iam.gserviceaccount.com.

  4. עוברים לדף IAM & Admin.

    IAM & Admin

  5. לוחצים על הענקת גישה.

  6. בשדה New principals (חשבונות משתמשים חדשים), מזינים את המזהה של חשבון השירות של המופע ובוחרים בתפקיד Cloud Storage > Storage Admin.

  7. לוחצים על Save.

השלב הבא:

הגדרת גישה ל-Cloud SQL מפרויקט אחר

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

  1. מחליפים את המשתנה PROJECT_NUMBER במספר הפרויקט שלכם ב-חיפוש מבוסס סוכנים, ואז מעתיקים את התוכן של בלוק הקוד. זה המזהה של חשבון השירות של חיפוש מבוסס סוכנים שלך:

    service-PROJECT_NUMBER@gcp-sa-discoveryengine.iam.gserviceaccount.com`
    
  2. עוברים לדף IAM & Admin.

    IAM & Admin

  3. עוברים לפרויקט Cloud SQL בדף IAM & Admin ולוחצים על Grant Access.

  4. בשדה New principals (חשבונות משתמשים חדשים), מזינים את המזהה של חשבון השירות ובוחרים בתפקיד Cloud SQL > Cloud SQL Viewer.

  5. לוחצים על Save.

לאחר מכן, עוברים אל ייבוא נתונים מ-Cloud SQL.

ייבוא נתונים מ-Cloud SQL

המסוף

כדי להשתמש במסוף להעברת נתונים מ-Cloud SQL, פועלים לפי השלבים הבאים:

  1. נכנסים לדף AI Applications במסוף Google Cloud .

    אפליקציות AI

  2. עוברים לדף מאגרי נתונים.

  3. לוחצים על מאגר נתונים חדש.

  4. בדף Source, בוחרים באפשרות Cloud SQL.

  5. מציינים את מזהה הפרויקט, מזהה המכונה, מזהה מסד הנתונים ומזהה הטבלה של הנתונים שרוצים לייבא.

  6. לוחצים על Browse, בוחרים מיקום ביניים ב-Cloud Storage לייצוא הנתונים ולוחצים על Select. אפשר גם להזין את המיקום ישירות בשדה gs://.

  7. בוחרים אם להפעיל ייצוא ללא שרת. ייצוא בלי שרת (serverless) כרוך בעלות נוספת. מידע על ייצוא בלי שרת (serverless) זמין במאמר מזעור ההשפעה של הייצוא על הביצועים במאמרי העזרה של Cloud SQL.

  8. לוחצים על Continue.

  9. בוחרים אזור למאגר הנתונים.

  10. מזינים שם למאגר הנתונים.

  11. לוחצים על יצירה.

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

    בהתאם לגודל הנתונים, תהליך ההטמעה יכול להימשך כמה דקות או כמה שעות.

REST

כדי להשתמש בשורת הפקודה כדי ליצור מאגר נתונים ולהטמיע נתונים מ-Cloud SQL, פועלים לפי השלבים הבאים:

  1. יוצרים מאגר נתונים.

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    -H "X-Goog-User-Project: PROJECT_ID" \
    "https://discoveryengine.googleapis.com/v1alpha/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores?dataStoreId=DATA_STORE_ID" \
    -d '{
      "displayName": "DISPLAY_NAME",
      "industryVertical": "GENERIC",
      "solutionTypes": ["SOLUTION_TYPE_SEARCH"],
    }'
    

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

    • PROJECT_ID: מזהה הפרויקט.
    • DATA_STORE_ID: המזהה של מאגר הנתונים. המזהה יכול להכיל רק אותיות קטנות, ספרות, קווים תחתונים ומקפים.
    • DISPLAY_NAME: השם המוצג של מאגר הנתונים. יכול להיות שההודעה תוצג במסוף. Google Cloud
  2. ייבוא נתונים מ-Cloud SQL.

      curl -X POST \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/branches/0/documents:import" \
      -d '{
        "cloudSqlSource": {
          "projectId": "SQL_PROJECT_ID",
          "instanceId": "INSTANCE_ID",
          "databaseId": "DATABASE_ID",
          "tableId": "TABLE_ID",
          "gcsStagingDir": "STAGING_DIRECTORY"
        },
        "reconciliationMode": "RECONCILIATION_MODE",
        "autoGenerateIds": "AUTO_GENERATE_IDS",
        "idField": "ID_FIELD",
      }'
    

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

    • PROJECT_ID: מזהה הפרויקט של חיפוש מבוסס סוכנים.
    • DATA_STORE_ID: המזהה של מאגר הנתונים. המזהה יכול להכיל רק אותיות קטנות, ספרות, קווים תחתונים ומקפים.
    • SQL_PROJECT_ID: מזהה הפרויקט ב-Cloud SQL.
    • INSTANCE_ID: המזהה של מופע Cloud SQL.
    • DATABASE_ID: המזהה של מסד הנתונים של Cloud SQL.
    • TABLE_ID: המזהה של טבלת Cloud SQL.
    • STAGING_DIRECTORY: אופציונלי. ספרייה ב-Cloud Storage – לדוגמה, gs://<your-gcs-bucket>/directory/import_errors.
    • RECONCILIATION_MODE: אופציונלי. הערכים הם FULL ו-INCREMENTAL. ערך ברירת המחדל הוא INCREMENTAL. הגדרה של INCREMENTAL גורמת לרענון מצטבר של נתונים מ-Cloud SQL למאגר הנתונים. הפעולה הזו מבצעת upsert, שמוסיפה מסמכים חדשים ומחליפה מסמכים קיימים במסמכים מעודכנים עם אותו מזהה. אם מציינים FULL, מתבצעת התאמה מלאה של המסמכים במאגר הנתונים. במילים אחרות, מסמכים חדשים ומעודכנים מתווספים למאגר הנתונים, ומסמכים שלא נמצאים ב-Cloud SQL מוסרים ממנו. מצב FULL שימושי אם רוצים למחוק באופן אוטומטי מסמכים שכבר לא צריכים.

Python

מידע נוסף מופיע בתיעוד העזר של ה-API של חיפוש מבוסס סוכנים Python.

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

יצירת מאגר נתונים


from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"
# location = "YOUR_LOCATION" # Values: "global"
# data_store_id = "YOUR_DATA_STORE_ID"


def create_data_store_sample(
    project_id: str,
    location: str,
    data_store_id: str,
) -> str:
    #  For more information, refer to:
    # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
    client_options = (
        ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
        if location != "global"
        else None
    )

    # Create a client
    client = discoveryengine.DataStoreServiceClient(client_options=client_options)

    # The full resource name of the collection
    # e.g. projects/{project}/locations/{location}/collections/default_collection
    parent = client.collection_path(
        project=project_id,
        location=location,
        collection="default_collection",
    )

    data_store = discoveryengine.DataStore(
        display_name="My Data Store",
        # Options: GENERIC, MEDIA, HEALTHCARE_FHIR
        industry_vertical=discoveryengine.IndustryVertical.GENERIC,
        # Options: SOLUTION_TYPE_RECOMMENDATION, SOLUTION_TYPE_SEARCH, SOLUTION_TYPE_CHAT, SOLUTION_TYPE_GENERATIVE_CHAT
        solution_types=[discoveryengine.SolutionType.SOLUTION_TYPE_SEARCH],
        # TODO(developer): Update content_config based on data store type.
        # Options: NO_CONTENT, CONTENT_REQUIRED, PUBLIC_WEBSITE
        content_config=discoveryengine.DataStore.ContentConfig.CONTENT_REQUIRED,
    )

    request = discoveryengine.CreateDataStoreRequest(
        parent=parent,
        data_store_id=data_store_id,
        data_store=data_store,
        # Optional: For Advanced Site Search Only
        # create_advanced_site_search=True,
    )

    # Make the request
    operation = client.create_data_store(request=request)

    print(f"Waiting for operation to complete: {operation.operation.name}")
    response = operation.result()

    # After the operation is complete,
    # get information from operation metadata
    metadata = discoveryengine.CreateDataStoreMetadata(operation.metadata)

    # Handle the response
    print(response)
    print(metadata)

    return operation.operation.name

ייבוא מסמכים

from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"
# location = "YOUR_LOCATION" # Values: "global"
# data_store_id = "YOUR_DATA_STORE_ID"
# sql_project_id = "YOUR_SQL_PROJECT_ID"
# sql_instance_id = "YOUR_SQL_INSTANCE_ID"
# sql_database_id = "YOUR_SQL_DATABASE_ID"
# sql_table_id = "YOUR_SQL_TABLE_ID"

#  For more information, refer to:
# https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
client_options = (
    ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
    if location != "global"
    else None
)

# Create a client
client = discoveryengine.DocumentServiceClient(client_options=client_options)

# The full resource name of the search engine branch.
# e.g. projects/{project}/locations/{location}/dataStores/{data_store_id}/branches/{branch}
parent = client.branch_path(
    project=project_id,
    location=location,
    data_store=data_store_id,
    branch="default_branch",
)

request = discoveryengine.ImportDocumentsRequest(
    parent=parent,
    cloud_sql_source=discoveryengine.CloudSqlSource(
        project_id=sql_project_id,
        instance_id=sql_instance_id,
        database_id=sql_database_id,
        table_id=sql_table_id,
    ),
    # Options: `FULL`, `INCREMENTAL`
    reconciliation_mode=discoveryengine.ImportDocumentsRequest.ReconciliationMode.INCREMENTAL,
)

# Make the request
operation = client.import_documents(request=request)

print(f"Waiting for operation to complete: {operation.operation.name}")
response = operation.result()

# After the operation is complete,
# get information from operation metadata
metadata = discoveryengine.ImportDocumentsMetadata(operation.metadata)

# Handle the response
print(response)
print(metadata)

השלבים הבאים

ייבוא מ-Spanner

כדי להטמיע נתונים מ-Spanner, צריך ליצור מאגר נתונים ולהטמיע נתונים באמצעות Google Cloud המסוף או ה-API.

הגדרת גישה ל-Spanner מפרויקט אחר

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

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

  1. מחליפים את המשתנה PROJECT_NUMBER במספר הפרויקט שלכם ב-חיפוש מבוסס סוכנים, ואז מעתיקים את התוכן של בלוק הקוד הזה. זה המזהה של חשבון השירות של חיפוש מבוסס סוכנים שלך:

    service-PROJECT_NUMBER@gcp-sa-discoveryengine.iam.gserviceaccount.com
    
  2. עוברים לדף IAM & Admin.

    IAM & Admin

  3. עוברים לפרויקט Spanner בדף IAM ואדמין ולוחצים על הענקת גישה.

  4. בשדה New principals (חשבונות משתמשים חדשים), מזינים את המזהה של חשבון השירות ובוחרים באחת מהאפשרויות הבאות:

    • אם לא תשתמשו ב-Data Boost במהלך הייבוא, תצטרכו לבחור בתפקיד Cloud Spanner > Cloud Spanner Database Reader.
    • אם אתם מתכננים להשתמש בהגדלת נפח הנתונים במהלך הייבוא, צריך לבחור בתפקיד Cloud Spanner > Cloud Spanner Database Admin או בתפקיד מותאם אישית עם ההרשאות Cloud Spanner Database Reader ו-spanner.databases.useDataBoost. מידע על Data Boost זמין במאמר סקירה כללית על Data Boost במסמכי Spanner.
  5. לוחצים על Save.

לאחר מכן, עוברים אל ייבוא נתונים מ-Spanner.

ייבוא נתונים מ-Spanner

המסוף

כדי להשתמש במסוף להעברת נתונים מ-Spanner, פועלים לפי השלבים הבאים:

  1. נכנסים לדף AI Applications במסוף Google Cloud .

    אפליקציות AI

  2. עוברים לדף מאגרי נתונים.

  3. לוחצים על מאגר נתונים חדש.

  4. בדף מקור, בוחרים באפשרות Cloud Spanner.

  5. מציינים את מזהה הפרויקט, מזהה המכונה, מזהה מסד הנתונים ומזהה הטבלה של הנתונים שרוצים לייבא.

  6. בוחרים אם להפעיל את התכונה 'הגדלת נפח הנתונים'. מידע על Data Boost זמין במאמר סקירה כללית על Data Boost במסמכי התיעוד של Spanner.

  7. לוחצים על Continue.

  8. בוחרים אזור למאגר הנתונים.

  9. מזינים שם למאגר הנתונים.

  10. לוחצים על יצירה.

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

    בהתאם לגודל הנתונים, תהליך ההטמעה יכול להימשך כמה דקות או כמה שעות.

REST

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

  1. יוצרים מאגר נתונים.

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    -H "X-Goog-User-Project: PROJECT_ID" \
    "https://discoveryengine.googleapis.com/v1alpha/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores?dataStoreId=DATA_STORE_ID" \
    -d '{
      "displayName": "DISPLAY_NAME",
      "industryVertical": "GENERIC",
      "solutionTypes": ["SOLUTION_TYPE_SEARCH"],
      "contentConfig": "CONTENT_REQUIRED",
    }'
    

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

    • PROJECT_ID: מזהה הפרויקט של חיפוש מבוסס סוכנים.
    • DATA_STORE_ID: המזהה של מאגר הנתונים. המזהה יכול להכיל רק אותיות קטנות, ספרות, קווים תחתונים ומקפים.
    • DISPLAY_NAME: השם המוצג של מאגר הנתונים. יכול להיות שההודעה תוצג במסוף. Google Cloud
  2. ייבוא נתונים מ-Spanner.

      curl -X POST \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/branches/0/documents:import" \
      -d '{
        "cloudSpannerSource": {
          "projectId": "SPANNER_PROJECT_ID",
          "instanceId": "INSTANCE_ID",
          "databaseId": "DATABASE_ID",
          "tableId": "TABLE_ID",
          "enableDataBoost": "DATA_BOOST_BOOLEAN"
        },
        "reconciliationMode": "RECONCILIATION_MODE",
        "autoGenerateIds": "AUTO_GENERATE_IDS",
        "idField": "ID_FIELD",
      }'
    

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

    • PROJECT_ID: מזהה הפרויקט של חיפוש מבוסס סוכנים.
    • DATA_STORE_ID: המזהה של מאגר הנתונים.
    • SPANNER_PROJECT_ID: המזהה של פרויקט Spanner.
    • INSTANCE_ID: המזהה של מכונת Spanner.
    • DATABASE_ID: המזהה של מסד הנתונים של Spanner.
    • TABLE_ID: המזהה של טבלת Spanner.
    • DATA_BOOST_BOOLEAN: אופציונלי. האם להפעיל את Data Boost. מידע על Data Boost זמין במאמר סקירה כללית על Data Boost במאמרי העזרה של Spanner.
    • RECONCILIATION_MODE: אופציונלי. הערכים הם FULL ו-INCREMENTAL. ערך ברירת המחדל הוא INCREMENTAL. הגדרה של INCREMENTAL גורמת לרענון מצטבר של נתונים מ-Spanner למאגר הנתונים. הפעולה הזו היא פעולת upsert, שמוסיפה מסמכים חדשים ומחליפה מסמכים קיימים במסמכים מעודכנים עם אותו מזהה. ציון הערך FULL גורם לביצוע rebase מלא של המסמכים במאגר הנתונים. במילים אחרות, מסמכים חדשים ומעודכנים מתווספים למאגר הנתונים, ומסמכים שלא נמצאים ב-Spanner מוסרים ממנו. השימוש במצב FULL מועיל אם רוצים למחוק באופן אוטומטי מסמכים שכבר לא צריכים.
    • AUTO_GENERATE_IDS: אופציונלי. ההגדרה קובעת אם מזהי המסמכים ייווצרו באופן אוטומטי. אם המדיניות מוגדרת לערך true, מזהי המסמכים נוצרים על סמך גיבוב של מטען הייעודי. חשוב לדעת שמזהי מסמכים שנוצרו יכולים להשתנות בין ייבוא לייבוא. אם אתם יוצרים מזהים באופן אוטומטי בכמה ייבואים, מומלץ מאוד להגדיר את reconciliationMode ל-FULL כדי לשמור על מזהי מסמכים עקביים.

    • ID_FIELD: אופציונלי. מציינים אילו שדות הם מזהי המסמכים.

Python

מידע נוסף מופיע בתיעוד העזר של ה-API של חיפוש מבוסס סוכנים Python.

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

יצירת מאגר נתונים


from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"
# location = "YOUR_LOCATION" # Values: "global"
# data_store_id = "YOUR_DATA_STORE_ID"


def create_data_store_sample(
    project_id: str,
    location: str,
    data_store_id: str,
) -> str:
    #  For more information, refer to:
    # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
    client_options = (
        ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
        if location != "global"
        else None
    )

    # Create a client
    client = discoveryengine.DataStoreServiceClient(client_options=client_options)

    # The full resource name of the collection
    # e.g. projects/{project}/locations/{location}/collections/default_collection
    parent = client.collection_path(
        project=project_id,
        location=location,
        collection="default_collection",
    )

    data_store = discoveryengine.DataStore(
        display_name="My Data Store",
        # Options: GENERIC, MEDIA, HEALTHCARE_FHIR
        industry_vertical=discoveryengine.IndustryVertical.GENERIC,
        # Options: SOLUTION_TYPE_RECOMMENDATION, SOLUTION_TYPE_SEARCH, SOLUTION_TYPE_CHAT, SOLUTION_TYPE_GENERATIVE_CHAT
        solution_types=[discoveryengine.SolutionType.SOLUTION_TYPE_SEARCH],
        # TODO(developer): Update content_config based on data store type.
        # Options: NO_CONTENT, CONTENT_REQUIRED, PUBLIC_WEBSITE
        content_config=discoveryengine.DataStore.ContentConfig.CONTENT_REQUIRED,
    )

    request = discoveryengine.CreateDataStoreRequest(
        parent=parent,
        data_store_id=data_store_id,
        data_store=data_store,
        # Optional: For Advanced Site Search Only
        # create_advanced_site_search=True,
    )

    # Make the request
    operation = client.create_data_store(request=request)

    print(f"Waiting for operation to complete: {operation.operation.name}")
    response = operation.result()

    # After the operation is complete,
    # get information from operation metadata
    metadata = discoveryengine.CreateDataStoreMetadata(operation.metadata)

    # Handle the response
    print(response)
    print(metadata)

    return operation.operation.name

ייבוא מסמכים

from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"
# location = "YOUR_LOCATION" # Values: "global"
# data_store_id = "YOUR_DATA_STORE_ID"
# spanner_project_id = "YOUR_SPANNER_PROJECT_ID"
# spanner_instance_id = "YOUR_SPANNER_INSTANCE_ID"
# spanner_database_id = "YOUR_SPANNER_DATABASE_ID"
# spanner_table_id = "YOUR_SPANNER_TABLE_ID"

#  For more information, refer to:
# https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
client_options = (
    ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
    if location != "global"
    else None
)

# Create a client
client = discoveryengine.DocumentServiceClient(client_options=client_options)

# The full resource name of the search engine branch.
# e.g. projects/{project}/locations/{location}/dataStores/{data_store_id}/branches/{branch}
parent = client.branch_path(
    project=project_id,
    location=location,
    data_store=data_store_id,
    branch="default_branch",
)

request = discoveryengine.ImportDocumentsRequest(
    parent=parent,
    spanner_source=discoveryengine.SpannerSource(
        project_id=spanner_project_id,
        instance_id=spanner_instance_id,
        database_id=spanner_database_id,
        table_id=spanner_table_id,
    ),
    # Options: `FULL`, `INCREMENTAL`
    reconciliation_mode=discoveryengine.ImportDocumentsRequest.ReconciliationMode.INCREMENTAL,
)

# Make the request
operation = client.import_documents(request=request)

print(f"Waiting for operation to complete: {operation.operation.name}")
response = operation.result()

# After the operation is complete,
# get information from operation metadata
metadata = discoveryengine.ImportDocumentsMetadata(operation.metadata)

# Handle the response
print(response)
print(metadata)

השלבים הבאים

ייבוא מ-Firestore

כדי להטמיע נתונים מ-Firestore, צריך ליצור מאגר נתונים ולהטמיע נתונים באמצעות Google Cloud המסוף או ה-API.

אם נתוני Firestore נמצאים באותו פרויקט כמו חיפוש מבוסס סוכנים, עוברים אל ייבוא נתונים מ-Firestore.

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

הגדרת גישה ל-Firestore מפרויקט אחר

כדי להעניק ל-Agent Search גישה לנתוני Firestore שנמצאים בפרויקט אחר, פועלים לפי השלבים הבאים:

  1. מחליפים את המשתנה PROJECT_NUMBER במספר הפרויקט שלכם ב-חיפוש מבוסס סוכנים, ואז מעתיקים את התוכן של בלוק הקוד הזה. זה המזהה של חשבון השירות של חיפוש מבוסס סוכנים שלך:

    service-PROJECT_NUMBER@gcp-sa-discoveryengine.iam.gserviceaccount.com
    
  2. עוברים לדף IAM & Admin.

    IAM & Admin

  3. עוברים לפרויקט Firestore בדף IAM ואדמין ולוחצים על הענקת גישה.

  4. בשדה New principals (חשבונות משתמשים חדשים), מזינים את המזהה של חשבון השירות של המופע ובוחרים בתפקיד Datastore > Cloud Datastore Import Export Admin.

  5. לוחצים על Save.

  6. חוזרים לפרויקט חיפוש מבוסס סוכנים.

אחר כך עוברים אל ייבוא נתונים מ-Firestore.

ייבוא נתונים מ-Firestore

המסוף

כדי להטמיע נתונים מ-Firestore באמצעות המסוף, פועלים לפי השלבים הבאים:

  1. נכנסים לדף AI Applications במסוף Google Cloud .

    אפליקציות AI

  2. עוברים לדף מאגרי נתונים.

  3. לוחצים על מאגר נתונים חדש.

  4. בדף Source, בוחרים באפשרות Firestore.

  5. מציינים את מזהה הפרויקט, מזהה מסד הנתונים ומזהה האוסף של הנתונים שרוצים לייבא.

  6. לוחצים על Continue.

  7. בוחרים אזור למאגר הנתונים.

  8. מזינים שם למאגר הנתונים.

  9. לוחצים על יצירה.

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

    בהתאם לגודל הנתונים, תהליך ההטמעה יכול להימשך כמה דקות או כמה שעות.

REST

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

  1. יוצרים מאגר נתונים.

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    -H "X-Goog-User-Project: PROJECT_ID" \
    "https://discoveryengine.googleapis.com/v1alpha/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores?dataStoreId=DATA_STORE_ID" \
    -d '{
      "displayName": "DISPLAY_NAME",
      "industryVertical": "GENERIC",
      "solutionTypes": ["SOLUTION_TYPE_SEARCH"],
    }'
    

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

    • PROJECT_ID: מזהה הפרויקט.
    • DATA_STORE_ID: המזהה של מאגר הנתונים. המזהה יכול להכיל רק אותיות קטנות, ספרות, קווים תחתונים ומקפים.
    • DISPLAY_NAME: השם המוצג של מאגר הנתונים. יכול להיות שההודעה תוצג במסוף. Google Cloud
  2. ייבוא נתונים מ-Firestore.

      curl -X POST \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/branches/0/documents:import" \
      -d '{
        "firestoreSource": {
          "projectId": "FIRESTORE_PROJECT_ID",
          "databaseId": "DATABASE_ID",
          "collectionId": "COLLECTION_ID",
        },
        "reconciliationMode": "RECONCILIATION_MODE",
        "autoGenerateIds": "AUTO_GENERATE_IDS",
        "idField": "ID_FIELD",
      }'
    

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

    • PROJECT_ID: מזהה הפרויקט של חיפוש מבוסס סוכנים.
    • DATA_STORE_ID: המזהה של מאגר הנתונים. המזהה יכול להכיל רק אותיות קטנות, ספרות, קווים תחתונים ומקפים.
    • FIRESTORE_PROJECT_ID: המזהה של פרויקט Firestore.
    • DATABASE_ID: המזהה של מסד הנתונים שלכם ב-Firestore.
    • COLLECTION_ID: המזהה של האוסף ב-Firestore.
    • RECONCILIATION_MODE: אופציונלי. הערכים הם FULL ו-INCREMENTAL. ערך ברירת המחדל הוא INCREMENTAL. ציון של INCREMENTAL גורם לרענון מצטבר של נתונים מ-Firestore אל מאגר הנתונים שלכם. הפעולה הזו מבצעת upsert, שמוסיפה מסמכים חדשים ומחליפה מסמכים קיימים במסמכים מעודכנים עם אותו מזהה. אם מציינים FULL, מתבצעת התאמה מלאה של המסמכים במאגר הנתונים. במילים אחרות, מסמכים חדשים ומעודכנים מתווספים למאגר הנתונים, ומסמכים שלא נמצאים ב-Firestore מוסרים ממאגר הנתונים. מצב FULL שימושי אם רוצים למחוק באופן אוטומטי מסמכים שכבר לא צריכים.
    • AUTO_GENERATE_IDS: אופציונלי. ההגדרה קובעת אם מזהי המסמכים ייווצרו באופן אוטומטי. אם המדיניות מוגדרת לערך true, מזהי המסמכים נוצרים על סמך גיבוב של מטען הייעודי. חשוב לדעת שמזהי מסמכים שנוצרו יכולים להשתנות בין ייבוא לייבוא. אם אתם יוצרים מזהים באופן אוטומטי בכמה ייבואים, מומלץ מאוד להגדיר את reconciliationMode ל-FULL כדי לשמור על מזהי מסמכים עקביים.
    • ID_FIELD: אופציונלי. מציינים אילו שדות הם מזהי המסמכים.

Python

מידע נוסף מופיע בתיעוד העזר של ה-API של חיפוש מבוסס סוכנים Python.

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

יצירת מאגר נתונים


from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"
# location = "YOUR_LOCATION" # Values: "global"
# data_store_id = "YOUR_DATA_STORE_ID"


def create_data_store_sample(
    project_id: str,
    location: str,
    data_store_id: str,
) -> str:
    #  For more information, refer to:
    # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
    client_options = (
        ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
        if location != "global"
        else None
    )

    # Create a client
    client = discoveryengine.DataStoreServiceClient(client_options=client_options)

    # The full resource name of the collection
    # e.g. projects/{project}/locations/{location}/collections/default_collection
    parent = client.collection_path(
        project=project_id,
        location=location,
        collection="default_collection",
    )

    data_store = discoveryengine.DataStore(
        display_name="My Data Store",
        # Options: GENERIC, MEDIA, HEALTHCARE_FHIR
        industry_vertical=discoveryengine.IndustryVertical.GENERIC,
        # Options: SOLUTION_TYPE_RECOMMENDATION, SOLUTION_TYPE_SEARCH, SOLUTION_TYPE_CHAT, SOLUTION_TYPE_GENERATIVE_CHAT
        solution_types=[discoveryengine.SolutionType.SOLUTION_TYPE_SEARCH],
        # TODO(developer): Update content_config based on data store type.
        # Options: NO_CONTENT, CONTENT_REQUIRED, PUBLIC_WEBSITE
        content_config=discoveryengine.DataStore.ContentConfig.CONTENT_REQUIRED,
    )

    request = discoveryengine.CreateDataStoreRequest(
        parent=parent,
        data_store_id=data_store_id,
        data_store=data_store,
        # Optional: For Advanced Site Search Only
        # create_advanced_site_search=True,
    )

    # Make the request
    operation = client.create_data_store(request=request)

    print(f"Waiting for operation to complete: {operation.operation.name}")
    response = operation.result()

    # After the operation is complete,
    # get information from operation metadata
    metadata = discoveryengine.CreateDataStoreMetadata(operation.metadata)

    # Handle the response
    print(response)
    print(metadata)

    return operation.operation.name

ייבוא מסמכים

from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"
# location = "YOUR_LOCATION" # Values: "global"
# data_store_id = "YOUR_DATA_STORE_ID"
# firestore_project_id = "YOUR_FIRESTORE_PROJECT_ID"
# firestore_database_id = "YOUR_FIRESTORE_DATABASE_ID"
# firestore_collection_id = "YOUR_FIRESTORE_COLLECTION_ID"

#  For more information, refer to:
# https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
client_options = (
    ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
    if location != "global"
    else None
)

# Create a client
client = discoveryengine.DocumentServiceClient(client_options=client_options)

# The full resource name of the search engine branch.
# e.g. projects/{project}/locations/{location}/dataStores/{data_store_id}/branches/{branch}
parent = client.branch_path(
    project=project_id,
    location=location,
    data_store=data_store_id,
    branch="default_branch",
)

request = discoveryengine.ImportDocumentsRequest(
    parent=parent,
    firestore_source=discoveryengine.FirestoreSource(
        project_id=firestore_project_id,
        database_id=firestore_database_id,
        collection_id=firestore_collection_id,
    ),
    # Options: `FULL`, `INCREMENTAL`
    reconciliation_mode=discoveryengine.ImportDocumentsRequest.ReconciliationMode.INCREMENTAL,
)

# Make the request
operation = client.import_documents(request=request)

print(f"Waiting for operation to complete: {operation.operation.name}")
response = operation.result()

# After the operation is complete,
# get information from operation metadata
metadata = discoveryengine.ImportDocumentsMetadata(operation.metadata)

# Handle the response
print(response)
print(metadata)

השלבים הבאים

ייבוא מ-Bigtable

כדי להטמיע נתונים מ-Bigtable, צריך לבצע את השלבים הבאים כדי ליצור מאגר נתונים ולהטמיע נתונים באמצעות ה-API.

הגדרת גישה ל-Bigtable

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

  1. מחליפים את המשתנה PROJECT_NUMBER במספר הפרויקט של חיפוש מבוסס סוכנים, ואז מעתיקים את התוכן של בלוק הקוד הזה. זה המזהה של חשבון השירות של חיפוש מבוסס סוכנים שלך:

    service-PROJECT_NUMBER@gcp-sa-discoveryengine.iam.gserviceaccount.com`
    
  2. עוברים לדף IAM & Admin.

    IAM & Admin

  3. עוברים לפרויקט Bigtable בדף IAM & Admin ולוחצים על Grant Access.

  4. בשדה New principals (חשבונות משתמשים חדשים), מזינים את מזהה חשבון השירות של המופע ובוחרים בתפקיד Bigtable > Bigtable Reader.

  5. לוחצים על Save.

  6. חוזרים לפרויקט חיפוש מבוסס סוכנים.

לאחר מכן, עוברים אל ייבוא נתונים מ-Bigtable.

ייבוא נתונים מ-Bigtable

REST

כדי להשתמש בשורת הפקודה כדי ליצור מאגר נתונים ולייבא נתונים מ-Bigtable, פועלים לפי השלבים הבאים:

  1. יוצרים מאגר נתונים.

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    -H "X-Goog-User-Project: PROJECT_ID" \
    "https://discoveryengine.googleapis.com/v1alpha/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores?dataStoreId=DATA_STORE_ID" \
    -d '{
      "displayName": "DISPLAY_NAME",
      "industryVertical": "GENERIC",
      "solutionTypes": ["SOLUTION_TYPE_SEARCH"],
    }'
    

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

    • PROJECT_ID: מזהה הפרויקט.
    • DATA_STORE_ID: המזהה של מאגר הנתונים. המזהה יכול להכיל רק אותיות קטנות, ספרות, קווים תחתונים ומקפים.
    • DISPLAY_NAME: השם המוצג של מאגר הנתונים. יכול להיות שההודעה תוצג במסוף. Google Cloud
  2. ייבוא נתונים מ-Bigtable.

      curl -X POST \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/branches/0/documents:import" \
      -d '{
        "bigtableSource ": {
          "projectId": "BIGTABLE_PROJECT_ID",
          "instanceId": "INSTANCE_ID",
          "tableId": "TABLE_ID",
          "bigtableOptions": {
            "keyFieldName": "KEY_FIELD_NAME",
            "families": {
              "key": "KEY",
              "value": {
                "fieldName": "FIELD_NAME",
                "encoding": "ENCODING",
                "type": "TYPE",
                "columns": [
                  {
                    "qualifier": "QUALIFIER",
                    "fieldName": "FIELD_NAME",
                    "encoding": "COLUMN_ENCODING",
                    "type": "COLUMN_VALUES_TYPE"
                  }
                ]
              }
             }
             ...
          }
        },
        "reconciliationMode": "RECONCILIATION_MODE",
        "autoGenerateIds": "AUTO_GENERATE_IDS",
        "idField": "ID_FIELD",
      }'
    

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

    • PROJECT_ID: מזהה הפרויקט של חיפוש מבוסס סוכנים.
    • DATA_STORE_ID: המזהה של מאגר הנתונים. המזהה יכול להכיל רק אותיות קטנות, ספרות, קווים תחתונים ומקפים.
    • BIGTABLE_PROJECT_ID: מזהה הפרויקט של Bigtable.
    • INSTANCE_ID: המזהה של מופע Bigtable.
    • TABLE_ID: המזהה של טבלת Bigtable.
    • KEY_FIELD_NAME: אופציונלי אבל מומלץ. שם השדה שבו ישתמשו בשביל ערך מפתח השורה אחרי ההטמעה ב-חיפוש מבוסס סוכנים.
    • KEY: חובה. ערך מחרוזת של מפתח קבוצת עמודות.
    • ENCODING: אופציונלי. מצב הקידוד של הערכים כשהסוג הוא לא STRING.אפשר לשנות את ההגדרה הזו לעמודה ספציפית על ידי ציון העמודה ב-columns והגדרת קידוד בשבילה.
    • COLUMN_TYPE: אופציונלי. סוג הערכים בעמודה הזו
    • QUALIFIER: חובה. מגדיר העמודה.
    • FIELD_NAME: אופציונלי אבל מומלץ. שם השדה שבו יש להשתמש בעמודה הזו אחרי ההטמעה בחיפוש מבוסס סוכנים.
    • COLUMN_ENCODING: אופציונלי. מצב הקידוד של הערכים בעמודה מסוימת כשהסוג הוא לא STRING.
    • RECONCILIATION_MODE: אופציונלי. הערכים הם FULL ו-INCREMENTAL. ערך ברירת המחדל הוא INCREMENTAL. ציון של INCREMENTAL גורם לרענון מצטבר של הנתונים מ-Bigtable אל מאגר הנתונים. הפעולה הזו מבצעת upsert, שמוסיף מסמכים חדשים ומחליף מסמכים קיימים במסמכים מעודכנים עם אותו מזהה. הגדרת FULL גורמת לשינוי בסיס מלא של המסמכים במאגר הנתונים. במילים אחרות, מסמכים חדשים ומעודכנים מתווספים למאגר הנתונים, ומסמכים שלא נמצאים ב-Bigtable מוסרים ממנו. מצב FULL שימושי אם רוצים למחוק באופן אוטומטי מסמכים שכבר לא צריכים.
    • AUTO_GENERATE_IDS: אופציונלי. ההגדרה קובעת אם מזהי המסמכים ייווצרו באופן אוטומטי. אם המדיניות מוגדרת לערך true, מזהי המסמכים נוצרים על סמך גיבוב של מטען הייעודי. חשוב לדעת שמזהי מסמכים שנוצרו יכולים להשתנות בין ייבוא לייבוא. אם אתם יוצרים מזהים באופן אוטומטי בכמה ייבואים, מומלץ מאוד להגדיר את reconciliationMode ל-FULL כדי לשמור על מזהי מסמכים עקביים.

      מציינים autoGenerateIds רק אם הערך של bigquerySource.dataSchema הוא custom. אחרת, מוחזרת שגיאת INVALID_ARGUMENT. אם לא מציינים את autoGenerateIds או מגדירים אותו ל-false, צריך לציין את idField. אחרת, ייבוא המסמכים ייכשל.

    • ID_FIELD: אופציונלי. מציינים אילו שדות הם מזהי המסמכים.

Python

מידע נוסף מופיע בתיעוד העזר של ה-API של חיפוש מבוסס סוכנים Python.

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

יצירת מאגר נתונים


from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"
# location = "YOUR_LOCATION" # Values: "global"
# data_store_id = "YOUR_DATA_STORE_ID"


def create_data_store_sample(
    project_id: str,
    location: str,
    data_store_id: str,
) -> str:
    #  For more information, refer to:
    # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
    client_options = (
        ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
        if location != "global"
        else None
    )

    # Create a client
    client = discoveryengine.DataStoreServiceClient(client_options=client_options)

    # The full resource name of the collection
    # e.g. projects/{project}/locations/{location}/collections/default_collection
    parent = client.collection_path(
        project=project_id,
        location=location,
        collection="default_collection",
    )

    data_store = discoveryengine.DataStore(
        display_name="My Data Store",
        # Options: GENERIC, MEDIA, HEALTHCARE_FHIR
        industry_vertical=discoveryengine.IndustryVertical.GENERIC,
        # Options: SOLUTION_TYPE_RECOMMENDATION, SOLUTION_TYPE_SEARCH, SOLUTION_TYPE_CHAT, SOLUTION_TYPE_GENERATIVE_CHAT
        solution_types=[discoveryengine.SolutionType.SOLUTION_TYPE_SEARCH],
        # TODO(developer): Update content_config based on data store type.
        # Options: NO_CONTENT, CONTENT_REQUIRED, PUBLIC_WEBSITE
        content_config=discoveryengine.DataStore.ContentConfig.CONTENT_REQUIRED,
    )

    request = discoveryengine.CreateDataStoreRequest(
        parent=parent,
        data_store_id=data_store_id,
        data_store=data_store,
        # Optional: For Advanced Site Search Only
        # create_advanced_site_search=True,
    )

    # Make the request
    operation = client.create_data_store(request=request)

    print(f"Waiting for operation to complete: {operation.operation.name}")
    response = operation.result()

    # After the operation is complete,
    # get information from operation metadata
    metadata = discoveryengine.CreateDataStoreMetadata(operation.metadata)

    # Handle the response
    print(response)
    print(metadata)

    return operation.operation.name

ייבוא מסמכים

from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"
# location = "YOUR_LOCATION" # Values: "global"
# data_store_id = "YOUR_DATA_STORE_ID"
# bigtable_project_id = "YOUR_BIGTABLE_PROJECT_ID"
# bigtable_instance_id = "YOUR_BIGTABLE_INSTANCE_ID"
# bigtable_table_id = "YOUR_BIGTABLE_TABLE_ID"

#  For more information, refer to:
# https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
client_options = (
    ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
    if location != "global"
    else None
)

# Create a client
client = discoveryengine.DocumentServiceClient(client_options=client_options)

# The full resource name of the search engine branch.
# e.g. projects/{project}/locations/{location}/dataStores/{data_store_id}/branches/{branch}
parent = client.branch_path(
    project=project_id,
    location=location,
    data_store=data_store_id,
    branch="default_branch",
)

bigtable_options = discoveryengine.BigtableOptions(
    families={
        "family_name_1": discoveryengine.BigtableOptions.BigtableColumnFamily(
            type_=discoveryengine.BigtableOptions.Type.STRING,
            encoding=discoveryengine.BigtableOptions.Encoding.TEXT,
            columns=[
                discoveryengine.BigtableOptions.BigtableColumn(
                    qualifier="qualifier_1".encode("utf-8"),
                    field_name="field_name_1",
                ),
            ],
        ),
        "family_name_2": discoveryengine.BigtableOptions.BigtableColumnFamily(
            type_=discoveryengine.BigtableOptions.Type.INTEGER,
            encoding=discoveryengine.BigtableOptions.Encoding.BINARY,
        ),
    }
)

request = discoveryengine.ImportDocumentsRequest(
    parent=parent,
    bigtable_source=discoveryengine.BigtableSource(
        project_id=bigtable_project_id,
        instance_id=bigtable_instance_id,
        table_id=bigtable_table_id,
        bigtable_options=bigtable_options,
    ),
    # Options: `FULL`, `INCREMENTAL`
    reconciliation_mode=discoveryengine.ImportDocumentsRequest.ReconciliationMode.INCREMENTAL,
)

# Make the request
operation = client.import_documents(request=request)

print(f"Waiting for operation to complete: {operation.operation.name}")
response = operation.result()

# After the operation is complete,
# get information from operation metadata
metadata = discoveryengine.ImportDocumentsMetadata(operation.metadata)

# Handle the response
print(response)
print(metadata)

השלבים הבאים

ייבוא מ-AlloyDB ל-PostgreSQL

כדי להטמיע נתונים מ-AlloyDB ל-PostgreSQL, צריך ליצור מאגר נתונים ולהטמיע נתונים באמצעות Google Cloud המסוף או ה-API.

אם הנתונים שלכם ב-AlloyDB ל-PostgreSQL נמצאים באותו פרויקט כמו פרויקט חיפוש מבוסס סוכנים, אפשר לעבור אל ייבוא נתונים מ-AlloyDB ל-PostgreSQL.

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

הגדרת גישה ל-AlloyDB ל-PostgreSQL מפרויקט אחר

כדי לתת לחיפוש מבוסס סוכנים גישה לנתוני AlloyDB ל-PostgreSQL שנמצאים בפרויקט אחר, פועלים לפי השלבים הבאים:

  1. מחליפים את המשתנה PROJECT_NUMBER במספר הפרויקט שלכם ב-חיפוש מבוסס סוכנים, ואז מעתיקים את התוכן של בלוק הקוד הזה. זה המזהה של חשבון השירות של חיפוש מבוסס סוכנים שלך:

    service-PROJECT_NUMBER@gcp-sa-discoveryengine.iam.gserviceaccount.com
    
  2. עוברים אל Google Cloud הפרויקט שבו נמצאים הנתונים שלכם ב-AlloyDB ל-PostgreSQL.

  3. עוברים לדף IAM.

    IAM

  4. לוחצים על הענקת גישה.

  5. בשדה New principals (ישות מורשית חדשה), מזינים את המזהה של חשבון השירות של חיפוש מבוסס סוכנים ובוחרים בתפקיד Cloud AlloyDB > Cloud AlloyDB Admin (Cloud AlloyDB > אדמין של Cloud AlloyDB).

  6. לוחצים על Save.

  7. חוזרים לפרויקט חיפוש מבוסס סוכנים.

לאחר מכן, עוברים אל ייבוא נתונים מ-AlloyDB ל-PostgreSQL.

ייבוא נתונים מ-AlloyDB ל-PostgreSQL

המסוף

כדי להשתמש במסוף להעברת נתונים מ-AlloyDB ל-PostgreSQL, פועלים לפי השלבים הבאים:

  1. נכנסים לדף AI Applications במסוף Google Cloud .

    אפליקציות AI

  2. בתפריט הניווט, לוחצים על מאגרי נתונים.

  3. לוחצים על יצירת מאגר נתונים.

  4. בדף מקור, בוחרים באפשרות AlloyDB.

  5. מציינים את מזהה הפרויקט, מזהה המיקום, מזהה האשכול, מזהה מסד הנתונים ומזהה הטבלה של הנתונים שרוצים לייבא.

  6. לוחצים על Continue.

  7. בוחרים אזור למאגר הנתונים.

  8. מזינים שם למאגר הנתונים.

  9. לוחצים על יצירה.

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

    בהתאם לגודל הנתונים, תהליך ההטמעה יכול להימשך כמה דקות או כמה שעות.

REST

כדי להשתמש בשורת הפקודה כדי ליצור מאגר נתונים ולהטמיע נתונים מ-AlloyDB ל-PostgreSQL, פועלים לפי השלבים הבאים:

  1. יוצרים מאגר נתונים.

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    -H "X-Goog-User-Project: PROJECT_ID" \
    "https://discoveryengine.googleapis.com/v1beta/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores?dataStoreId=DATA_STORE_ID" \
    -d '{
      "displayName": "DISPLAY_NAME",
      "industryVertical": "GENERIC",
      "solutionTypes": ["SOLUTION_TYPE_SEARCH"],
    }'
    

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

    • PROJECT_ID: מזהה הפרויקט.
    • DATA_STORE_ID: המזהה של מאגר הנתונים. המזהה יכול להכיל רק אותיות קטנות, ספרות, קווים תחתונים ומקפים.
    • DISPLAY_NAME: השם המוצג של מאגר הנתונים. יכול להיות שההודעה תוצג במסוף. Google Cloud
  2. ייבוא נתונים מ-AlloyDB ל-PostgreSQL.

      curl -X POST \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/branches/0/documents:import" \
      -d '{
        "alloydbSource": {
          "projectId": "ALLOYDB_PROJECT_ID",
          "locationId": "LOCATION_ID",
          "clusterId": "CLUSTER_ID",
          "databaseId": "DATABASE_ID",
          "tableId": "TABLE_ID",
        },
        "reconciliationMode": "RECONCILIATION_MODE",
        "autoGenerateIds": "AUTO_GENERATE_IDS",
        "idField": "ID_FIELD",
      }'
    

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

    • PROJECT_ID: מזהה הפרויקט של חיפוש מבוסס סוכנים.
    • DATA_STORE_ID: המזהה של מאגר הנתונים. המזהה יכול להכיל רק אותיות קטנות, ספרות, קווים תחתונים ומקפים.
    • ALLOYDB_PROJECT_ID: מזהה הפרויקט שלכם ב-AlloyDB ל-PostgreSQL.
    • LOCATION_ID: מזהה המיקום של AlloyDB ל-PostgreSQL.
    • CLUSTER_ID: מזהה אשכול AlloyDB ל-PostgreSQL.
    • DATABASE_ID: המזהה של מסד הנתונים שלכם ב-AlloyDB ל-PostgreSQL.
    • TABLE_ID: המזהה של הטבלה ב-AlloyDB ל-PostgreSQL.
    • RECONCILIATION_MODE: אופציונלי. הערכים הם FULL ו-INCREMENTAL. ערך ברירת המחדל הוא INCREMENTAL. הגדרה של INCREMENTAL גורמת לרענון מצטבר של נתונים מ-AlloyDB ל-PostgreSQL אל מאגר הנתונים שלכם. הפעולה הזו מבצעת upsert, שמוסיפה מסמכים חדשים ומחליפה מסמכים קיימים במסמכים מעודכנים עם אותו מזהה. אם מציינים FULL, מתבצעת התאמה מלאה של המסמכים במאגר הנתונים. במילים אחרות, מסמכים חדשים ומעודכנים מתווספים למאגר הנתונים, ומסמכים שלא נמצאים ב-AlloyDB ל-PostgreSQL מוסרים ממאגר הנתונים. מצב FULL שימושי אם רוצים למחוק באופן אוטומטי מסמכים שכבר לא צריכים.
    • AUTO_GENERATE_IDS: אופציונלי. ההגדרה קובעת אם מזהי המסמכים ייווצרו באופן אוטומטי. אם המדיניות מוגדרת לערך true, מזהי המסמכים נוצרים על סמך גיבוב של מטען הייעודי. חשוב לדעת שמזהי מסמכים שנוצרו יכולים להשתנות בין ייבוא לייבוא. אם אתם יוצרים מזהים באופן אוטומטי בכמה ייבואים, מומלץ מאוד להגדיר את reconciliationMode ל-FULL כדי לשמור על מזהי מסמכים עקביים.
    • ID_FIELD: אופציונלי. מציינים אילו שדות הם מזהי המסמכים.

Python

מידע נוסף מופיע בתיעוד העזר של ה-API של חיפוש מבוסס סוכנים Python.

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

יצירת מאגר נתונים


from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"
# location = "YOUR_LOCATION" # Values: "global"
# data_store_id = "YOUR_DATA_STORE_ID"


def create_data_store_sample(
    project_id: str,
    location: str,
    data_store_id: str,
) -> str:
    #  For more information, refer to:
    # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
    client_options = (
        ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
        if location != "global"
        else None
    )

    # Create a client
    client = discoveryengine.DataStoreServiceClient(client_options=client_options)

    # The full resource name of the collection
    # e.g. projects/{project}/locations/{location}/collections/default_collection
    parent = client.collection_path(
        project=project_id,
        location=location,
        collection="default_collection",
    )

    data_store = discoveryengine.DataStore(
        display_name="My Data Store",
        # Options: GENERIC, MEDIA, HEALTHCARE_FHIR
        industry_vertical=discoveryengine.IndustryVertical.GENERIC,
        # Options: SOLUTION_TYPE_RECOMMENDATION, SOLUTION_TYPE_SEARCH, SOLUTION_TYPE_CHAT, SOLUTION_TYPE_GENERATIVE_CHAT
        solution_types=[discoveryengine.SolutionType.SOLUTION_TYPE_SEARCH],
        # TODO(developer): Update content_config based on data store type.
        # Options: NO_CONTENT, CONTENT_REQUIRED, PUBLIC_WEBSITE
        content_config=discoveryengine.DataStore.ContentConfig.CONTENT_REQUIRED,
    )

    request = discoveryengine.CreateDataStoreRequest(
        parent=parent,
        data_store_id=data_store_id,
        data_store=data_store,
        # Optional: For Advanced Site Search Only
        # create_advanced_site_search=True,
    )

    # Make the request
    operation = client.create_data_store(request=request)

    print(f"Waiting for operation to complete: {operation.operation.name}")
    response = operation.result()

    # After the operation is complete,
    # get information from operation metadata
    metadata = discoveryengine.CreateDataStoreMetadata(operation.metadata)

    # Handle the response
    print(response)
    print(metadata)

    return operation.operation.name

ייבוא מסמכים

from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine_v1 as discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"
# location = "YOUR_LOCATION" # Values: "global"
# data_store_id = "YOUR_DATA_STORE_ID"
# alloy_db_project_id = "YOUR_ALLOY_DB_PROJECT_ID"
# alloy_db_location_id = "YOUR_ALLOY_DB_LOCATION_ID"
# alloy_db_cluster_id = "YOUR_ALLOY_DB_CLUSTER_ID"
# alloy_db_database_id = "YOUR_ALLOY_DB_DATABASE_ID"
# alloy_db_table_id = "YOUR_ALLOY_DB_TABLE_ID"

# For more information, refer to:
# https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
client_options = (
    ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
    if location != "global"
    else None
)

# Create a client
client = discoveryengine.DocumentServiceClient(client_options=client_options)

# The full resource name of the search engine branch.
# e.g. projects/{project}/locations/{location}/dataStores/{data_store_id}/branches/{branch}
parent = client.branch_path(
    project=project_id,
    location=location,
    data_store=data_store_id,
    branch="default_branch",
)

request = discoveryengine.ImportDocumentsRequest(
    parent=parent,
    alloy_db_source=discoveryengine.AlloyDbSource(
        project_id=alloy_db_project_id,
        location_id=alloy_db_location_id,
        cluster_id=alloy_db_cluster_id,
        database_id=alloy_db_database_id,
        table_id=alloy_db_table_id,
    ),
    # Options: `FULL`, `INCREMENTAL`
    reconciliation_mode=discoveryengine.ImportDocumentsRequest.ReconciliationMode.INCREMENTAL,
)

# Make the request
operation = client.import_documents(request=request)

print(f"Waiting for operation to complete: {operation.operation.name}")
response = operation.result()

# After the operation is complete,
# get information from operation metadata
metadata = discoveryengine.ImportDocumentsMetadata(operation.metadata)

# Handle the response
print(response)
print(metadata)

השלבים הבאים

העלאת נתונים מובְנים בפורמט JSON באמצעות ה-API

כדי להעלות ישירות מסמך או אובייקט בפורמט JSON באמצעות ה-API, פועלים לפי השלבים הבאים.

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

REST

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

  1. יוצרים מאגר נתונים.

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    -H "X-Goog-User-Project: PROJECT_ID" \
    "https://discoveryengine.googleapis.com/v1alpha/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores?dataStoreId=DATA_STORE_ID" \
    -d '{
      "displayName": "DATA_STORE_DISPLAY_NAME",
      "industryVertical": "GENERIC",
      "solutionTypes": ["SOLUTION_TYPE_SEARCH"]
    }'
    

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

    • PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
    • DATA_STORE_ID: המזהה של מאגר הנתונים של חיפוש מבוסס סוכנים שרוצים ליצור. המזהה יכול להכיל רק אותיות קטנות, ספרות, קווים תחתונים ומקפים.
    • DATA_STORE_DISPLAY_NAME: השם המוצג של מאגר הנתונים של חיפוש מבוסס סוכנים שרוצים ליצור.
  2. ייבוא נתונים מובְנים.

    יש כמה גישות להעלאת נתונים, כולל:

    • מעלים מסמך JSON.

      curl -X POST \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      "https://discoveryengine.googleapis.com/v1beta/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/branches/0/documents?documentId=DOCUMENT_ID" \
      -d '{
        "jsonData": "JSON_DOCUMENT_STRING"
      }'
      

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

      • DOCUMENT_ID: מזהה ייחודי של המסמך. המזהה יכול לכלול עד 63 תווים, שמורכבים רק מאותיות קטנות, ספרות, קווים תחתונים ומקפים.
      • JSON_DOCUMENT_STRING: מסמך ה-JSON כמחרוזת אחת. הפורמט צריך להיות בהתאם לסכימת ה-JSON שסיפקתם בשלב הקודם – לדוגמה:

        { \"title\": \"test title\", \"categories\": [\"cat_1\", \"cat_2\"], \"uri\": \"test uri\"}
        
    • מעלים אובייקט JSON.

      curl -X POST \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      "https://discoveryengine.googleapis.com/v1beta/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/branches/0/documents?documentId=DOCUMENT_ID" \
      -d '{
        "structData": JSON_DOCUMENT_OBJECT
      }'
      

      מחליפים את JSON_DOCUMENT_OBJECT במסמך ה-JSON כאובייקט JSON. הפורמט צריך להיות בהתאם לסכימת ה-JSON שסיפקתם בשלב הקודם – לדוגמה:

       {
         "title": "test title",
         "categories": [
           "cat_1",
           "cat_2"
         ],
         "uri": "test uri"
       }
      
    • עדכון באמצעות מסמך JSON.

      curl -X PATCH \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      "https://discoveryengine.googleapis.com/v1beta/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/branches/0/documents/DOCUMENT_ID" \
      -d '{
        "jsonData": "JSON_DOCUMENT_STRING"
      }'
      
    • עדכון באמצעות אובייקט JSON.

      curl -X PATCH \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      "https://discoveryengine.googleapis.com/v1beta/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/branches/0/documents/DOCUMENT_ID" \
      -d '{
        "structData": JSON_DOCUMENT_OBJECT
      }'
      

השלבים הבאים

פתרון בעיות בהטמעת נתונים

אם נתקלתם בבעיות בהעברת נתונים, כדאי לעיין בטיפים הבאים:

  • אם אתם משתמשים במפתחות הצפנה בניהול הלקוח וייבוא הנתונים נכשל (עם הודעת השגיאה The caller does not have permission), צריך לוודא שסוכן השירות של Cloud Storage קיבל את תפקיד ה-IAM‏ CryptoKey Encrypter/Decrypter‏ (roles/cloudkms.cryptoKeyEncrypterDecrypter) במפתח. מידע נוסף מופיע במאמר בנושא מפתחות הצפנה בניהול הלקוח, בקטע לפני שמתחילים.

  • אם אתם משתמשים בהוספה מתקדמת של אתרים לאינדקס, והערך של Document usage במאגר הנתונים נמוך בהרבה מהצפוי, כדאי לבדוק את תבניות כתובות ה-URL שציינתם להוספה לאינדקס ולוודא שהן כוללות את הדפים שאתם רוצים להוסיף לאינדקס. אם צריך, אפשר להרחיב את התבניות. לדוגמה, אם השתמשתם ב-*.en.example.com/*, יכול להיות שתצטרכו להוסיף את *.example.com/* לאתרים שאתם רוצים לאנדקס.

יצירת מאגר נתונים באמצעות Terraform

אפשר להשתמש ב-Terraform כדי ליצור מאגר נתונים ריק. אחרי שמאגר הנתונים הריק נוצר, אפשר להטמיע בו נתונים באמצעות Google Cloud המסוף או פקודות API.

כדי ללמוד איך להחיל הגדרות ב-Terraform או להסיר אותן, ראו פקודות בסיסיות ב-Terraform.

כדי ליצור מאגר נתונים ריק באמצעות Terraform, אפשר לעיין במאמר google_discovery_engine_data_store.

קישור של מקור נתונים מצד שלישי

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

הוראות לחיבור מקור נתונים של צד שלישי מופיעות במסמכי Gemini Enterprise.