חיפוש עם שאלות המשך

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

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

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

מידע על חיפוש עם שאלות המשך

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

התכונה 'חיפוש עם שאלות המשך' תומכת בפעולות הבאות:

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

  • הבנת ההקשר: הוא מבין את ההקשר של אינטראקציות קודמות ומספק תשובות בהתאם להקשר.

  • רב-שלבי: המשתמשים יכולים לשאול שאלות המשך ולקבל תשובות רלוונטיות.

דוגמה לחיפוש עם שאלות המשך

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

  • אתה: מתי הכי כדאי לצאת לחופשה במקסיקו?

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

  • אתה: מהו שער החליפין?

  • חיפוש עם שאלות המשך: דולר אחד שווה בערך ל-17.65 פסו מקסיקני.

  • אתם: מה הטמפרטורה הממוצעת בדצמבר?

  • חיפוש עם שאלות המשך: מה הטמפרטורה הממוצעת? הטמפרטורה הממוצעת בקנקון היא ‎~ 25°C.

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

מידע על שיחות

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

לפעמים קוראים לצמדים האלה של שאילתות ותשובות הודעות. בדוגמה שלמעלה, ההודעה השנייה מורכבת מהטקסטים 'What is the exchange rate?' (מהו שער החליפין?) ו-'1 USD is equal to approximately 17.65 Mexican pesos' (דולר אחד שווה בערך ל-17.65 פסו מקסיקני).

השיחות מאוחסנות באותו מאגר נתונים שבו מאוחסנים הנתונים הלא מובנים. מאגר הנתונים מייצג שיחה באמצעות מקור המידע Conversation. בנוסף להודעות של השאילתה והתשובה, במשאב השיחה יש:

  • שם ייחודי (מזהה השיחה).

  • סטטוס (בתהליך או הושלם).

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

  • שעת התחלה ושעת סיום.

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

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

שמירת שיחות וקבלת תשובות

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

