Haystack raises "cannot import name 'MODEL_TO_ENCODING' from 'tiktoken.model"

489 views Asked by At

i am trying to build a Q&A System using haystack. I am following this tutorial.

When I try to import certain modules. e.g.:

from haystack.document_stores import ElasticsearchDocumentStore

I get:

ImportError: cannot import name 'MODEL_TO_ENCODING' from 'tiktoken.model' (c:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\tiktoken\model.py)

Tried reinstalling haystack in iteration (big, medium large). Tried different devices. Is this a problem with the library itself? OS is windows.

Tried reinstalling the library, tried running python with and without venv.

1

There are 1 answers

1
Julian Risch On

The current fix is to pin the tiktoken version that is installed to the following:

pip install tiktoken>=0.3.2,<0.5.0"

There was a tiktoken release 0.5.0 a few hours ago that had a breaking change causing a problem with Haystack just as you reported. Pinning the installed version of tiktoken to any earlier version solves it. The team behind Haystack is preparing a patch release as we speak so if you install Haystack in a fresh environment in a few hours it should automatically install the patch version 1.20.1 and the error should be gone.