מחיקת נתונים לצמיתות ממאגר נתונים מאינטראקציה ישירה (First-Party)

בדף הזה מוסבר איך למחוק את כל הנתונים במאגר נתונים מובנה או לא מובנה.

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

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

מחיקת נתונים

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

המסוף

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

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

    Gemini Enterprise

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

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

  4. בכרטיסייה מסמכים, לוחצים על מחיקת נתונים.

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

  6. לוחצים על הכרטיסייה פעילות כדי לעקוב אחרי התקדמות פעולת ההסרה.

REST

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

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

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

      כניסה לדף Data Stores

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

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

  2. מבצעים קריאה ל-method‏ documents.purge.

    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:purge" \
    -d '{
      "filter": "*",
      "force": FORCE
    }'
    

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

    • PROJECT_ID: Google Cloud project
    • DATA_STORE_ID: המזהה של מאגר הנתונים.
    • FORCE: ערך בוליאני שקובע אם למחוק נתונים מהענף של מאגר הנתונים.
      • אם true, כל הנתונים מהענף נמחקים
      • אם false, לא נמחקים נתונים ומוחזרת רשימה של מסמכים בענף.
      • אם לא מציינים את הערך force, ברירת המחדל היא false.
  3. אופציונלי: רושמים את הערך name שמוחזר על ידי השיטה documents.purge ופועלים לפי ההוראות במאמר קבלת פרטים על פעולה ממושכת כדי לראות מתי פעולת ההסרה הושלמה.

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 GeneratedDocumentServiceClientSnippets
{
    /// <summary>Snippet for PurgeDocuments</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 PurgeDocumentsRequestObject()
    {
        // Create client
        DocumentServiceClient documentServiceClient = DocumentServiceClient.Create();
        // Initialize request argument(s)
        PurgeDocumentsRequest request = new PurgeDocumentsRequest
        {
            ParentAsBranchName = BranchName.FromProjectLocationDataStoreBranch("[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[BRANCH]"),
            Filter = "",
            Force = false,
            GcsSource = new GcsSource(),
            ErrorConfig = new PurgeErrorConfig(),
        };
        // Make the request
        Operation<PurgeDocumentsResponse, PurgeDocumentsMetadata> response = documentServiceClient.PurgeDocuments(request);

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

Go

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

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


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.PurgeDocumentsRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/discoveryengine/apiv1/discoveryenginepb#PurgeDocumentsRequest.
	}
	op, err := c.PurgeDocuments(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.BranchName;
import com.google.cloud.discoveryengine.v1.DocumentServiceClient;
import com.google.cloud.discoveryengine.v1.PurgeDocumentsRequest;
import com.google.cloud.discoveryengine.v1.PurgeDocumentsResponse;
import com.google.cloud.discoveryengine.v1.PurgeErrorConfig;

public class SyncPurgeDocuments {

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

  public static void syncPurgeDocuments() 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()) {
      PurgeDocumentsRequest request =
          PurgeDocumentsRequest.newBuilder()
              .setParent(
                  BranchName.ofProjectLocationDataStoreBranchName(
                          "[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[BRANCH]")
                      .toString())
              .setFilter("filter-1274492040")
              .setErrorConfig(PurgeErrorConfig.newBuilder().build())
              .setForce(true)
              .build();
      PurgeDocumentsResponse response = documentServiceClient.purgeDocumentsAsync(request).get();
    }
  }
}

Node.js

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי Node.jsההוראות להגדרה במאמר מדריך למתחילים של Gemini Enterprise באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Gemini Enterprise Node.js 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.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Cloud Storage location for the input content.
 *  Supported `data_schema`:
 *  * `document_id`: One valid
 *  Document.id google.cloud.discoveryengine.v1.Document.id  per line.
 */
// const gcsSource = {}
/**
 *  Inline source for the input content for purge.
 */
// const inlineSource = {}
/**
 *  Required. The parent resource name, such as
 *  `projects/{project}/locations/{location}/collections/{collection}/dataStores/{data_store}/branches/{branch}`.
 */
// const parent = 'abc123'
/**
 *  Required. Filter matching documents to purge. Only currently supported
 *  value is
 *  `*` (all items).
 */
// const filter = 'abc123'
/**
 *  The desired location of errors incurred during the purge.
 */
// const errorConfig = {}
/**
 *  Actually performs the purge. If `force` is set to false, return the
 *  expected purge count without deleting any documents.
 */
// const force = true

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

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

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

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

callPurgeDocuments();

Python

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

כדי לבצע אימות ב-Gemini Enterprise, צריך להגדיר את 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", "us", "eu"
# data_store_id = "YOUR_DATA_STORE_ID"


def purge_documents_sample(
    project_id: str, location: str, data_store_id: str
) -> discoveryengine.PurgeDocumentsMetadata:
    #  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)

    operation = client.purge_documents(
        request=discoveryengine.PurgeDocumentsRequest(
            # 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",
            ),
            filter="*",
            # If force is set to `False`, return the expected purge count without deleting any documents.
            force=True,
        )
    )

    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.PurgeDocumentsMetadata(operation.metadata)

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

    return metadata

Ruby

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

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

require "google/cloud/discovery_engine/v1"

##
# Snippet for the purge_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#purge_documents.
#
def purge_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::PurgeDocumentsRequest.new

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