从数据存储区中清除数据

本页介绍了如何清除结构化或非结构化数据存储区中的所有数据。

您必须先清除结构化数据存储区、非结构化数据存储区或医疗保健数据存储区中的数据,然后才能删除数据存储区。

如果您想在重新导入新数据之前彻底删除数据存储区中的内容,还可以清除数据存储区中的数据。清除数据存储区只会删除数据存储区中的数据,而不会影响您的应用、架构和配置。

网站数据存储区

网站数据存储区不支持清除操作。您可以根据需要从网站数据存储区中移除网站,但在删除数据存储区之前,这并非必需操作。

清除数据

如需从数据存储区中清除数据,请执行以下操作:

控制台

如需使用 Google Cloud 控制台从结构化数据存储区、非结构化数据存储区或医疗保健数据存储区的分支中清除数据,请按以下步骤操作:

  1. 在 Google Cloud 控制台中,前往 Agent Builder 页面。

    Agent Builder

  2. 在导航菜单中,点击数据存储区

  3. 名称列中,点击要清除的数据存储区。

  4. 结算凭证标签页中,点击 清除数据

  5. 阅读确认清除数据对话框中的警告。如果您想继续,请输入数据存储区的名称,然后点击确认。清除数据是一项长时间运行的操作。如需了解详情,请参阅监控长时间运行的操作

  6. 点击活动标签页,监控清除操作的进度。

REST

如需使用命令行从结构化或非结构化数据存储区的分支中清除数据,请按以下步骤操作:

  1. 找到您的数据存储区 ID。如果您已拥有数据存储区 ID,请跳至下一步。

    1. 在 Google Cloud 控制台中,前往 Agent Builder 页面,然后在导航菜单中点击数据存储区

      前往“数据存储区”页面

    2. 点击您的数据存储区的名称。

    3. 在数据存储区的数据页面上,获取数据存储区 ID。

  2. 调用 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 项目。
    • DATA_STORE_ID:Vertex AI Search 数据存储区的 ID。
    • FORCE:一个布尔值,用于指定是否从数据存储区的分支中删除数据。
      • 如果为 true,则会从分支中删除所有数据
      • 如果为 false,则不会删除任何数据,并返回分支中的文档列表。
      • 如果省略 force,则默认为 false
  3. 可选:记下 documents.purge 方法返回的 name 值,然后按照获取长时间运行的操作的详细信息中的说明查看清除操作何时完成。

C#

如需了解详情,请参阅 Vertex AI Agent Builder C# API 参考文档

如需向 Vertex AI Agent Builder 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

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

如需了解详情,请参阅 Vertex AI Agent Builder Go API 参考文档

如需向 Vertex AI Agent Builder 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证


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

如需了解详情,请参阅 Vertex AI Agent Builder Java API 参考文档

如需向 Vertex AI Agent Builder 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

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

如需了解详情,请参阅 Vertex AI Agent Builder Node.js API 参考文档

如需向 Vertex AI Agent Builder 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

/**
 * 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

如需了解详情,请参阅 Vertex AI Agent Builder Python API 参考文档

如需向 Vertex AI Agent Builder 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

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

如需了解详情,请参阅 Vertex AI Agent Builder Ruby API 参考文档

如需向 Vertex AI Agent Builder 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

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