beir icon indicating copy to clipboard operation
beir copied to clipboard

Importlib.util needs to be directly imported

Open amanchoudhri opened this issue 7 months ago • 0 comments

On Python 3.12, attempting to import DenseRetrievalExactSearch,

from beir.retrieval.search.dense.exact_search import DenseRetrievalExactSearch as DRES

throws an AttributeError:

Traceback (most recent call last):
  File "/workspace/exa-bin-quant/bin_quant/encode.py", line 3, in <module>
    from beir.retrieval.search.dense.exact_search import DenseRetrievalExactSearch as DRES
  File "/workspace/exa-bin-quant/.venv/lib/python3.12/site-packages/beir/retrieval/search/dense/__init__.py", line 3, in <module>
    from .exact_search import DenseRetrievalExactSearch
  File "/workspace/exa-bin-quant/.venv/lib/python3.12/site-packages/beir/retrieval/search/dense/exact_search.py", line 8, in <module>
    if importlib.util.find_spec("faiss") is not None:
       ^^^^^^^^^^^^^^
AttributeError: module 'importlib' has no attribute 'util'

It seems that importlib doesn't expose util by default. See this Python stdlib thread, for example.

amanchoudhri avatar Jul 28 '25 03:07 amanchoudhri