REST

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

  1. מציינים את מאגר הנתונים שבו רוצים לאחסן את היסטוריית השיחות:

    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/conversations" \
    -d '{
      "user_pseudo_id": "USER_PSEUDO_ID"
    }'
    
    • PROJECT_ID: מספר הפרויקט או המזהה של Google Cloud הפרויקט

    • DATA_STORE_ID: המזהה של מאגר הנתונים שמשויך לאפליקציה.

    • USER_PSEUDO_ID: מזהה ייחודי למעקב אחרי מבקר בחיפוש. לדוגמה, אפשר להטמיע את זה באמצעות קובץ Cookie של HTTP, שמזהה באופן ייחודי מבקר במכשיר יחיד.

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

    {
      "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/conversations/11078281986791420687",
      "state": "IN_PROGRESS",
      "userPseudoId": "test_id",
      "startTime": "2023-08-15T20:08:12.094639Z"
    }
  2. ליצור תשובה לחיפוש ולהוסיף אותה לשיחה חדשה או קיימת במאגר הנתונים:

    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/conversations/CONVERSATION_ID:converse" \
    -d '{
      "query": { "input": "FREE_TEXT"},
      "filter": "FILTER"
    }'
    
    • PROJECT_ID: מספר הפרויקט או המזהה של Google Cloud הפרויקט

    • DATA_STORE_ID: המזהה של מאגר הנתונים שמשויך לאפליקציה.

    • CONVERSATION_ID: מזהה ייחודי של השיחה, לדוגמה, 123456. בשיחה עם חיפוש והמשך שאלות, צריך להשתמש באותו מזהה שיחה בכל תור.

    • FREE_TEXT: מחרוזת טקסט חופשית שמכילה את השאלה של המשתמש. לדוגמה: what is bigquery?

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

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

    {
    "reply": {
    "summary": {
      "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data."
    }
    },
    "conversation": {
    "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/conversations/11078281986791420687",
    "state": "IN_PROGRESS",
    "userPseudoId": "test_id",
    "messages": [
      {
        "userInput": {
          "input": "what is bigquery?"
        }
      },
      {
        "reply": {
          "summary": {
            "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data."
          }
        }
      }
    ],
    "startTime": "2023-08-15T20:08:12.094639Z"
    },
    "searchResults": [
    {
      "id": "c86f19582746b56f71c9bb6929893835",
      "document": {
        "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/branches/0/documents/c86f19582746b56f71c9bb6929893835",
        "id": "c86f19582746b56f71c9bb6929893835",
        "derivedStructData": {
          "link": "gs://aquamuse-data-ucs-eval-dev/documents/94627ee0249dfdfda25b1b158c717bca.txt",
          "snippets": [
            {
              "snippet_status": "SUCCESS",
              "snippet": "For larger websites, talk to the IT team and/or utilize a big data solution such as Google \u003cb\u003eBigQuery\u003c/b\u003e to extract all URLs. It may also be necessary to ask the ..."
            }
          ],
          "extractive_answers": [
            {
              "content": "Alternatively, load the Server Log Files into Google BigQuery and use the Google BigQuery interface or the 360 Data Studio to analyze the data. To monitor the indexation numbers of the HTTP and the HTTPS version, keep an eye on all submitted XML Sitemaps."
            }
          ]
        }
      }
    },
    {
      "id": "774bd7ce2a3509ab4bbd1fc876f39dc2",
      "document": {
        "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/branches/0/documents/774bd7ce2a3509ab4bbd1fc876f39dc2",
        "id": "774bd7ce2a3509ab4bbd1fc876f39dc2",
        "derivedStructData": {
          "snippets": [
            {
              "snippet": "No snippet is available for this page.",
              "snippet_status": "NO_SNIPPET_AVAILABLE"
            }
          ],
          "extractive_answers": [
            {
              "content": "This consists of a collection of virtual tables. A virtual table exists for every queryable object type (content type if you prefer) in the repository. Each row in these virtual tables correspond to an instance of the corresponding object type (or of one of its subtypes)."
            }
          ],
          "link": "gs://aquamuse-data-ucs-eval-dev/documents/28841ef8590a105e9415f1390648a811.txt"
        }
      }
    },
    {
      "id": "3e1d306e49aefd9e23f2d5f7a66e6c76",
      "document": {
        "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/branches/0/documents/3e1d306e49aefd9e23f2d5f7a66e6c76",
        "id": "3e1d306e49aefd9e23f2d5f7a66e6c76",
        "derivedStructData": {
          "snippets": [
            {
              "snippet": "No snippet is available for this page.",
              "snippet_status": "NO_SNIPPET_AVAILABLE"
            }
          ],
          "extractive_answers": [
            {
              "content": "Other logo switches are based on search terms. For instance, if the term "ASCII art" is searched, an ASCII art version of the Google logo will appear next to the search box."
            }
          ],
          "link": "gs://aquamuse-data-ucs-eval-dev/documents/98008df3eef5d3ee1661c52f23189190.txt"
        }
      }
    },
    {
      "id": "cf94e24aacd47cd2c2f5effcbdeda832",
      "document": {
        "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/branches/0/documents/cf94e24aacd47cd2c2f5effcbdeda832",
        "id": "cf94e24aacd47cd2c2f5effcbdeda832",
        "derivedStructData": {
          "extractive_answers": [
            {
              "content": "The company is listed on the NASDAQ stock exchange under the ticker symbols GOOGL and GOOG, and on the Frankfurt Stock Exchange under the ticker symbol GGQ1. These ticker symbols now refer to Alphabet Inc., Google's holding company, since the fourth quarter of 2015."
            }
          ],
          "snippets": [
            {
              "snippet": "No snippet is available for this page.",
              "snippet_status": "NO_SNIPPET_AVAILABLE"
            }
          ],
          "link": "gs://aquamuse-data-ucs-eval-dev/documents/d80204083ef1096799fa4b7257548b33.txt"
        }
      }
    },
    {
      "id": "05bc6497a4e7e6ca36b2e495b354b764",
      "document": {
        "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/branches/0/documents/05bc6497a4e7e6ca36b2e495b354b764",
        "id": "05bc6497a4e7e6ca36b2e495b354b764",
        "derivedStructData": {
          "extractive_answers": [
            {
              "content": "SQL injection countermeasures are designed to utilize secure programming methods. By changing the variables used by the application code, weaknesses in applications can be greatly minimized. This report will detail how to perform a SQL injection and explore the best countermeasures to prevent the attack."
            }
          ],
          "link": "gs://aquamuse-data-ucs-eval-dev/documents/7cba75d646f5774a21d96801bec68bb3.txt",
          "snippets": [
            {
              "snippet_status": "NO_SNIPPET_AVAILABLE",
              "snippet": "No snippet is available for this page."
            }
          ]
        }
      }
    }
    ]
    }
  3. חוזרים על שלב 2 לכל שאלה חדשה בשיחה.

Python

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

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

