8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

Last updated at Posted at 2024-03-03

Pythonのllama_indexでエラーが出た解決方法について。
バージョンがllama_index v0.10.0以上の場合は書き方を変える必要があった。

出てたエラー

from llama_index import SimpleDirectoryReader, ServiceContext, GPTSimpleVectorIndex, LLMPredictor
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-30-7f97f81316cf> in <cell line: 1>()
----> 1 from llama_index import SimpleDirectoryReader, ServiceContext, GPTSimpleVectorIndex, LLMPredictor

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

from llama_index import GPTVectorStoreIndex, ServiceContext
from llama_index.llms import OpenAI
# from llama_index.callbacks import CallbackManager, LlamaDebugHandler
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-29-0a68ce9db5aa> in <cell line: 1>()
----> 1 from llama_index import GPTVectorStoreIndex, ServiceContext
      2 from llama_index.llms import OpenAI
      3 # from llama_index.callbacks import CallbackManager, LlamaDebugHandler

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

from llama_index import LLMPredictor, ServiceContext, SQLDatabase, VectorStoreIndex
from llama_index.indices.struct_store import SQLTableRetrieverQueryEngine
from llama_index.objects import SQLTableNodeMapping, ObjectIndex, SQLTableSchema
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-31-83f4868ef00c> in <cell line: 1>()
----> 1 from llama_index import LLMPredictor, ServiceContext, SQLDatabase, VectorStoreIndex
      2 from llama_index.indices.struct_store import SQLTableRetrieverQueryEngine
      3 from llama_index.objects import SQLTableNodeMapping, ObjectIndex, SQLTableSchema

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

解決方法

  • llama_index v0.10.0以前の書き方
from llama_index import SimpleDirectoryReader, ServiceContext, GPTSimpleVectorIndex, LLMPredictor
  • llama_index v0.10.0以降の書き方

参考

from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.core import ServiceContext, SQLDatabase, VectorStoreIndex
from llama_index.core.indices.struct_store import SQLTableRetrieverQueryEngine
from llama_index.core.objects import SQLTableNodeMapping, ObjectIndex, SQLTableSchema
from llama_index.legacy import LLMPredictor
8
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?