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

初始化Vertex AI匹配引擎客户端时遇AttributeError错误求助

解决Vertex AI匹配引擎客户端初始化AttributeError问题

初始化Vertex AI匹配引擎客户端时出现AttributeError: module 'google.cloud.aiplatform.gapic' has no attribute 'MatchingEngineServiceClient',原因是该客户端类的导入路径在新版google-cloud-aiplatform库中已变更。以下是具体解决步骤:

  • 升级依赖库版本
    旧版本库的客户端类位置已调整,先安装最新版google-cloud-aiplatform:

    pip install --upgrade google-cloud-aiplatform
    
  • 使用正确的客户端导入与初始化代码
    新版库中,匹配引擎客户端需从aiplatform_v1模块导入,代码示例:

    from google.cloud.aiplatform_v1 import MatchingEngineServiceClient
    
    # 初始化客户端
    client = MatchingEngineServiceClient()
    

    若需要结合Vertex AI主模块使用,也可同时导入google.cloud.aiplatform进行项目、区域等基础配置。

  • 验证客户端功能
    可通过调用客户端基础方法验证是否初始化成功,例如列出当前项目下的匹配引擎索引:

    project_id = "你的项目ID"
    location = "us-central1"
    parent = f"projects/{project_id}/locations/{location}"
    
    for index in client.list_indexes(parent=parent):
        print(index.name)
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 05:52:02