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

使用预构建GCP向量搜索索引调用add_texts时触发Blob属性错误

问题分析与解决方案

错误原因

这个AttributeError: 'Blob' object has no attribute '_prep_and_do_upload'错误源于google-cloud-storage客户端库版本与langchain_google_vertexai 1.0.10不兼容:

  • langchain_google_vertexai 1.0.10依赖的旧版google-cloud-storage(<2.0.0)中,Blob对象存在_prep_and_do_upload方法;
  • 若当前环境安装的是google-cloud-storage 2.0.0及以上版本,该方法已被移除/重命名,导致调用失败;
  • 新建索引时流程正常,是因为新建流程的代码路径未触发批量上传逻辑,而使用预构建索引时触发了该路径,暴露了版本冲突。

解决方案

1. 降级google-cloud-storage到兼容版本

执行以下命令安装与langchain_google_vertexai 1.0.10匹配的存储库版本:

pip install google-cloud-storage==1.44.0

该版本的API逻辑与langchain_google_vertexai 1.0.10的批量上传代码完全兼容,可直接解决方法不存在的问题。

2. 验证存储桶配置与权限

  • 确认gcs_bucket_name参数与预构建向量索引关联的GCS存储桶名称完全一致;
  • 确保运行代码的服务账号拥有该存储桶的storage.objects.create和storage.objects.delete权限(可通过GCP IAM控制台配置)。

3. 可选:升级langchain_google_vertexai到兼容新版本

若不想降级存储库,可尝试升级langchain_google_vertexai到已适配google-cloud-storage 2.0+的新版本(如>=1.2.0):

pip install --upgrade langchain_google_vertexai

升级后需核对代码中的API调用是否有参数或方法变更,需参考官方文档做少量适配。

内容的提问来源于stack exchange,提问作者Simón Cerda

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 21:20:10