עדכון סכימה

אפשר לעדכן את הנתונים המובְנים של הסכימה ואת הנתונים הלא מובְנים עם מטא-נתונים שתומכים בסכימה.

אפשר לעדכן את הסכימה במסוף Google Cloud או באמצעות ה-method‏ schemas.patch ב-API.

כדי לעדכן את הסכימה, אתם יכולים להוסיף שדות חדשים, לשנות את ההערות של שדה שניתן להוסיף לאינדקס, לחפש ולאחזר, או לסמן שדה כמאפיין מפתח, כמו title, uri ו-description.

עדכון הסכימה

אפשר לעדכן את הסכימה במסוף Google Cloud או באמצעות ה-API.

המסוף

כדי לעדכן סכימה במסוף Google Cloud :

  1. כדי לוודא שעדכון הסכימה תקין, עיינו בקטע דרישות ומגבלות.

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

  3. מוודאים שהשלמתם את הטמעת הנתונים. אחרת, יכול להיות שהסכימה עדיין לא זמינה לעריכה.

  4. נכנסים לדף Gemini Enterprise במסוף Google Cloud .

    Gemini Enterprise

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

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

  7. לוחצים על הכרטיסייה Schema כדי לראות את הסכימה של הנתונים.

    אם זו הפעם הראשונה שאתם עורכים את השדות, יכול להיות שהכרטיסייה הזו תהיה ריקה.

  8. לוחצים על הכפתור עריכה.

  9. עדכון הסכימה:

    • מיפוי מאפייני מפתח: בעמודה מאפייני מפתח של הסכימה, בוחרים מאפיין מפתח כדי למפות אליו שדה. לדוגמה, אם שדה בשם details תמיד מכיל את התיאור של מסמך, ממפים את השדה הזה למאפיין המפתח Description.

    • עדכון מספר המאפיינים (מתקדם): אתם יכולים לעדכן את ההגדרה הזו אם אתם משתמשים בהטמעות וקטורים בהתאמה אישית עם Gemini Enterprise. שימוש בהטמעות בהתאמה אישית במאמרי העזרה של Agent Search.

    • עדכון הערות בשדות: כדי לעדכן הערות בשדה, בוחרים או מבטלים את הבחירה בהגדרת ההערות של השדה. ההערות הזמינות הן Retrievable,‏ Indexable,‏ Dynamic Facetable,‏ Searchable ו-Completable. בחלק מהגדרות השדות יש מגבלות. במאמר קביעת הגדרות של שדות מפורטים התיאורים והדרישות של כל סוג הערה.

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

      1. לוחצים על הוספת שדות חדשים כדי להרחיב את הקטע הזה.

      2. לוחצים על add_box Add node ומגדירים את השדה החדש.

        כדי לציין מערך, מגדירים את מערך לערך כן. לדוגמה, כדי להוסיף מערך של מחרוזות, מגדירים את type לערך string ואת Array לערך Yes.

  10. לוחצים על Save כדי להחיל את השינויים בסכימה.

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

REST

כדי לעדכן את הסכימה באמצעות ה-API, פועלים לפי השלבים הבאים:

  1. כדי לוודא שהשינויים בסכימה תקינים, עיינו בקטעים דרישות ומגבלות ודוגמאות למגבלות (REST בלבד).

    כדי לעדכן את הסכימה של מאגרי נתונים לא מובְנים עם מטא-נתונים, דלגו לשלב 5 והפעילו את ה-method‏ schema.patch.

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

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

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

    1. במסוף Google Cloud , נכנסים לדף Gemini Enterprise ובתפריט הניווט לוחצים על מאגרי נתונים.

      כניסה לדף Data Stores

    2. לוחצים על השם של מאגר הנתונים.

    3. בדף Data של מאגר הנתונים, מאתרים את מזהה מאגר הנתונים.

  5. משתמשים ב-method של ה-API‏ schemas.patch כדי לספק את סכימת ה-JSON החדשה כאובייקט 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/schemas/default_schema" \
    -d '{
      "structSchema": JSON_SCHEMA_OBJECT
    }'
    

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

    • ‫PROJECT_ID: מזהה הפרויקט.
    • ‫DATA_STORE_ID: המזהה של מאגר הנתונים.
    • ‫JSON_SCHEMA_OBJECT: סכימת ה-JSON החדשה כאובייקט JSON. לדוגמה:

      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "type": "object",
        "properties": {
          "title": {
            "type": "string",
            "keyPropertyMapping": "title"
          },
          "categories": {
            "type": "array",
            "items": {
              "type": "string",
              "keyPropertyMapping": "category"
            }
          },
          "uri": {
            "type": "string",
            "keyPropertyMapping": "uri"
          }
        }
      }
  6. אופציונלי: בודקים את הסכימה לפי ההליך הצגת הגדרת סכימה.

C#

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

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

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

public sealed partial class GeneratedSchemaServiceClientSnippets
{
    /// <summary>Snippet for UpdateSchema</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 UpdateSchemaRequestObject()
    {
        // Create client
        SchemaServiceClient schemaServiceClient = SchemaServiceClient.Create();
        // Initialize request argument(s)
        UpdateSchemaRequest request = new UpdateSchemaRequest
        {
            Schema = new Schema(),
            AllowMissing = false,
        };
        // Make the request
        Operation<Schema, UpdateSchemaMetadata> response = schemaServiceClient.UpdateSchema(request);

        // Poll until the returned long-running operation is complete
        Operation<Schema, UpdateSchemaMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        Schema 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<Schema, UpdateSchemaMetadata> retrievedResponse = schemaServiceClient.PollOnceUpdateSchema(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            Schema retrievedResult = retrievedResponse.Result;
        }
    }
}

Go

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

כדי לבצע אימות ב-Gemini Enterprise, צריך להגדיר את 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.NewSchemaClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

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

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

Java

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

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

import com.google.cloud.discoveryengine.v1.Schema;
import com.google.cloud.discoveryengine.v1.SchemaServiceClient;
import com.google.cloud.discoveryengine.v1.UpdateSchemaRequest;

public class SyncUpdateSchema {

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

  public static void syncUpdateSchema() 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 (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
      UpdateSchemaRequest request =
          UpdateSchemaRequest.newBuilder()
              .setSchema(Schema.newBuilder().build())
              .setAllowMissing(true)
              .build();
      Schema response = schemaServiceClient.updateSchemaAsync(request).get();
    }
  }
}

Python

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

כדי לבצע אימות ב-Gemini Enterprise, צריך להגדיר את 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.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import discoveryengine_v1


def sample_update_schema():
    # Create a client
    client = discoveryengine_v1.SchemaServiceClient()

    # Initialize request argument(s)
    request = discoveryengine_v1.UpdateSchemaRequest()

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

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)

Ruby

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

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

require "google/cloud/discovery_engine/v1"

##
# Snippet for the update_schema call in the SchemaService 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::SchemaService::Client#update_schema.
#
def update_schema
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::DiscoveryEngine::V1::SchemaService::Client.new

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

  # Call the update_schema method.
  result = client.update_schema 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

דרישות ומגבלות

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

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

עדכוני סכימה לא תומכים בפעולות הבאות:

  • שינוי סוג השדה. אי אפשר לשנות את סוג השדה בעדכון סכימה, למעט חריג אחד: אפשר לשנות שדה מסוג integer ל-number. כל שינוי אחר, כמו integer ל-string, שדה יחיד למערך או עומק קינון שונה למערך קיים, נכשל עם השגיאה Schema update cannot alter the field type. Field type mismatch for field "FIELD_NAME".
  • הסרת שדה אחרי שמגדירים שדה, אי אפשר להסיר אותו. אתם יכולים להמשיך להוסיף שדות חדשים, אבל לא להסיר שדות קיימים. בקשה שמשמיטה שדה קיים נכשלת ומתקבלת השגיאה Schema update doesn't support removing fields. Fields "FIELD_NAME" cannot be removed.
  • שינוי מיפויים אחרים של מאפייני מפתחות. אפשר להוסיף או להסיר את מיפויי המאפיינים של המקשים title,‏ description,‏ uri,‏ create_time ו-update_time. אי אפשר להעביר מיפוי של מאפיין מפתח משדה אחד לשדה אחר, ואי אפשר להוסיף מיפוי של מאפיין מפתח אחר לסכימה כל עוד מאגר הנתונים מכיל מסמכים.

דוגמאות למגבלות (REST בלבד)

בקטע הזה מוצגות דוגמאות לסוגים תקינים ולא תקינים של עדכוני סכימה. בדוגמאות האלה נעשה שימוש בסכימת ה-JSON הבאה:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "title": {
      "type": "string"
    },
    "description": {
      "type": "string",
      "keyPropertyMapping": "description"
    },
    "categories": {
      "type": "array",
      "items": {
        "type": "string",
        "keyPropertyMapping": "category"
      }
    }
  }
}

דוגמאות לעדכונים נתמכים

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

  • הוספת שדה. בדוגמה הזו, השדה properties.uri נוסף לסכימה.

    {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "type": "object",
      "properties": {
        "title": {
          "type": "string"
        },
        "description": {
          "type": "string",
          "keyPropertyMapping": "description"
        },
        "uri": { // Added field. This is supported.
          "type": "string",
          "keyPropertyMapping": "uri"
        },
        "categories": {
          "type": "array",
          "items": {
            "type": "string",
            "keyPropertyMapping": "category"
          }
        }
      }
    }
    
  • הוספה או הסרה של הערות למאפייני מפתח של title, ‏description או uri. בדוגמה הזו, הערך keyPropertyMapping נוסף לשדה title.

    {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "type": "object",
      "properties": {
        "title": {
          "type": "string",
          "keyPropertyMapping": "title" // Added "keyPropertyMapping". This is supported.
        },
        "description": {
          "type": "string",
          "keyPropertyMapping": "description"
        },
        "categories": {
          "type": "array",
          "items": {
            "type": "string",
            "keyPropertyMapping": "category"
          }
        }
      }
    }
    

דוגמאות לעדכוני סכימה לא תקינים

העדכונים הבאים לסכימה לדוגמה לא נתמכים.

  • שינוי סוג השדה. בדוגמה הזו, סוג השדה title השתנה ממחרוזת למספר. האפשרות הזו לא נתמכת.

      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "type": "object",
        "properties": {
          "title": {
            "type": "number" // Changed from string. Not allowed.
          },
          "description": {
            "type": "string",
            "keyPropertyMapping": "description"
          },
          "categories": {
            "type": "array",
            "items": {
              "type": "string",
              "keyPropertyMapping": "category"
            }
          }
        }
      }
    
  • הסרת שדה בדוגמה הזו, השדה title הוסר. האפשרות הזו לא נתמכת.

      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "type": "object",
        "properties": {
          // "title" is removed. Not allowed.
          "description": {
            "type": "string",
            "keyPropertyMapping": "description"
          },
          "uri": {
            "type": "string",
            "keyPropertyMapping": "uri"
          },
          "categories": {
            "type": "array",
            "items": {
              "type": "string",
              "keyPropertyMapping": "category"
            }
          }
        }
      }
    

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