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

Try use ‘GPTVectorStoreIndex’ instead of ‘GPTSimpleVectorIndex’:

from llama_index import GPTVectorStoreIndex, ..

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

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

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

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

1

Your Answer

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