עדכון סכימה

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

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

כדי לעדכן את הסכימה, אפשר להוסיף שדות חדשים, לשנות את ההערות של שדה שניתן להוסיף לאינדקס, לחפש ולאחזר, או לסמן שדה כמאפיין מפתח, כמו 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 ומגדירים את השדה החדש.

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

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

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

REST

כדי להשתמש ב-API לעדכון הסכימה:

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

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

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

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

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

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

      כניסה לדף Data Stores

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

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

  5. משתמשים ב-method‏ schemas.patch של ה-API כדי לספק את סכימת ה-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 ל-string.
  • הסרת שדה אחרי שמגדירים שדה, אי אפשר להסיר אותו. אפשר להמשיך להוסיף שדות חדשים, אבל אי אפשר להסיר שדה קיים.

דוגמאות למגבלות (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"
            }
          }
        }
      }
    

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