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

ImportError: cannot import name 'Document' from 'llama_index' (unknown location) #152

Closed
alokkrsahu opened this issue Feb 21, 2024 · 12 comments

Comments

@alokkrsahu
Copy link

https://github.com/bclavie/RAGatouille/blob/main/ragatouille/data/preprocessors.py

@bclavie
Copy link
Collaborator

bclavie commented Feb 22, 2024

Hey, what version of llama-index are you using? It seems like they've updated some things on their end, will work on a fix! Also related #147

@logan-markewich
Copy link

@bclavie LlamaIndex maintainer here -- v0.10.x is a bit of a breaking change in terms of imports. Let me know if you need a hand with handling any migration :)

@bclavie
Copy link
Collaborator

bclavie commented Feb 22, 2024

Hey @logan-markewich, thanks a lot! I think all we're really using right now is the document splitter & the Document object. I could dig but I assume you're a lot more familiar than I am -- any recommendations in keeping the overall behaviour here with imports compatible with both the new version and older ones?

@logan-markewich
Copy link

Probably just need a try except

try:
  from llama_index import Document
  from llama_index.text_splitter import SentenceSplitter
except ImportError:
  from llama_index.core import Document
  from llama_index.core.text_splitter import SentenceSplitter

That should work for both v0.10.x and older versions

@bclavie
Copy link
Collaborator

bclavie commented Feb 23, 2024

Thanks! Fixed in #155 (0.0.7post5)

@bclavie bclavie closed this as completed Feb 23, 2024
@RibinMTC
Copy link

Hi, I'm encountering the same issue with the error: ImportError: cannot import name 'Document' from 'llama_index.core' (unknown location)
Ragatouille version: 0.0.7.post5
llama-index version: 0.9.48.

@Balavarun5
Copy link

Hi @RibinMTC , I too faced similar issue. Here's how i fixed it

  1. uninstall ragatouille
  2. reinstall with pip install git+https://github.com/bclavie/RAGatouille/
  3. modify the file /path/to/venv/lib/python3.10/site-packages/ragatouille/data/preprocessors.py line 5 to from llama_index.core.schema import Document

@mallahyari
Copy link

you have to remove all the python libraries related to llamaindex (image below) and then install llamaindex again.

image

@logan-markewich
Copy link

Yea, either that or starting with a fresh venv is probably the ideal solution here

@atang31
Copy link

atang31 commented Mar 17, 2024

For me I just had to make sure setuptools is also required.
ragatouille: 0.0.7.post11
llama-index: 0.9.48

@akshay6893
Copy link

akshay6893 commented Jun 16, 2024

Now the error looks like this -

Plain typing.TypeAlias is not valid as type argument

Just adding it so people searching it will be able to find this thread.

Also, to get it working, I changed ( in the package ) i.e RAGatouille/blob/main/ragatouille/data/preprocessors.py -

From :
from llama_index.core import Document
from llama_index.core.text_splitter import SentenceSplitter

To:

from llama_index.legacy import Document
from llama_index.legacy.text_splitter import SentenceSplitter

@fabiannagel
Copy link

fabiannagel commented Jun 26, 2024

Still running into the ImportError with ragatouille==0.0.8post2. Why don't we narrow down the version of llama-index to reduce the risk of pulling breaking changes? ">=0.7, <=0.10" worked great for me so far.

See this PR: #227

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants