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
相关产品推荐
相关产品推荐

