תוסף חיפוש מבוסס סוכנים

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

  • "מה היו השינויים באיומים התחרותיים על החברה בין הרבעון הראשון של השנה שעברה לבין הרבעון הראשון של השנה הנוכחית?"
  • "What parts of the company are growing the fastest? כמה מהר?"

התוסף Agent Search משתמש ב-Agent Search כדי לאחזר תוצאות משמעותיות ממאגר הנתונים שלכם. תוסף חיפוש מבוסס סוכנים מוגדר בקובץ vertex_ai_search.yaml של OpenAPI Specification.

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

openapi: "3.0.0"
info:
  title: Vertex AI Search
  version: v1alpha
  description: >
    Performs search on user ingested data including website and unstructured data type.

    This extension is used when user wants to search or retrieve meaningful results from their ingested data in the Vertex AI Search service.

    Supported AuthTypes:
    - GOOGLE_SERVICE_ACCOUNT_AUTH: (only supports using Vertex AI Extension Service Agent).
paths:
  /search:
    get:
      operationId: search
      description: Retrieves the results from user's query by searching in the data store.
      parameters:
      - name: query
        in: query
        schema:
          type: string
        description: User natural language instructions for search.
        required: true
      responses:
        default:
          description: Search execution result.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SearchResult"

components:
  schemas:
    SearchResult:
      description: Top results from search response.
      type: object
      properties:
        results:
          type: array
          items:
            type: object
            properties:
              title:
                type: string
                description: Retrieved document title.
              display_link:
                type: string
                description: Retrieved document link to display.
              link:
                type: string
                description: Retrieved document link.
              extractive_segments:
                type: array
                description: Extractive segments from the retrieved file.
                items:
                  type: string
              extractive_answers:
                type: array
                description: Extractive answers from the retrieved file. These are generated from the extractive segments.
                items:
                  type: string

    

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

  • תהליך העבודה של מנתח עסקי עם תוספים של Vertex AI: שימוש בתוסף Code Interpreter ובתוסף חיפוש מבוסס סוכנים כדי להשלים דוח מחקר על הזדמנויות להשקעה בנדל"ן עבור בעלי עניין בעסק.
    Colab | GitHub | Vertex AI Workbench
  • תהליך עבודה לניתוח ביקורות על משחקים באמצעות תוספים ל-Vertex AI: אפשר להשתמש בתוסף Code Interpreter כדי לנתח ביקורות על משחקים מ-Steam. אפשר להשתמש בתוסף חיפוש מבוסס סוכנים כדי לסכם ביקורות על משחקים מאתרים. משתמשים בתוסף Code Interpreter כדי ליצור דוח עם כל הנכסים שנוצרו.
    Colab | GitHub | Vertex AI Workbench

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

  1. נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Vertex AI API, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Vertex AI API, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

רישום והפעלה של התוסף חיפוש מבוסס סוכנים

בקטעים הבאים מוסבר איך לרשום את התוסף חיפוש מבוסס סוכנים באמצעות Google Cloud המסוף ו-Vertex AI API. אחרי שרושמים את התוסף, אפשר להריץ אותו באמצעות Vertex AI API.

המסוף

רישום התוסף

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

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

    מעבר ל-Vertex AI Extensions

  2. לוחצים על יצירת תוסף.

  3. בתיבת הדו-שיח Create a new extension (יצירת תוסף חדש), ממלאים את השדות הבאים:

    • שם התוסף: מזינים שם לתוסף, למשל vertex_search_extension.
    • תיאור: (אופציונלי) מזינים תיאור של התוסף, למשל 'תוסף חיפוש של Vertex AI'.
    • סוג תוסף: בוחרים באפשרות Vertex AI search.
  4. בקטע OpenAPI Spec file שמופיע עכשיו, מוודאים שהשדות הבאים מוגדרים בצורה נכונה:

    • שם ה-API: vertex_ai_search.
    • תיאור ה-API: Performs search on user ingested data including website and unstructured data type...
    • מקור: Cloud Storage.
    • OpenAPI Spec: vertex-extension-public/vertex_ai_search.yaml.
    • אימות: Google service account.
  5. בקטע Runtime configurations (הגדרות זמן ריצה), מציינים שם להגדרת ההצגה. שם הגדרת ההצגה מצוין ב-vertexAiSearchRuntimeConfig. הפורמט והמילוי של הטופס הם כאלה: projects/PROJECT_ID/locations/global/collections/COLLECTION_NAME/engines/ENGINE/servingConfigs/SERVING_CONFIG

  6. לוחצים על יצירת תוסף.

REST

רישום התוסף

שולחים בקשה ל-Vertex AI API extensions.import כדי לרשום את התוסף חיפוש מבוסס סוכנים.

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

  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
  • ‫REGION: אזור Compute Engine.
  • ‫DISPLAY_NAME: התוסף name שמוצג למשתמשים, כמו my_search_extension.
  • ‫DESCRIPTION: (אופציונלי) תיאור התוסף שמוצג למשתמשים, למשל 'תוסף חיפוש'.
  • ‫SERVICE_ACCOUNT: (אופציונלי) התוסף Vertex AI Search משתמש ב-GOOGLE_SERVICE_ACCOUNT_AUTH כמו שמוצג בגוף בקשת הדוגמה. אם לא מציינים חשבון שירות, התוסף משתמש בחשבון השירות שמוגדר כברירת מחדל Vertex AI Extension Service Agent. אם מציינים חשבון שירות אחר, צריך לתת את ההרשאה iam.serviceAccounts.getAccessToken לחשבון השירות שצוין, לחשבון השירות של סוכן שירות התוספים של Vertex AI.
  • ‫SERVING_CONFIG_NAME: השם של הגדרות ההצגה מצוין ב-vertexAiSearchRuntimeConfig. הפורמט והמילוי שלו הם כאלה: projects/PROJECT_ID/locations/global/collections/COLLECTION_NAME/engines/ENGINE/servingConfigs/SERVING_CONFIG.

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

POST https://REGION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/REGION/extensions:import

גוף בקשת JSON:

{
  "displayName":"DISPLAY_NAME",
  "description":"DESCRIPTION",
  "manifest":{
    "name":"vertex_ai_search_tool",
    "description":"A Vertex AI Search tool",
    "apiSpec":{
      "openApiGcsUri":"gs://vertex-extension-public/vertex_ai_search.yaml"
    },
    "authConfig":{
      "authType":"GOOGLE_SERVICE_ACCOUNT_AUTH",
      "googleServiceAccountConfig":{
        "serviceAccount":"SERVICE_ACCOUNT"
      }
    }
  }
  "runtimeConfig": {
     "vertexAiSearchRuntimeConfig": {
        "servingConfigName": "SERVING_CONFIG_NAME",
     }
  }
}

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

curl

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

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://REGION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/REGION/extensions:import"

PowerShell

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

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

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://REGION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/REGION/extensions:import" | Select-Object -Expand Content

הפעלת התוסף

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

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

  • ‫PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
  • ‫REGION: אזור Compute Engine.
  • ‫EXTENSION_ID: המזהה של התוסף שלכם לחיפוש מבוסס-Vertex AI שמופיע בפרטי התוסף במסוף Google Cloud .

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

POST https://REGION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/REGION/extensions/EXTENSION_ID:execute

גוף בקשת JSON:

{
  "operation_id":"search",
  "operation_params":{
    "query":"Housing affordability since 2010",
  }
}

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

curl

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

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://REGION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/REGION/extensions/EXTENSION_ID:execute"

PowerShell

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

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

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://REGION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/REGION/extensions/EXTENSION_ID:execute" | Select-Object -Expand Content