使用 RAG 检查接地

作为 检索增强生成 (RAG) Vertex AI Agent Builder,您可以 检查依据,确定如何 依据一段文本(称为候选答案)是否位于指定的一组字词中 参考文本(称为事实)。

Check Grounding API 会返回一个介于 0 到 1 之间的总体支持得分,该得分表示候选答案与给定事实的一致程度。该回复还包含对候选答案中每个声明所依据事实的引用

此外,您还可以将断言级支持得分作为一项实验性功能启用,以获取支持得分,该得分表示候选答案的每个断言的依据。

完全归因要求答案候选中的每个断言都必须有一个或多个给定事实支持。换句话说,该声明完全由事实所蕴含。如果版权主张只有部分涉及,那么 会被视为无法接地。例如,“Google 由 Larry Page 和 Sergey Brin 于 1975 年创立”这一声明只有部分正确(创始人的名字正确,但日期有误),因此整个声明被视为缺乏依据。在此版本的 Check grounding API 中,句子是 被视为一项版权主张。

您还可以启用反引用这项实验性功能 矛盾得分,指示候选答案的矛盾程度 给定事实。该回复还包含针对每个声明的矛盾事实的反引用

您可以使用 check grounding API 检查任何文本。这可以是人工生成的宣传信息,也可以是机器生成的回答。一个典型用例是,根据给定的一组事实检查 LLM 生成的回答。检查 Grounding API 设计得非常快,延迟时间不到 500 毫秒。这种语速 允许聊天机器人在每次推理期间调用 Check grounding API, 速度将会大幅降低Check Grounding API 还可以 以便于用户判断网站的哪些部分 是否可靠。该 API 还会提供一个支持得分, 表示回答的总体准确性。通过设置引用阈值 聊天机器人可以在推理时过滤掉可能包含 幻觉声明。

本页介绍了如何使用 Check Grounding API 检查接地。

准备工作

检查接地 API 已正式发布。

此外,还有两个功能处于“实验性”阶段:

  • 用于生成冲突得分的反引用功能。
  • 用于返回每个版权主张支持得分的版权主张级得分功能。

如需试用实验性功能,请与您的 Google 客户支持团队联系,请求将您添加到许可名单中。

术语的定义和解释

在使用 Check grounding API 之前,最好先了解输入和 输出内容,以及如何构建依据数据以获得最佳效果。

输入数据

Check grounding API 需要在请求中提供以下输入。

  • 候选答案:候选答案可以是您想要检查其背景知识的任何文本。例如,在 Vertex AI Search,候选答案可能是 用于回答查询的摘要。然后,该 API 会确定摘要与输入事实的相关程度。候选答案的长度上限 达到 4096 个词元。

  • 事实:一组文本段,用作标准答案参考。 您可以为每个文本片段提供一组元数据属性(键值对)。例如:“作者”和“标题”都是典型的属性键

    该服务最多支持 200 条事实,每条最多 1 万个字符。

    Google 建议不要提供包含全部信息、 信息。相反,您可以将大事实拆分为小事实,并为小事实提供适当的属性,从而获得更好的结果。例如,您可以按标题、作者或网址对大事实进行分解, 并在属性中提供此信息。

  • 引用阈值:一个介于 0 到 1 之间的浮点值,用于控制支持候选答案的引用的置信度。阈值越高,置信度要求越严格。因此,阈值越高,引用量越少,但引用质量越高。

输出数据

Check Grounding API 会针对候选答案返回以下内容:

  • 支持得分:支持得分是一个介于 0 到 1 之间的数字, 表示某个答案候选者在给定事实集的依据程度。 它大致近似于答案候选项中被发现基于一个或多个给定事实的断言所占的比例。

  • 引用的块:引用的块是输入事实的一部分, 。

  • 断言和引用:断言和引用将答案候选项的断言(通常是一个句子)与一个或多个用于证实该断言的引用内容块相关联。

    启用声明级得分后,对于每个声明,都将提供 得分以 0 到 1 之间的数字的形式返回,指示 与所提供的事实不符。如需了解详情,请参阅 获取 候选答案

  • 需要进行依据调查:对于每项版权主张, 标准答案返回的是 grounding-check-required 布尔值。当返回为 False 时, 则表示系统认为该版权主张不需要依据、 因此不会返回引用和反引用内容。例如, 例如“以下是我找到的内容”这本身并不是一项事实 不需要执行依据检查。

    如果“需要执行标准答案的检查”返回为 true,则意味着 并执行了依据核查, 包含反引用内容(如果有的话)。

