.add_faiss_index and .add_elasticsearch_index returns ImportError at Google Colab
NONE
I can fix this.
It's mainly because faiss-gpu requires python<=3.10 but the default python version in colab is 3.11. We just have to downgrade the CPython version down to 3.10 and it should work fine.

2025-03-16T08:34:40Z
https://github.com/huggingface/datasets/issues/7456#issuecomment-2727266641
https://api.github.com/repos/huggingface/datasets/issues/7456
IC_kwDODunzps6ijslR
https://api.github.com/repos/huggingface/datasets/issues/comments/2727266641/reactions
2025-03-16T08:34:40Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2727266641
https://avatars.githubusercontent.com/u/90778800?v=4
https://api.github.com/users/Akshay-Sisodia/events{/privacy}
https://api.github.com/users/Akshay-Sisodia/followers
https://api.github.com/users/Akshay-Sisodia/following{/other_user}
https://api.github.com/users/Akshay-Sisodia/gists{/gist_id}
https://github.com/Akshay-Sisodia
Akshay-Sisodia
MDQ6VXNlcjkwNzc4ODAw
https://api.github.com/users/Akshay-Sisodia/orgs
https://api.github.com/users/Akshay-Sisodia/received_events
https://api.github.com/users/Akshay-Sisodia/repos
https://api.github.com/users/Akshay-Sisodia/starred{/owner}{/repo}
https://api.github.com/users/Akshay-Sisodia/subscriptions
User
https://api.github.com/users/Akshay-Sisodia
public
NONE
I think I just had no chance to meet with faiss-cpu.
It could be import problem? 
_has_faiss gets its value at the beginning of datasets/search.
I tried to call object before import faiss, so _has_faiss took False. And never updated later. 
2025-03-17T10:25:46Z
https://github.com/huggingface/datasets/issues/7456#issuecomment-2728975672
https://api.github.com/repos/huggingface/datasets/issues/7456
IC_kwDODunzps6iqN04
https://api.github.com/repos/huggingface/datasets/issues/comments/2728975672/reactions
2025-03-17T10:25:46Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2728975672
https://avatars.githubusercontent.com/u/109490785?v=4
https://api.github.com/users/MapleBloom/events{/privacy}
https://api.github.com/users/MapleBloom/followers
https://api.github.com/users/MapleBloom/following{/other_user}
https://api.github.com/users/MapleBloom/gists{/gist_id}
https://github.com/MapleBloom
MapleBloom
U_kgDOBoayYQ
https://api.github.com/users/MapleBloom/orgs
https://api.github.com/users/MapleBloom/received_events
https://api.github.com/users/MapleBloom/repos
https://api.github.com/users/MapleBloom/starred{/owner}{/repo}
https://api.github.com/users/MapleBloom/subscriptions
User
https://api.github.com/users/MapleBloom
public
NONE
Yes you can't meet the requirements because faiss-cpu runs only on
python3.10 and lower but the default version for colab is python3.11 which
results in pip not being able to find wheels for faiss-cpu with python3.11.

On Mon, 17 Mar, 2025, 3:56 pm MapleBloom, ***@***.***> wrote:

