ImportError: cannot import name 'GPTSimpleVectorIndex' from 'llama_index'
Asked Answered
M

6

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
Mcvay answered 9/7, 2023 at 4:26 Comment(0)
C
10

Try use GPTVectorStoreIndex instead of GPTSimpleVectorIndex:

from llama_index import GPTVectorStoreIndex, ..
Campanulaceous answered 9/7, 2023 at 5:18 Comment(0)
C
4

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")
Calefacient answered 6/10, 2023 at 16:4 Comment(1)
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.Schurman
D
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
Dug answered 8/8, 2023 at 19:39 Comment(0)
S
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

Swiger answered 21/11, 2023 at 18:24 Comment(0)
O
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
Overview answered 20/9 at 17:23 Comment(0)
S
-3

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

Siusan answered 16/11, 2023 at 6:42 Comment(1)
Don't the existing answers already cover this? Please don't repeat answers.Veg

© 2022 - 2024 — McMap. All rights reserved.