from typing import List

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", "us", "eu"
# data_store_id = "YOUR_DATA_STORE_ID"
# search_queries = ["YOUR_FIRST_SEARCH_QUERY", "YOUR_SECOND_SEARCH_QUERY"]


def multi_turn_search_sample(
    project_id: str,
    location: str,
    data_store_id: str,
    search_queries: List[str],
) -> List[discoveryengine.ConverseConversationResponse]:
    #  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.ConversationalSearchServiceClient(
        client_options=client_options
    )

    # Initialize Multi-Turn Session
    conversation = client.create_conversation(
        # The full resource name of the data store
        # e.g. projects/{project_id}/locations/{location}/dataStores/{data_store_id}
        parent=client.data_store_path(
            project=project_id, location=location, data_store=data_store_id
        ),
        conversation=discoveryengine.Conversation(),
    )


    for search_query in search_queries:
        # Add new message to session
        request = discoveryengine.ConverseConversationRequest(
            name=conversation.name,
            query=discoveryengine.TextInput(input=search_query),
            serving_config=client.serving_config_path(
                project=project_id,
                location=location,
                data_store=data_store_id,
                serving_config="default_config",
            ),
            # Options for the returned summary
            summary_spec=discoveryengine.SearchRequest.ContentSearchSpec.SummarySpec(
                # Number of results to include in summary
                summary_result_count=3,
                include_citations=True,
            ),
        )
        response = client.converse_conversation(request)

        print(f"Reply: {response.reply.summary.summary_text}\n")

        for i, result in enumerate(response.search_results, 1):
            result_data = result.document.derived_struct_data
            print(f"[{i}]")
            print(f"Link: {result_data['link']}")
            print(f"First Snippet: {result_data['snippets'][0]['snippet']}")
            print(
                "First Extractive Answer: \n"
                f"\tPage: {result_data['extractive_answers'][0]['pageNumber']}\n"
                f"\tContent: {result_data['extractive_answers'][0]['content']}\n\n"
            )
        print("\n\n")

סינון החיפוש באמצעות שאלות המשך

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

ביטויי סינון לנתוני אתרים

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

ביטויי סינון לנתונים לא מובנים עם מטא-נתונים

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

הגדרת הסיכום

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

איך מקבלים ציטוטים עם תוצאות החיפוש

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

