6

I am getting an ImportError while using GPTSimpleVectorIndex from the llama-index library. Have installed the latest version of llama-index library and trying to run it on python 3.9.

from llama_index import GPTSimpleVectorIndex, SimpleDirectoryReader, LLMPredictor, PromptHelper, ServiceContext
ImportError: cannot import name 'GPTSimpleVectorIndex' from 'llama_index' (E:\Experiments\OpenAI\data anaysis\llama-index-main\venv\lib\site-packages\llama_index\__init__.py

The source code is given below,

import os, streamlit as st

from llama_index import GPTVectorStoreIndex, SimpleDirectoryReader, LLMPredictor, PromptHelper, ServiceContext
from langchain.llms.openai import OpenAI

6 Answers 6

10

Try use GPTVectorStoreIndex instead of GPTSimpleVectorIndex:

from llama_index import GPTVectorStoreIndex, ..
Sign up to request clarification or add additional context in comments.

Comments

5

As per llama_index 0.8.40, GPTSimpleVectorIndex is deprecated and replaced by VectorStoreIndex.

To do a query, you need to change from index.query to

query_enginge = index.as_query_engine()
response = query_engine.query("My query")

1 Comment

This should be the accepted answer as it describes how to query the VectorStroreIndex. Note there is a typo in the example: it should be query_engine.
2

As mentioned in issue, GPTSimpleVectorIndex was renamed to GPTVectorStoreIndex, try removing it from the end of your imports. So you can simply import it as mentioned by RadoTheProgrammer above.

Before

from llama_index import GPTSimpleVectorIndex

After

from llama_index import GPTVectorStoreIndex

Comments

0

I replaced GPTSimpleVectorIndex , GPTVectorStoreIndex

documents = SimpleDirectoryReader('../news').load_data()
index = GPTVectorStoreIndex.from_documents(documents)

query_engine = index.as_query_engine()
r = query_engine.query("how did the pandemic effect business")
print(r)

the version of llama_index used was llama-index==0.9.4

Comments

0

Even though i installed llama_index (not core). I still was able to use it only after accessing it from core. Is confusing that they have seperated the two and you still have to depend on core. They've stated the difference here https://pypi.org/project/llama-index/

from llama_index.core import GPTVectorStoreIndex

Comments

-3

you should change GPTSimpleVectorIndex to GPTVectorStoreIndex. this work for me.

1 Comment

Don't the existing answers already cover this? Please don't repeat answers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.