获取候选答案的支持得分

如需了解候选答案与一组事实的相关性,请按以下步骤操作:

  1. 准备好您的事实信息。有关详情和示例,请参见条款 定义和解释

  2. 使用以下代码调用 check 方法:

REST

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-H "X-Goog-User-Project: PROJECT_ID" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/groundingConfigs/default_grounding_config:check" \
-d '{
  "answerCandidate": "CANDIDATE",
  "facts": [
  {
    "factText": "TEXT_0",
    "attributes": {"ATTRIBUTE_A": "VALUE_A0","ATTRIBUTE_B": "VALUE_B0"}
  },
  {
    "factText": "TEXT_1",
    "attributes": {"ATTRIBUTE_A": "VALUE_A1","ATTRIBUTE_B": "VALUE_B1"}
  },
  {
    "factText": "TEXT_2",
    "attributes": {"ATTRIBUTE_A": "VALUE_A2","ATTRIBUTE_B": "VALUE_B2"}
  }
  ],
  "groundingSpec": {
    "citationThreshold": "CITATION_THRESHOLD"
  }
}'

替换以下内容:

  • PROJECT_ID:您的 Google Cloud 项目的项目编号或 ID。

  • CANDIDATE:为其确定的答案候选字符串 您希望获得支持分数,例如 Titanic was directed by James Cameron. It was released in 1997.。 长度上限为 4096 个词元。

  • TEXT:要使用的文本段 表示依据,例如 Titanic is a 1997 American epic... Academy Awards.(请参阅事实示例中的完整内容。)

  • ATTRIBUTE:与事实关联的元数据属性的名称,例如 authortitle。这是用户定义的标签,用于向事实文本添加更多信息。例如,如果事实文本 Toronto is the capital of Ontario 具有 author 属性,且其值为 Wikipedia,则系统会认为以下断言基于该事实:

    • Wikipedia cites that Toronto is the capital of Ontario
    • Toronto is the capital of Ontario

      不过,Government of Ontario claims that Toronto is the capital of Ontario 的声明没有前两个声明的依据充分。

  • VALUE: 属性,例如 Simple WikipediaTitanic (1997 film)

  • CITATION_THRESHOLD:一个介于 0 到 1 之间的浮点值,用于确定是否必须为候选答案中的断言引用事实。阈值越高,引用量越少,但引用质量越高;阈值越低,引用量越多,但引用质量越低。如果未设置,默认阈值为 0.6

Python

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

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

from google.cloud import discoveryengine_v1 as discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"

client = discoveryengine.GroundedGenerationServiceClient()

# The full resource name of the grounding config.
# Format: projects/{project_id}/locations/{location}/groundingConfigs/default_grounding_config
grounding_config = client.grounding_config_path(
    project=project_id,
    location="global",
    grounding_config="default_grounding_config",
)

request = discoveryengine.CheckGroundingRequest(
    grounding_config=grounding_config,
    answer_candidate="Titanic was directed by James Cameron. It was released in 1997.",
    facts=[
        discoveryengine.GroundingFact(
            fact_text=(
                "Titanic is a 1997 American epic romantic disaster movie. It was directed, written,"
                " and co-produced by James Cameron. The movie is about the 1912 sinking of the"
                " RMS Titanic. It stars Kate Winslet and Leonardo DiCaprio. The movie was released"
                " on December 19, 1997. It received positive critical reviews. The movie won 11 Academy"
                " Awards, and was nominated for fourteen total Academy Awards."
            ),
            attributes={"author": "Simple Wikipedia"},
        ),
        discoveryengine.GroundingFact(
            fact_text=(
                'James Cameron\'s "Titanic" is an epic, action-packed romance'
                "set against the ill-fated maiden voyage of the R.M.S. Titanic;"
                "the pride and joy of the White Star Line and, at the time,"
                "the largest moving object ever built. "
                'She was the most luxurious liner of her era -- the "ship of dreams" -- '
                "which ultimately carried over 1,500 people to their death in the "
                "ice cold waters of the North Atlantic in the early hours of April 15, 1912."
            ),
            attributes={"author": "Simple Wikipedia"},
        ),
    ],
    grounding_spec=discoveryengine.CheckGroundingSpec(citation_threshold=0.6),
)

response = client.check_grounding(request=request)

# Handle the response
print(response)

事实示例

以下是一些事实及其属性的示例。以下示例可帮助您了解基准响应和 curl 命令的格式

  • 事实 0

    • 文本:"Titanic is a 1997 American epic romantic disaster movie. It was directed, written, and co-produced by James Cameron. The movie is about the 1912 sinking of the RMS Titanic. It stars Kate Winslet and Leonardo DiCaprio. The movie was released on December 19, 1997. It received positive critical reviews. The movie won 11 Academy Awards, and was nominated for fourteen total Academy Awards."

    • 属性:{"Author": "Simple Wikipedia"}

  • 事实 1

    • 文本:"James Cameron's "Titanic" is an epic, action-packed romance set against the ill-fated maiden voyage of the R.M.S. Titanic; the pride and joy of the White Star Line and, at the time, the largest moving object ever built. She was the most luxurious liner of her era -- the "ship of dreams" -- which ultimately carried over 1,500 people to their death in the ice cold waters of the North Atlantic in the early hours of April 15, 1912."

    • 属性:{"Author": "Rotten Tomatoes"}

示例请求

准备好事实后,您可以发送以下请求,将 CANDIDATE 字段,其中包含您想要关联其依据的不同字符串 检查。

    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/groundingConfigs/default_grounding_config:check" \
    -d '{
    "answerCandidate": "CANDIDATE",
    "facts": [
     {
      "factText": "Titanic is a 1997 American epic romantic disaster movie. It was directed, written, and co-produced by James Cameron. The movie is about the 1912 sinking of the RMS Titanic. It stars Kate Winslet and Leonardo DiCaprio. The movie was released on December 19, 1997. It received positive critical reviews. The movie won 11 Academy Awards, and was nominated for fourteen total Academy Awards.",
      "attributes": {"author":"Simple Wikipedia"}
     },
     {
      "factText": "James Cameron's \"Titanic\" is an epic, action-packed romance set against the ill-fated maiden voyage of the R.M.S. Titanic; the pride and joy of the White Star Line and, at the time, the largest moving object ever built. She was the most luxurious liner of her era -- the \"ship of dreams\" -- which ultimately carried over 1,500 people to their death in the ice cold waters of the North Atlantic in the early hours of April 15, 1912.",
      "attributes": {"author":"Simple Wikipedia"}
     }
    ],
    "groundingSpec": {
      "citationThreshold": "0.6"
    }
    }'

候选答案和依据标准的回复示例

下表根据示例事实,展示了在您发送示例请求时,不同答案候选和响应的示例。

答案候选 Check Grounding 响应
Here is what I found. Titanic was directed by James Cameron. 支持得分:0.99

引用的数据块:
  1. [From FACT 0]....Titanic is a 1997 American epic romantic disaster movie. It was directed, written, and co-produced by James Cameron. It stars Kate Winslet and Leonardo DiCaprio. The movie was released on December 19, 1997. It received positive critical reviews. The movie won 11 Academy Awards, and was nominated for fourteen total Academy Awards.....
版权主张和引用:
  • 0。Here is what I found.
    需要进行依据检查:false
  • 1. Titanic was directed by James Cameron.
    引用数:[0]
    需要进行依据核查:true
Titanic was directed by James Cameron. It was released in 1997. 支持分数:0.99

引用的代码段:
  1. [From FACT 0]....Titanic is a 1997 American epic romantic disaster movie. It was directed, written, and co-produced by James Cameron. It stars Kate Winslet and Leonardo DiCaprio. The movie was released on December 19, 1997. It received positive critical reviews. The movie won 11 Academy Awards, and was nominated for fourteen total Academy Awards.....
  2. [From FACT 1]...Titanic is an epic, action-packed romance set against the ill-fated maiden voyage of the R.M.S. Titanic; the pride and joy of the White Star Line and, at the time, the largest moving object ever built. She was the most luxurious liner of her era which ultimately carried over 1,500 people to their death in the ice cold waters of the North Atlantic in the early hours of April 15, 1912....
版权主张和引用:
  • 0。Titanic was directed by James Cameron.
    引用数:[0]
    需要进行依据核查:true
  • 1. It was released in 1997.
    引用数:[1]
    需要进行依据核查:true
Titanic was directed by James Cameron. It was based on the sinking of the RMS Titanic that led to the death of 1500 people. 支持得分:0.95

引用的数据块:
  1. [From FACT 0]....Titanic is a 1997 American epic romantic disaster movie. It was directed, written, and co-produced by James Cameron. It stars Kate Winslet and Leonardo DiCaprio. The movie was released on December 19, 1997. It received positive critical reviews. The movie won 11 Academy Awards, and was nominated for fourteen total Academy Awards.....
  2. [From FACT 1]...Titanic is an epic, action-packed romance set against the ill-fated maiden voyage of the R.M.S. Titanic; the pride and joy of the White Star Line and, at the time, the largest moving object ever built. She was the most luxurious liner of her era which ultimately carried over 1,500 people to their death in the ice cold waters of the North Atlantic in the early hours of April 15, 1912....