כדי לקבל ציטוטים:

  • פועלים לפי ההוראות שבקטע שמירת שיחות וקבלת תשובות בצ'אט, אבל בשלב 2 מריצים את הפקודה הזו שכוללת את השדה summarySpec שבו הערך includeCitations מוגדר כ-true.

    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/conversations/CONVERSATION_ID:converse" \
    -d '{
      "query": { "input": "FREE_TEXT"},
      "summarySpec": { "include_citations": true }
    }'
    

    לחיצה על חלק מהתשובה מפקודה לדוגמה.

    {
    "reply": {
    "summary": {
    }
    "reply": {
    "summary": {
      "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly [1]. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data [2, 3].",
      "safetyAttributes": {
        "categories": [
          "Finance",
          "Legal"
        ]

מספרי הציטוטים כלולים בטקסט הסיכום. מספרי הציטוטים מתייחסים לתוצאות החיפוש שהוחזרו, והם ממוספרים מ-1. לדוגמה, [1] מציין שהמשפט משויך לתוצאת החיפוש הראשונה. ‫[2, 3] מציין שהמשפט משויך גם לתוצאת החיפוש השנייה וגם לתוצאת החיפוש השלישית.

התעלמות משאילתות שמנסות להטעות

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

כדי לציין שלא יוחזרו סיכומים של חיפושים לשאילתות שנועדו להטעות:

  • פועלים לפי ההוראות שבקטע שמירת שיחות וקבלת תשובות בצ'אט, אבל בשלב 2 מריצים את הפקודה הזו שכוללת את השדה summarySpec שבו הערך ignoreAdversarialQuery מוגדר כ-true.

    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/conversations/CONVERSATION_ID:converse" \
    -d '{
      "query": { "input": "FREE_TEXT"},
      "summarySpec": { "ignoreAdversarialQuery": true }
    }'
    

    לוחצים על חלק מהתשובה משאילתה עוינת.

    "reply": {
    "summary": {
      "summaryText": "A summary could not be generated for your search query. Here are some search results.",
      "summarySkippedReasons": [
        "ADVERSARIAL_QUERY_IGNORED"
      ]

התעלמות משאילתות שלא קשורות לסיכום

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

כדי לציין שלא יוחזרו סיכומי חיפוש לשאילתות שלא מחפשות סיכום:

  • פועלים לפי ההוראות שבקטע שמירת שיחות וקבלת תשובות בצ'אט, אבל בשלב 2 מריצים את הפקודה הזו שכוללת את השדה summarySpec שבו הערך ignoreNonSummarySeekingQuery מוגדר כ-true.

    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/conversations/CONVERSATION_ID:converse" \
    -d '{
      "query": { "input": "FREE_TEXT"},
      "summarySpec": { "ignore_non_summary_seeking_query": true }
    }'
    

    לוחצים על חלק מהתשובה משאילתה עוינת.

     "reply": {
    "summary": {
      "summaryText": "A summary could not be generated for your search query. Here are some search results.",
      "summarySkippedReasons": [
        "NON_SUMMARY_SEEKING_QUERY_IGNORED"
      ]

הגדרת מספר התוצאות שייכללו בסיכום

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

כדי להגדיר את מספר התוצאות המובילות שייכללו בסיכום:

  • פועלים לפי ההוראות שבקטע שמירת שיחות וקבלת תשובות בצ'אט, אבל בשלב 2 מריצים את הפקודה הזו שכוללת את השדה summarySpec שבו מוגדר הערך summaryResultCount.

    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/conversations/CONVERSATION_ID:converse" \
    -d '{
      "query": { "input": "FREE_TEXT"},
      "summarySpec": { "summary_result_count": NUMBER_OF_RESULTS }
    }'
    

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

קבלת סיכומים בהתאמה אישית

כדי לקבל סיכומים בהתאמה אישית, אפשר לספק הוראות בשפה טבעית בשדה modelPromptSpec.preamble כשמבקשים סיכום.

אתם יכולים לבקש התאמות אישיות כמו אורך ורמת פירוט, סגנון הפלט (למשל, "פשוט"), שפת הפלט, מוקד התשובה ופורמט (למשל, טבלאות, תבליטים ו-XML).

לדוגמה, בשאילתה 'מה היתרונות של BigQuery?' אפשר להזין הוראות להתאמה אישית כמו בדוגמאות הבאות:

  • הוראה לדוגמה: "please show the answer format in an ordered list"

    דוגמה לתשובה:

    The benefits of BigQuery are:
    
    1. Increased business productivity
    2. IT staff productivity
    3. Reduced infrastructure costs
    4. Loading and exporting data are free
    
  • הוראה לדוגמה: give a very detailed answer

    דוגמה לתשובה:

    BigQuery is a serverless, highly scalable, and cost-effective cloud data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that takes care of provisioning, scaling, and managing the underlying infrastructure, so you can focus on analyzing your data. BigQuery is also integrated with other Google Cloud services, such as Google Kubernetes Engine, Cloud Data Fusion, and Cloud Dataproc, making it easy to build and deploy data pipelines.
    
    Here are some of the benefits of using BigQuery:
    
    * **Fast and scalable:** BigQuery can process petabytes of data very quickly, and it can scale to handle even the most demanding workloads. * **Cost-effective:** BigQuery is a very cost-effective way to store and analyze data. You only pay for the data that you use, and there are no upfront costs or commitments. * **Secure:** BigQuery is a secure platform that meets the needs of even the most security-conscious organizations. * **Easy to use:** BigQuery is easy to use, even for non-technical users. It has a simple and intuitive user interface, and it supports a variety of data sources. * **Integrated with other Google Cloud services:** BigQuery is integrated with other Google Cloud services, making it easy to build and deploy data pipelines.
    
    If you are looking for a fast, scalable, and cost-effective way to analyze your data, then BigQuery is a great option.
    

כדי לקבל סיכום מותאם אישית:

  • פועלים לפי השלבים של שמירת שיחות בחנות וקבלת תשובות בצ'אט, אבל בשלב 2 מריצים את הפקודה הזו שכוללת את השדה summarySpec שמציין את הוראות ההתאמה האישית ב-modelPromptSpec.preamble.

      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/conversations/CONVERSATION_ID:converse" \
      -d '{
        "query": { "input": "FREE_TEXT"},
        "summarySpec": {
          "modelPromptSpec": {
            "preamble": "CUSTOMIZATION_INSTRUCTIONS"
          }
        }
      }'
    
    • CUSTOMIZATION_INSTRUCTIONS: ההוראה להתאמה אישית, בפורמט של מחרוזת.

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

כדי להחיל חיפוש בטוח על תשובה בצ'אט:

  • פועלים לפי השלבים של שמירת שיחות עם החנות וקבלת תשובות בצ'אט, אבל בשלב 2, בשאילתה, מציינים safe_search.

    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/conversations/CONVERSATION_ID:converse" \
    -d '{
      "query": { "input": "FREE_TEXT"},
      "safe_search": true
    }'
    

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

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

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

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

  • מריצים את פקודת ה-curl הבאה:

    curl -X GET \
    -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/conversations/CONVERSATION_ID"
    
    • PROJECT_ID: מספר הפרויקט או המזהה של Google Cloud הפרויקט

    • DATA_STORE_ID:המזהה של מאגר הנתונים שמשויך לאפליקציה.

    • CONVERSATION_ID: מזהה השיחה

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

    {
    "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/conversations/2040473575290303058",
    "state": "IN_PROGRESS",
    "userPseudoId": "2040473575290303058",
    "messages": [
    {
      "userInput": {
        "input": "what is bigquery?"
      }
    },
    {
      "reply": {
        "summary": {
          "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data."
        }
      }
    }
    ],
    "startTime": "2023-08-15T20:11:24.046735Z"
    }

מחיקת שיחה ממאגר הנתונים

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

כדי למחוק שיחה ממאגר נתונים:

  • מריצים את פקודת ה-curl הבאה:

    curl -X DELETE \
    -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/conversations/CONVERSATION_ID"
    
    • PROJECT_ID: מספר הפרויקט או המזהה של Google Cloud הפרויקט

    • DATA_STORE_ID: המזהה של מאגר הנתונים שמשויך לאפליקציה.

    • CONVERSATION_ID: מזהה השיחה

    התגובה מהפקודה DELETE אמורה להיראות כך:

    {}
    

עדכון שיחה

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

  • איך מסמנים ששיחה טופלה

  • מיזוג ההודעות משיחה אחת לשיחה אחרת

  • שינוי user_pseudo_id

כדי לעדכן את state בשיחה:

  • מריצים את פקודת ה-curl הבאה:

    curl -X PATCH \
    -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/conversations/CONVERSATION_ID?updateMask=state" \
    -d '{
      "state": "NEW_STATE"
    }'
    
    • PROJECT_ID: מספר הפרויקט או המזהה של Google Cloud הפרויקט

    • DATA_STORE_ID: המזהה של מאגר הנתונים שמשויך לאפליקציה.

    • CONVERSATION_ID: המזהה של השיחה שרוצים לעדכן.

    • NEW_STATE: הערך החדש של המצב, לדוגמה, COMPLETED

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

    {
    "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/conversations/11078281986791420687",
    "state": "COMPLETED",
    "userPseudoId": "test_id1",
    "messages": [
    {
      "userInput": {
        "input": "what is bigquery?"
      }
    },
    {
      "reply": {
        "summary": {
          "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data."
        }
      }
    }
    ],
    "startTime": "2023-08-15T20:08:12.094639Z"
    }

כדי לעדכן את user_pseudo_id בשיחה:

  • מריצים את פקודת ה-curl הבאה:

    curl -X PATCH \
    -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/conversations/CONVERSATION_ID?updateMask=user_pseudo_id" \
    -d '{
      "user_pseudo_id": "NEW_USER_PSEUDO_ID"
    }'
    
    • PROJECT_ID: מספר הפרויקט או המזהה של Google Cloud הפרויקט

    • DATA_STORE_ID: המזהה של מאגר הנתונים שמשויך לאפליקציה.

    • CONVERSATION_ID: המזהה של השיחה שרוצים לעדכן

    • NEW_USER_PSEUDO_ID: הערך החדש של המזהה הפסאודו-אנונימי של המשתמש

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

    {
    "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/conversations/11078281986791420687",
    "state": "IN_PROGRESS",
    "userPseudoId": "test_id1",
    "messages": [
    {
      "userInput": {
        "input": "what is bigquery?"
      }
    },
    {
      "reply": {
        "summary": {
          "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data."
        }
      }
    }
    ],
    "startTime": "2023-08-15T20:08:12.094639Z"
    }

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

הצגת רשימה של כל השיחות

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

  • מריצים את פקודת ה-curl הבאה:

    curl -X GET \
    -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/conversations"
    
    • PROJECT_ID: מספר הפרויקט או המזהה של Google Cloud הפרויקט

    • DATA_STORE_ID: המזהה של מאגר הנתונים שמשויך לאפליקציה.

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

    {
    "conversations": [
    {
      "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/conversations/11078281986791420687",
      "state": "IN_PROGRESS",
      "userPseudoId": "test_id",
      "messages": [
        {
          "userInput": {
            "input": "what is bigquery?"
          }
        },
        {
          "reply": {
            "summary": {
              "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data."
            }
          }
        }
      ],
      "startTime": "2023-08-15T20:08:12.094639Z"
    },
    {
      "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/conversations/2040473575290303058",
      "state": "IN_PROGRESS",
      "userPseudoId": "2040473575290303058",
      "messages": [
        {
          "userInput": {
            "input": "what is bigquery?"
          }
        },
        {
          "reply": {
            "summary": {
              "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data."
            }
          }
        }
      ]
    }
    ]
    }

התשובה מכילה רשימה של שיחות ואת next_page_token. אם לא מוחזרת next_page_token, אין עוד שיחות להצגה.

גודל הדף שמוגדר כברירת מחדל הוא 50.

סינון השיחות לפי מסנן

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

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

כדי לעשות את זה, מציגים רשימה של שיחות שתואמות למסנן נתון: user_pseudo_id או state (IN_PROGRESS או COMPLETED).

רשימת השיחות של משתמש

כדי להציג רשימה של שיחות שמשויכות למשתמש או למבקר:

  • מריצים את פקודת ה-curl הבאה:

    curl -X GET \
    -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/conversations?filter=user_pseudo_id=USER_PSEUDO_ID"
    
    • PROJECT_ID: מספר הפרויקט או המזהה של Google Cloud הפרויקט

    • DATA_STORE_ID: המזהה של מאגר הנתונים שמשויך לאפליקציה.

    • USER_PSEUDO_ID: המזהה הפסאודו של המשתמש שרוצים להציג את השיחות שלו.

    התגובה מהפקודה GET נראית כך:

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

    {
    "conversations": [
    {
      "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/conversations/11078281986791420687",
      "state": "IN_PROGRESS",
      "userPseudoId": "test_id",
      "messages": [
        {
          "userInput": {
            "input": "what is bigquery?"
          }
        },
        {
          "reply": {
            "summary": {
              "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data."
            }
          }
        }
      ],
      "startTime": "2023-08-15T20:08:12.094639Z"
    }
    ]
    }

רשימת שיחות של משתמש ומצב

כדי להציג רשימה של שיחות בסטטוס מסוים (פתוח או סגור) וגם שיחות שמשויכות למשתמש או למבקר:

  • מריצים את פקודת ה-curl הבאה:

    curl -X GET \
    -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/conversations?filter=user_pseudo_id=USER_PSEUDO_ID%20AND%20state=STATE"
    
    • PROJECT_ID: מספר הפרויקט או המזהה של Google Cloud הפרויקט

    • DATA_STORE_ID: המזהה של מאגר הנתונים שמשויך לאפליקציה.

    • USER_PSEUDO_ID: המזהה הפסאודו של המשתמש שרוצים להציג את השיחות שלו.

    • STATE: אם השיחה פתוחה או סגורה (IN_PROGRESS או COMPLETED)

    התגובה מהפקודה GET נראית כך:

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

    {
    "conversations": [
    {
      "name": "projects/12345/locations/global/collections/default_collection/dataStores/my-data-store_4321/conversations/11078281986791420687",
      "state": "IN_PROGRESS",
      "userPseudoId": "test_id",
      "messages": [
        {
          "userInput": {
            "input": "what is bigquery?"
          }
        },
        {
          "reply": {
            "summary": {
              "summaryText": "BigQuery is a cloud-based data warehouse that enables businesses to analyze all their data very quickly. It is a fully managed service that provides a simple and cost-effective way to store and analyze large amounts of data."
            }
          }
        }
      ],
      "startTime": "2023-08-15T20:08:12.094639Z"
    }
    ]
    }

מידע כללי על תחביר סינון זמין במאמר AIP-160 Filtering.

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

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

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

אחרי שמפעילים את התכונה 'שאלות קשורות', השאלות מוחזרות כמחרוזות ב-ConverseConversationResponse.

מידע נוסף

  • מידע נוסף על השדות summaryResultCount, includeCitations, ignoreAdversarialQuery ו-ignoreNonSummarySeekingQuery זמין במאמר SummarySpec במסמכי התיעוד של Agent Search API.

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