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

Llama-index模块导入问题求助:无法导入GPTVectorStoreIndex

修复Llama-index模块导入错误方案

核心原因

Llama-index(曾用名GPT Index)在v0.8.0及以上版本中,GPTVectorStoreIndex已被重命名为VectorStoreIndex,同时多个模块的导入路径也做了调整,这是导致导入失败的直接原因。

修复步骤

1. 检查并升级llama-index版本

先查看当前安装的版本:

pip show llama-index

若版本低于v0.8.0,升级到最新稳定版:

pip install --upgrade llama-index

2. 调整导入代码

将原导入代码替换为适配新版本的写法:

from llama_index import (
    VectorStoreIndex,  # 替换原GPTVectorStoreIndex
    LLMPredictor,
    PromptHelper,
    ServiceContext,
    SimpleDirectoryReader,
    StorageContext,
    load_index_from_storage,
)
from llama_index.llms.mock import MockLLMPredictor  # 路径调整:llm_predictor.mock → llms.mock
from llama_index.node_parser import SimpleNodeParser  # 路径调整:nodes.parser → node_parser
from llama_index.response_synthesizers import SimpleOutputFormatter  # 路径调整:response.formatting → response_synthesizers

3. 代码逻辑适配

如果代码中有实例化GPTVectorStoreIndex的语句,比如:

index = GPTVectorStoreIndex.from_documents(documents)

需要改为:

index = VectorStoreIndex.from_documents(documents)

额外排查点

  • 确认虚拟环境:若使用虚拟环境,确保激活的环境是安装llama-index的环境,避免多环境版本冲突。
  • 清理缓存:执行pip cache purge后重新安装llama-index,排除旧版本缓存干扰。

内容的提问来源于stack exchange,提问作者krun.03

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 18:43:10