Vertex AI RAG Engine 的检索和生成输出

本页面介绍了 Vertex AI RAG Engine 输出的每个字段。

retrieveContexts

本部分介绍了 retrieveContexts API 中定义的每个字段,并在示例代码中使用了这些字段。

字段

字段名称 说明
source_uri 导入到 RAG 之前的原始源文件。如果文件是从 Cloud Storage 或 Google 云端硬盘导入的,则 source_uri 是 Cloud Storage 或云端硬盘中的原始文件 URI。如果文件已上传,则 source_uri 是文件的显示名称。
source_display_name 文件的显示名称。
text 与查询相关的文本块。
score 查询与文本块之间的相似度或距离。 相似度或距离取决于您选择的 vectorDB。对于 ragManagedDB,得分是 COSINE_DISTANCE

示例输出

此代码示例演示了如何使用这些字段来生成示例输出。

contexts {
    source_uri: "gs://sample_folder/hello_world.txt"
    source_display_name: "hello_world.txt"
    text: "Hello World!"
    score: 0.60545359030757784
  }

generateContent

generateContent API 定义的大部分字段都可以在响应正文中找到。

字段

本部分介绍了 generateContent API 的 grounding_metadata 部分中定义的每个字段,并在示例代码中使用这些字段。

字段名称 说明
text 由 Gemini 生成的回答。
grounding_chunks Vertex AI RAG 引擎返回的块。
retrieved_context 一个重复字段,可以包含零个或多个用于为生成的内容提供依据的块。
  • uri
  • source_uri 用于指定数据的原始存储位置。
  • title
  • source_display_name 是原始文件的文件名或显示名称。
  • text
  • 文本块用于为 Gemini 回答提供依据。
grounding_supports 生成的内容与依据块之间的关系。此字段是重复字段。每个 grounding_supports 字段都显示了生成的上下文的一个文本段与 RAG 检索到的一个或多个文本块之间的关系。
segment 生成文本中已确定依据的文本段。
  • start_index
  • 已添加根据的文本的第一个索引。如果缺少 start_index,则 start_index0
  • end_index
  • 已根据上下文信息确定的文本的最后一个索引。
  • text
  • 有事实依据的文本。
grounding_chunk_indices 用于锚定文本段的块。可以使用多个块来作为文本的基础。索引从 0 开始,表示 grounding_chunks 字段中的第一个块。地面位于整个区块上。未指定作为回答依据的块部分。
confidence_scores 用于将文本锚定到给定块的分数。最高分是 1,得分越高,置信度越高。每个得分都与每个 grounding_chunk_indices 相匹配。输出中仅包含置信度分数不低于 0.6 的块。

示例输出

此代码示例演示了如何使用这些字段来生成示例输出。

candidates {
  content {
    role: "model"
    parts {
      text: "The rectangle is red and the background is white. The rectangle appears to be on some type of document editing software. \n"
    }
  }
  grounding_metadata {
    grounding_chunks {
      retrieved_context {
        uri: "a.txt"
        title: "a.txt"
        text: "Okay ,  I  see  a  red  rectangle  on  a  white  background .  It looks like it\'s on some sort of document editing software. It has those small squares and circles around it, indicating that it\'s a selected object ."
      }
    }
    grounding_chunks {
      retrieved_context {
        uri: "b.txt"
        title: "b.txt"
        text: "The  video  is  identical  to  the  last  time  I  described  it .  It shows a blue rectangle on a white background."
      }
    }
    grounding_chunks {
      retrieved_context {
        uri: "c.txt"
        title: "c.txt"
        text: "Okay ,  I  remember  the  rectangle  was  blue  in  the  past  session . Now it is red.\n The  red  rectangle  is  still  there .  It \' s  still  in  the same position on the white background, with the same handles around it. Nothing new is visible since last time.\n You \' re  welcome .  The  red  rectangle  is  still  the  only  thing visible."
      }
    }
    grounding_supports {
      segment {
        end_index: 49
        text: "The rectangle is red and the background is white."
      }
      grounding_chunk_indices: 2
      grounding_chunk_indices: 0
      confidence_scores: 0.958192229
      confidence_scores: 0.992316723
    }
    grounding_supports {
      segment {
        start_index: 50
        end_index: 120
        text: "The rectangle appears to be on some type of document editing software."
      }
      grounding_chunk_indices: 0
      confidence_scores: 0.98374176
    }
  }
}

后续步骤