You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vertex AI中Google Search Grounding动态检索配置阈值设置报错求助

Vertex AI中Google Search Grounding阈值配置问题解决

你当前的基础代码可正常初始化Google Search检索工具,但尝试用字典配置阈值时出错,核心原因是Tool.from_google_search_retrieval方法仅接受grounding.GoogleSearchRetrieval实例作为参数,而非直接传入字典配置。

正确的配置方式是通过grounding.GroundingConfig类构造阈值等参数,再传入GoogleSearchRetrieval实例中,示例代码如下:

from vertexai.generative_models import Tool, grounding

# 构造带阈值配置的检索实例
search_retrieval = grounding.GoogleSearchRetrieval(
    grounding_config=grounding.GroundingConfig(
        threshold=0.7,  # 替换为你需要的阈值(范围0-1)
        max_references=3  # 可选:设置返回的最大参考结果数量
    )
)

# 生成检索工具
tool = Tool.from_google_search_retrieval(search_retrieval)

# 调用模型生成内容(注意tools参数需传入列表)
responses = model.generate_content(
    prompt,
    tools=[tool],
    generation_config=self.generation_config
)

另外需要注意:原代码中tools=tool不符合参数要求,generate_content的tools参数需要传入工具列表,因此需改为tools=[tool],否则可能引发类型错误。

内容的提问来源于stack exchange,提问作者Will

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 11:43:15