Vertex AI RAG 引擎的检索和生成输出

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

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
    }
  }
}

后续步骤