Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name 'VectorStoreIndex' from 'llama_index' (unknown location)

I ran into this problem when I was trying to import the following libraries and it is giving the error "ImportError: cannot import name 'VectorStoreIndex' from 'llama_index' (unknown location)"

I ran this exact same code in the morning and it worked perfectly.

I did !pip install llama_index

from llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext
from llama_index.llms import HuggingFaceLLM
from llama_index.prompts.prompts import SimpleInputPrompt

I tried commenting out first line and faced same issue for HuggingFaceLLM module Same issue for SimpleInputPrompt, got error "ModuleNotFoundError: No module named 'llama_index.prompts'"

First I faced the problem in a sagemaker notebook so I thought the issue was with the sagemaker notebook so I spun up a clean new notebook and I got the same error. So, I tried the code in my local Jypiter notebook, google collab notebook, sagemaker studiolab notebook and I got the same error.

like image 570
lat Avatar asked Dec 12 '25 18:12

lat


1 Answers

The llama index library was recently updated so I was able to solve the issue by using updating the import according to the documentation

from llama_index.core import VectorStoreIndex,SimpleDirectoryReader,ServiceContext,PromptTemplate
from llama_index.llms.huggingface import HuggingFaceLLM

https://docs.llamaindex.ai/en/stable/examples/customization/llms/SimpleIndexDemo-Huggingface_stablelm.html

like image 185
lat Avatar answered Dec 14 '25 08:12

lat