pythonpython-3.xllama-index

How to properly import llama-index classes?


Recently I making some PoCs using Llama Index.

I'm following the documentation in order to use routing features for different indexes. I made two indexes and I want to use SubQueryEngine to route the query engines that I have created.

In the tutorial, we have the following example of imports:

from llama_index import GPTVectorStoreIndex, SimpleDirectoryReader
from llama_index.tools import QueryEngineTool, ToolMetadata
from llama_index.query_engine import SubQuestionQueryEngine

But when I run my example, I'm not able to import ToolMetadata neither SubQuestionQueryEngine. I got the following error:

ImportError: cannot import name 'SubQuestionQueryEngine' from 'llama_index.query_engine'

Does anybody know what possible can be the problem? The other imports work normaly and I was able to run examples using GPTVectorStoreIndex class.

I'm using Python 3.10.11


Solution

  • Please provide the version of llama-index that you are using.

    A simple fix would be: pip install -U llama-index. I frequently encounter issues due to the continuous updates of the library. I would suggest updating it every day just to make sure you are using the latest version.