声明和引用:
  • 0。Cited chunks: Titanic was directed by James Cameron.
    引用:[0]
    需要进行依据核查:true
  • 1. Cited chunks: It was based on the sinking of the RMS Titanic that led to the death of 1500 people.
    参考文献:[1]
    需要进行接地检查:true
Titanic was directed by James Cameron. It starred Brad Pitt and Kate Winslet 支持得分:0.54

引用的数据块:
  1. [From FACT 0]....Titanic is a 1997 American epic romantic disaster movie. It was directed, written, and co-produced by James Cameron. It stars Kate Winslet and Leonardo DiCaprio. The movie was released on December 19, 1997. It received positive critical reviews. The movie won 11 Academy Awards, and was nominated for fourteen total Academy Awards.....
  2. [From FACT 1]...Titanic is an epic, action-packed romance set against the ill-fated maiden voyage of the R.M.S. Titanic; the pride and joy of the White Star Line and, at the time, the largest moving object ever built. She was the most luxurious liner of her era which ultimately carried over 1,500 people to their death in the ice cold waters of the North Atlantic in the early hours of April 15, 1912....
声明和引用:
  • 0。Titanic was directed by James Cameron.
    引用数:[0]
    需要进行依据核查:true
  • 1. It starred Brad Pitt and Kate Winslet
    引用数:[]
    需要进行依据核查:true
注意:尽管凯特·温斯莱特在本部中出演过这部电影,但由于 声明 "It starred Brad Pitt and Kate Winslet" 不 完全正确,则不会被引用。在这种情况下,您可以调用 方法并启用反引用功能,从而给出矛盾分数。 如需了解详情,请参阅获取答案候选项的矛盾得分

获取答案候选项的矛盾得分

除了支持得分之外,您还可以获得矛盾得分。矛盾得分大致相当于与所提供事实相矛盾的声明所占的比例。

如需试用此实验性功能,请与您的 Google 客户支持团队联系,请求将您添加到许可名单。

如需获取矛盾得分,请按以下步骤操作:

  1. 准备好您的事实信息。如需了解详情和示例,请参阅定义和说明的术语

  2. 使用以下 curl 命令调用 check 方法:

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1alpha/projects/PROJECT_ID/locations/global/groundingConfigs/default_grounding_config:check" \
    -d '{
    "answerCandidate": "CANDIDATE",
    "facts": [
     {
      "factText": "TEXT_0",
      "attributes": {"ATTRIBUTE_A": "VALUE_A0","ATTRIBUTE_B": "VALUE_B0"}
     },
     {
      "factText": "TEXT_1",
      "attributes": {"ATTRIBUTE_A": "VALUE_A1","ATTRIBUTE_B": "VALUE_B1"}
     },
     {
      "factText": "TEXT_2",
      "attributes": {"ATTRIBUTE_A": "VALUE_A2","ATTRIBUTE_B": "VALUE_B2"}
     },
    ],
    "groundingSpec": {
      "citationThreshold": "CITATION_THRESHOLD",
      "enableAntiCitations": "ENABLE_ANTI_CITATION",
      "antiCitationThreshold": "ANTI_CITATION_THRESHOLD",
    }
    }'
    

    替换以下内容:

    • PROJECT_ID:您的 Google Cloud 项目。

    • CANDIDATE:您要获取支持得分的候选回答字符串,例如 Titanic was directed by James Cameron. It was released in 1997.。候选回答的长度不得超过 4096 个令牌。

    • TEXT:要使用的文本段 表示依据,例如 Titanic is a 1997 American epic... Academy Awards.(请参阅事实示例中的完整内容。)

    • ATTRIBUTE:元数据的名称 与事实相关联的属性,例如 authortitle。这是用户定义的标签,用于向事实文本添加更多信息。例如,如果事实文本 Toronto is the capital of Ontario 具有 author 属性,且其值为 Wikipedia,则以下断言是合理的:

      • Wikipedia cites that Toronto is the capital of Ontario
      • Toronto is the capital of Ontario

      不过,关于 Government of Ontario claims that Toronto is the capital of Ontario 的说法缺乏充分依据。

    • VALUE: 属性,例如 Simple WikipediaTitanic (1997 film)

    • CITATION_THRESHOLD:一个介于 0 到 1 之间的浮点值,用于确定是否必须为候选答案中的断言引用事实。阈值越高,用于支持声明的引用就越少,但引用的质量越高;阈值越低,用于支持声明的引用就越多,但引用的质量越低。如果未设置,默认阈值为 0.6。

    • ENABLE_ANTI_CITATION:一个布尔值。设置此项 字段设置为 true,以启用实验性功能来评估 矛盾分数。移除此字段或将此字段设置为“false” 关闭此功能。

    • ANTI_CITATION_THRESHOLD:0 之间的浮点值 根据第 1 项到第 1 项的顺序,即可确定是否必须将某项事实陈述为与 声明。阈值越高,则越少, 与陈述相抵触的引用较多,阈值越低 引用较多但较弱的引用,与主张相矛盾。如果未设置,默认阈值为 0.8。

