Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: ImportError: cannot import name 'BaseRetriever' from partially initialized module 'llama_index.core.base.base_retriever' #13411

Closed
ForgetThatNight opened this issue May 10, 2024 · 2 comments
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized

Comments

@ForgetThatNight
Copy link

Bug Description

Traceback (most recent call last):
File "/data/env/anaconda3/lib/python3.10/site-packages/llama_index/core/base/base_retriever.py", line 30, in
from llama_index.core.service_context import ServiceContext
File "/data/env/anaconda3/lib/python3.10/site-packages/llama_index/core/service_context.py", line 11, in
from llama_index.core.indices.prompt_helper import PromptHelper
File "/data/env/anaconda3/lib/python3.10/site-packages/llama_index/core/indices/init.py", line 4, in
from llama_index.core.indices.composability.graph import ComposableGraph
File "/data/env/anaconda3/lib/python3.10/site-packages/llama_index/core/indices/composability/init.py", line 4, in
from llama_index.core.indices.composability.graph import ComposableGraph
File "/data/env/anaconda3/lib/python3.10/site-packages/llama_index/core/indices/composability/graph.py", line 7, in
from llama_index.core.indices.base import BaseIndex
File "/data/env/anaconda3/lib/python3.10/site-packages/llama_index/core/indices/base.py", line 8, in
from llama_index.core.base.base_retriever import BaseRetriever
ImportError: cannot import name 'BaseRetriever' from partially initialized module 'llama_index.core.base.base_retriever' (most likely due to a circular import) (/data/env/anaconda3/lib/python3.10/site-packages/llama_index/core/base/base_retriever.py)

Version

0.10.34

Steps to Reproduce

from llama_index.core.base.base_retriever import BaseRetriever

llama-hub 0.0.79.post1
llama-index 0.10.34
llama-index-agent-openai 0.1.7
llama-index-cli 0.1.12
llama-index-core 0.10.34
llama-index-embeddings-openai 0.1.9
llama-index-indices-managed-llama-cloud 0.1.6
llama-index-legacy 0.9.48
llama-index-llms-openai 0.1.16
llama-index-multi-modal-llms-openai 0.1.5
llama-index-program-openai 0.1.6
llama-index-question-gen-openai 0.1.3
llama-index-readers-file 0.1.19
llama-index-readers-llama-parse 0.1.4
llama-parse 0.4.2
llamaindex-py-client 0.1.19

Relevant Logs/Tracbacks

No response

@ForgetThatNight ForgetThatNight added bug Something isn't working triage Issue needs to be triaged/prioritized labels May 10, 2024
Copy link

dosubot bot commented May 10, 2024

To address the ImportError due to a circular import involving BaseRetriever, you can try the following strategies:

  1. Refactor Your Code: Aim to eliminate the circular dependency by reorganizing your modules and packages.
  2. Lazy Import Inside Functions: Move the BaseRetriever import statement inside the function or method that requires it, delaying the import until necessary.
  3. Consolidate Imports: If feasible, combine related classes and functions into a single module to avoid circular dependencies.
  4. Use Import Hooks: This advanced solution involves customizing Python's import system to resolve circular imports.
  5. Import Within Type Checking Block: For type annotations, use if TYPE_CHECKING: to ensure imports are only executed by type checkers.
  6. Use from __future__ import annotations: For Python 3.7+, this approach stores annotations as strings, avoiding circular imports due to type annotations.

Additionally, a similar issue was resolved by uninstalling any existing installations of llama-index, creating a new virtual environment, and reinstalling llama-index with specific pip flags. Follow these steps:

pip uninstall llama-index  # remove any possible global install
python -m venv venv
source venv/bin/activate
pip install llama-index --upgrade --no-cache-dir --force-reinstall

Ensure you're not using outdated paths for imports and refer to the latest documentation for correct import statements.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

@logan-markewich
Copy link
Collaborator

The llama-hub package is deprecated, installing that would have maybe caused some issues.

Try again with a fresh venv. Works fine in google colab
https://colab.research.google.com/drive/155DJxHVgDV7exMct-3dkFA4n0fgDQZ_R?usp=sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized
Projects
None yet
Development

No branches or pull requests

2 participants