构建代理以发现数据

Knowledge Catalog 发现智能体是一款 AI 赋能的助理,可根据 Knowledge Catalog 搜索功能提高复杂自然语言查询的搜索相关性。通过优化查询理解和公式,它提供的结果比标准 Knowledge Catalog Search API 更准确。此功能至关重要,尤其对于复杂或冗长的查询而言更是如此。

使用场景

发现智能体为以下场景提供了丰富的对话式体验:

  • 复杂或组合的意图和限制条件: 处理具有多个条件的搜索请求,例如在 us-central1 中查找数据集,但排除 BigQuery 中的资源。
  • 面向业务的搜索: 根据意图和业务背景发现数据资产,而不是匹配确切的技术术语。
  • 多轮探索: 通过对话式对话优化搜索,以缩小结果范围。

发现智能体基于 Knowledge Catalog 语义搜索 构建,可为您提供开箱即用的混合搜索。当您需要处理高意图搜索(当您知道特定资源或列时)、低延迟要求或零设置混合搜索时,可以继续直接使用 Knowledge Catalog 语义搜索。

工作原理

发现智能体会执行以下步骤来响应搜索查询:

  1. 分析输入以了解意图,理解查询,生成多个搜索变体,并将术语映射到元数据过滤器。
  2. 使用 Knowledge Catalog 语义搜索来搜索资源。
  3. 根据相关性对合并后的结果进行排名。

下图详细介绍了该过程:

用于搜索请求的发现代理进程。
发现智能体中搜索请求的处理路径。

该智能体依赖于 Knowledge Catalog Search API 来提取相关 Google Cloud 资源。以下代码段展示了该智能体如何调用 Knowledge Catalog 语义搜索:


      # Configure the request parameters for the
      # call to Knowledge Catalog Semantic Search API.
      endpoint = "dataplex.googleapis.com"

      client = dataplex_v1.CatalogServiceClient(
          client_options={"api_endpoint": endpoint}
      )

      location = "global"
      consumer_project_id = "my-gcp-project"
      parent_name = f"projects/{consumer_project_id}/locations/{location}"

      # Call Knowledge Catalog Semantic Search API.
      response = client.search_entries(
          request={
              "name": parent_name,
              "query": query,
              "page_size": 50,
              "semantic_search": True,
          }
      )

      # Call Knowledge Catalog LookupContext for each search result
      # to retrieve rich, LLM-ready metadata.
      entries = []
      for result in response.results:
          entry_name = result.dataplex_entry.name
          
          # Prepare the LookupContext request for the specific resource
          lookup_request = {
              "name": parent_name,
              "resources": [entry_name]
          }
          
          # Call the LookupContext API
          lookup_response = client.lookup_context(request=lookup_request)
          
          # Extract the rich context YAML to share with the agent
          entries.append({
              "entry_name": entry_name,
              "context": lookup_response.context
          })

      return {