请求示例

利用上一部分中的事实示例,您可以 发送以下请求。将 CANDIDATE 字段替换为您要检查其依据和矛盾的不同字符串。

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1alpha/projects/PROJECT_ID/locations/global/groundingConfigs/default_grounding_config:check" \
    -d '{
    "answerCandidate": "CANDIDATE",
    "facts": [
     {
      "factText": "Titanic is a 1997 American epic romantic disaster movie. It was directed, written, and co-produced by James Cameron. The movie is about the 1912 sinking of the RMS Titanic. It stars Kate Winslet and Leonardo DiCaprio. The movie was released on December 19, 1997. It received positive critical reviews. The movie won 11 Academy Awards, and was nominated for fourteen total Academy Awards.",
      "attributes": {"author":"Simple Wikipedia"}
     },
     {
      "factText": "James Cameron's \"Titanic\" is an epic, action-packed romance set against the ill-fated maiden voyage of the R.M.S. Titanic; the pride and joy of the White Star Line and, at the time, the largest moving object ever built. She was the most luxurious liner of her era -- the \"ship of dreams\" -- which ultimately carried over 1,500 people to their death in the ice cold waters of the North Atlantic in the early hours of April 15, 1912.",
      "attributes": {"author":"Simple Wikipedia"}
     }
    ],
    "groundingSpec": {
      "citationThreshold": "0.6",
      "enableAntiCitations": true,
      "antiCitationThreshold": "0.8",
    }
    }'

包含矛盾的回答示例

下表显示了在您发送示例请求时,系统根据示例事实生成的示例候选回答及其响应。

答案候选 Check Grounding 响应
Titanic was directed by James Cameron. It starred Brad Pitt and Kate Winslet 支持得分:0.36

冲突分数:0.49

引用的数据块:
  1. [From FACT 0]....Titanic is a 1997 American epic romantic disaster movie. It was directed, written, and co-produced by James Cameron. It stars Kate Winslet and Leonardo DiCaprio. The movie was released on December 19, 1997. It received positive critical reviews. The movie won 11 Academy Awards, and was nominated for fourteen total Academy Awards.....
  2. [From FACT 1]...Titanic is an epic, action-packed romance set against the ill-fated maiden voyage of the R.M.S. Titanic; the pride and joy of the White Star Line and, at the time, the largest moving object ever built. She was the most luxurious liner of her era which ultimately carried over 1,500 people to their death in the ice cold waters of the North Atlantic in the early hours of April 15, 1912....
声明和引用:
  • 0。Titanic was directed by James Cameron.
    引用数:[0] 反引用次数:[]
    需要进行依据检查:true
  • 1. It starred Brad Pitt and Kate Winslet
    引用数:[] 反引用次数:[0]
    需要进行依据核查:true

获取候选答案的声明级得分

除了答案级支持得分之外,您还可以为候选答案中的每个断言获取断言级支持得分。

如需试用此实验性功能,请与您的 Google 客户支持团队联系,请求将您添加到许可名单。

如需获取声明级得分,请按以下步骤操作:

  1. 准备一组事实。如需了解详情和示例,请参阅定义和说明的术语

  2. 使用以下 curl 命令调用 check 方法:

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1alpha/projects/PROJECT_ID/locations/global/groundingConfigs/default_grounding_config:check" \
    -d '{
    "answerCandidate": "CANDIDATE",
    "facts": [
     {
      "factText": "TEXT_0",
      "attributes": {"ATTRIBUTE_A": "VALUE_A0","ATTRIBUTE_B": "VALUE_B0"}
     },
     {
      "factText": "TEXT_1",
      "attributes": {"ATTRIBUTE_A": "VALUE_A1","ATTRIBUTE_B": "VALUE_B1"}
     },
     {
      "factText": "TEXT_2",
      "attributes": {"ATTRIBUTE_A": "VALUE_A2","ATTRIBUTE_B": "VALUE_B2"}
     },
    ],
    "groundingSpec": {
      "citationThreshold": "CITATION_THRESHOLD",
      "enableClaimLevelScore": "ENABLE_CLAIM_LEVEL_SCORE",
    }
    }'
    

    替换以下内容:

    • PROJECT_ID:您的 Google Cloud 项目。

    • CANDIDATE:您要获取支持得分的候选回答字符串,例如 Titanic was directed by James Cameron. It was released in 1997.。候选回答的长度不得超过 4096 个令牌。

    • TEXT:要使用的文本段 表示依据,例如 Titanic is a 1997 American epic... Academy Awards.(请参阅事实示例中的完整内容。)

    • ATTRIBUTE:元数据的名称 与事实相关联的属性,例如 authortitle。它 是用户定义的标签,用于向事实文本中添加更多信息。例如,如果事实文本 Toronto is the capital of Ontario 具有 author 属性,且其值为 Wikipedia,则以下断言是合理的:

      • Wikipedia cites that Toronto is the capital of Ontario
      • Toronto is the capital of Ontario

      不过,关于 Government of Ontario claims that Toronto is the capital of Ontario 的说法缺乏充分依据。

    • VALUE: 属性,例如 Simple WikipediaTitanic (1997 film)

    • CITATION_THRESHOLD:介于 0 到 1 之间的浮点值 可确定回答中是否必须引用某项事实 。阈值越高,对以下内容的引用越少,但对 可为陈述提供佐证,而较低的阈值会导致引用数量较多但效果较差 来佐证声明。如果未设置,默认阈值为 0.6。

    • ENABLE_CLAIM_LEVEL_SCORE:布尔值。将此字段设置为 true 可启用版权主张级得分功能。关闭 移除此字段或将此字段设置为 false

请求示例

使用上一部分中的示例事实,您可以发送以下请求。将 CANDIDATE 字段替换为 您想要检查其每项声明依据的不同字符串。

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1alpha/projects/PROJECT_ID/locations/global/groundingConfigs/default_grounding_config:check" \
    -d '{
    "answerCandidate": "CANDIDATE",
    "facts": [
     {
      "factText": "Titanic is a 1997 American epic romantic disaster movie. It was directed, written, and co-produced by James Cameron. The movie is about the 1912 sinking of the RMS Titanic. It stars Kate Winslet and Leonardo DiCaprio. The movie was released on December 19, 1997. It received positive critical reviews. The movie won 11 Academy Awards, and was nominated for fourteen total Academy Awards.",
      "attributes": {"author":"Simple Wikipedia"}
     },
     {
      "factText": "James Cameron's \"Titanic\" is an epic, action-packed romance set against the ill-fated maiden voyage of the R.M.S. Titanic; the pride and joy of the White Star Line and, at the time, the largest moving object ever built. She was the most luxurious liner of her era -- the \"ship of dreams\" -- which ultimately carried over 1,500 people to their death in the ice cold waters of the North Atlantic in the early hours of April 15, 1912.",
      "attributes": {"author":"Simple Wikipedia"}
     }
    ],
    "groundingSpec": {
      "citationThreshold": "0.6",
      "enableClaimLevelScore": true,
    }
    }'

带有声明级得分的响应示例

下表显示了在您发送示例请求时,系统根据示例事实生成的示例候选回答及其响应。

答案候选 Check Grounding 响应
Here is what I found. Titanic was directed by James Cameron. It starred Kate Winslet and Leonardo DiCaprio. 支持得分:0.99

引用的数据块:
  1. [From FACT 0]....Titanic is a 1997 American epic romantic disaster movie. It was directed, written, and co-produced by James Cameron. It stars Kate Winslet and Leonardo DiCaprio. The movie was released on December 19, 1997. It received positive critical reviews. The movie won 11 Academy Awards, and was nominated for fourteen total Academy Awards.....
版权主张和引用:
  • 0。Here is what I found.
    需要进行依据检查:false
  • 1. Titanic was directed by James Cameron.
    参考文献:[0]
    需要进行基准测试:true
    得分:0.99
  • 2. It starred Kate Winslet and Leonardo DiCaprio.
    引用数:[0]
    需要进行依据核查:true
    得分:0.99