> I think I just had no chance to meet with faiss-cpu.
> It could be import problem?
> _has_faiss gets its value at the beginning of datasets/search.
> I tried to call object before import faiss, so _has_faiss took False. And
> never updated later.
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/huggingface/datasets/issues/7456#issuecomment-2728975672>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AVUSZMBVD7LEDDUGALOTVN32U2PMBAVCNFSM6AAAAABZDBA426VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMRYHE3TKNRXGI>
> .
> You are receiving this because you commented.Message ID:
> ***@***.***>
> [image: MapleBloom]*MapleBloom* left a comment (huggingface/datasets#7456)
> <https://github.com/huggingface/datasets/issues/7456#issuecomment-2728975672>
>
> I think I just had no chance to meet with faiss-cpu.
> It could be import problem?
> _has_faiss gets its value at the beginning of datasets/search.
> I tried to call object before import faiss, so _has_faiss took False. And
> never updated later.
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/huggingface/datasets/issues/7456#issuecomment-2728975672>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AVUSZMBVD7LEDDUGALOTVN32U2PMBAVCNFSM6AAAAABZDBA426VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMRYHE3TKNRXGI>
> .
> You are receiving this because you commented.Message ID:
> ***@***.***>
>

2025-03-17T10:28:26Z
https://github.com/huggingface/datasets/issues/7456#issuecomment-2728983373
https://api.github.com/repos/huggingface/datasets/issues/7456
IC_kwDODunzps6iqPtN
https://api.github.com/repos/huggingface/datasets/issues/comments/2728983373/reactions
2025-03-17T10:28:26Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2728983373
https://avatars.githubusercontent.com/u/90778800?v=4
https://api.github.com/users/Akshay-Sisodia/events{/privacy}
https://api.github.com/users/Akshay-Sisodia/followers
https://api.github.com/users/Akshay-Sisodia/following{/other_user}
https://api.github.com/users/Akshay-Sisodia/gists{/gist_id}
https://github.com/Akshay-Sisodia
Akshay-Sisodia
MDQ6VXNlcjkwNzc4ODAw
https://api.github.com/users/Akshay-Sisodia/orgs
https://api.github.com/users/Akshay-Sisodia/received_events
https://api.github.com/users/Akshay-Sisodia/repos
https://api.github.com/users/Akshay-Sisodia/starred{/owner}{/repo}
https://api.github.com/users/Akshay-Sisodia/subscriptions
User
https://api.github.com/users/Akshay-Sisodia
public
NONE
> you can't meet the requirements

It is not the case (or I didn't reach this point) because the same code in notebook
```importlib.util.find_spec("faiss")```
finds faiss. I've mention it.
I think the problem is in the very moment when _has_faiss takes its value and never try again. 
(or it couldn't find the path that was easily found when started from my code)
2025-03-17T14:31:31Z
https://github.com/huggingface/datasets/issues/7456#issuecomment-2729737414
https://api.github.com/repos/huggingface/datasets/issues/7456
IC_kwDODunzps6itHzG
https://api.github.com/repos/huggingface/datasets/issues/comments/2729737414/reactions
2025-03-17T14:31:31Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2729737414
https://avatars.githubusercontent.com/u/109490785?v=4
https://api.github.com/users/MapleBloom/events{/privacy}
https://api.github.com/users/MapleBloom/followers
https://api.github.com/users/MapleBloom/following{/other_user}
https://api.github.com/users/MapleBloom/gists{/gist_id}
https://github.com/MapleBloom
MapleBloom
U_kgDOBoayYQ
https://api.github.com/users/MapleBloom/orgs
https://api.github.com/users/MapleBloom/received_events
https://api.github.com/users/MapleBloom/repos
https://api.github.com/users/MapleBloom/starred{/owner}{/repo}
https://api.github.com/users/MapleBloom/subscriptions
User
https://api.github.com/users/MapleBloom
public
NONE
When you run the first cell containing pip install faiss-cpu does it
install it?

On Mon, 17 Mar, 2025, 8:01 pm MapleBloom, ***@***.***> wrote:

> you can't meet the requirements
>
> It is not the case (or I didn't reach this point) because the same code in
> notebook
> importlib.util.find_spec("faiss")
> finds faiss. I've mention it.
> I think the problem is in the very moment when _has_faiss takes its value
> and never try again.
> (or it couldn't find the path that was easily found when started from my
> code)
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/huggingface/datasets/issues/7456#issuecomment-2729737414>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AVUSZMCCE6BPZCOVAWXKIY32U3MFVAVCNFSM6AAAAABZDBA426VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMRZG4ZTONBRGQ>
> .
> You are receiving this because you commented.Message ID:
> ***@***.***>
> [image: MapleBloom]*MapleBloom* left a comment (huggingface/datasets#7456)
> <https://github.com/huggingface/datasets/issues/7456#issuecomment-2729737414>
>
> you can't meet the requirements
>
> It is not the case (or I didn't reach this point) because the same code in
> notebook
> importlib.util.find_spec("faiss")
> finds faiss. I've mention it.
> I think the problem is in the very moment when _has_faiss takes its value
> and never try again.
> (or it couldn't find the path that was easily found when started from my
> code)
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/huggingface/datasets/issues/7456#issuecomment-2729737414>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AVUSZMCCE6BPZCOVAWXKIY32U3MFVAVCNFSM6AAAAABZDBA426VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMRZG4ZTONBRGQ>
> .
> You are receiving this because you commented.Message ID:
> ***@***.***>
>

2025-03-17T14:49:22Z
https://github.com/huggingface/datasets/issues/7456#issuecomment-2729804637
https://api.github.com/repos/huggingface/datasets/issues/7456
IC_kwDODunzps6itYNd
https://api.github.com/repos/huggingface/datasets/issues/comments/2729804637/reactions
2025-03-17T14:49:22Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2729804637
https://avatars.githubusercontent.com/u/90778800?v=4
https://api.github.com/users/Akshay-Sisodia/events{/privacy}
https://api.github.com/users/Akshay-Sisodia/followers
https://api.github.com/users/Akshay-Sisodia/following{/other_user}
https://api.github.com/users/Akshay-Sisodia/gists{/gist_id}
https://github.com/Akshay-Sisodia
Akshay-Sisodia
MDQ6VXNlcjkwNzc4ODAw
https://api.github.com/users/Akshay-Sisodia/orgs
https://api.github.com/users/Akshay-Sisodia/received_events
https://api.github.com/users/Akshay-Sisodia/repos
https://api.github.com/users/Akshay-Sisodia/starred{/owner}{/repo}
https://api.github.com/users/Akshay-Sisodia/subscriptions
User
https://api.github.com/users/Akshay-Sisodia
public
NONE
> When you run the first cell containing pip install faiss-cpu does it
> install it?
> […](#)

Yes. It was installed succesfully. 
Methods of datasets library that depends on _has_faiss constant didn't start to work.
2025-03-17T15:57:18Z
https://github.com/huggingface/datasets/issues/7456#issuecomment-2730047713
https://api.github.com/repos/huggingface/datasets/issues/7456
IC_kwDODunzps6iuTjh
https://api.github.com/repos/huggingface/datasets/issues/comments/2730047713/reactions
2025-03-17T15:57:18Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2730047713
https://avatars.githubusercontent.com/u/109490785?v=4
https://api.github.com/users/MapleBloom/events{/privacy}
https://api.github.com/users/MapleBloom/followers
https://api.github.com/users/MapleBloom/following{/other_user}
https://api.github.com/users/MapleBloom/gists{/gist_id}
https://github.com/MapleBloom
MapleBloom
U_kgDOBoayYQ
https://api.github.com/users/MapleBloom/orgs
https://api.github.com/users/MapleBloom/received_events
https://api.github.com/users/MapleBloom/repos
https://api.github.com/users/MapleBloom/starred{/owner}{/repo}
https://api.github.com/users/MapleBloom/subscriptions
User
https://api.github.com/users/MapleBloom
public
### Describe the bug

At Google Colab
```!pip install faiss-cpu``` works
```import faiss``` no error
but
```embeddings_dataset.add_faiss_index(column='embeddings')```
returns
```
[/usr/local/lib/python3.11/dist-packages/datasets/search.py](https://localhost:8080/#) in init(self, device, string_factory, metric_type, custom_index)
247 self.faiss_index = custom_index
248 if not _has_faiss:
--> 249 raise ImportError(
250 "You must install Faiss to use FaissIndex. To do so you can run conda install -c pytorch faiss-cpu or conda install -c pytorch faiss-gpu. "
251 "A community supported package is also available on pypi: pip install faiss-cpu or pip install faiss-gpu. "
```

because
```_has_faiss = importlib.util.find_spec("faiss") is not None```    at the beginning of ```datasets/search.py``` returns ```False```
when
the same code at colab notebook returns
```ModuleSpec(name='faiss', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7b7851449f50>, origin='/usr/local/lib/python3.11/dist-packages/faiss/init.py', submodule_search_locations=['/usr/local/lib/python3.11/dist-packages/faiss'])```

But
```
import datasets
datasets.search._has_faiss
```
at ```colab notebook``` also returns ```False```

The same story with   ```_has_elasticsearch```

### Steps to reproduce the bug

1. Follow https://huggingface.co/learn/nlp-course/chapter5/6?fw=pt at Google Colab
2. till ```embeddings_dataset.add_faiss_index(column='embeddings')```
3. ```embeddings_dataset.add_elasticsearch_index(column='embeddings')```
4. https://colab.research.google.com/drive/1h2cjuiClblqzbNQgrcoLYOC8zBqTLLcv#scrollTo=3ddzRp72auOF

### Expected behavior

I've only started Tutorial and don't know exactly. But something tells me that ```embeddings_dataset.add_faiss_index(column='embeddings')```
should work without ```Import Error```

### Environment info

Google Colab notebook with default config