Can we parallelized the add_faiss_index process over dataset shards ?
{'login': 'shamanez', 'id': 16892570, 'node_id': 'MDQ6VXNlcjE2ODkyNTcw', 'avatar_url': 'https://avatars.githubusercontent.com/u/16892570?v=4', 'gravatar_id': '', 'url': 'https://api.github.com/users/shamanez', 'html_url': 'https://github.com/shamanez', 'followers_url': 'https://api.github.com/users/shamanez/followers', 'following_url': 'https://api.github.com/users/shamanez/following{/other_user}', 'gists_url': 'https://api.github.com/users/shamanez/gists{/gist_id}', 'starred_url': 'https://api.github.com/users/shamanez/starred{/owner}{/repo}', 'subscriptions_url': 'https://api.github.com/users/shamanez/subscriptions', 'organizations_url': 'https://api.github.com/users/shamanez/orgs', 'repos_url': 'https://api.github.com/users/shamanez/repos', 'events_url': 'https://api.github.com/users/shamanez/events{/privacy}', 'received_events_url': 'https://api.github.com/users/shamanez/received_events', 'type': 'User', 'site_admin': False}
[]
[]
Hi !
As far as I know not all faiss indexes can be computed in parallel and then merged. 
For example [here](https://github.com/facebookresearch/faiss/wiki/Special-operations-on-indexes#splitting-and-merging-indexes) is is mentioned that only IndexIVF indexes can be merged.
Moreover faiss already works using multithreading to parallelize the workload over your different CPU cores. You can find more info [here](https://github.com/facebookresearch/faiss/wiki/Threads-and-asynchronous-calls#internal-threading)
So I feel like the gains we would get by implementing a parallel `add_faiss_index` would not be that important, but let me know what you think.
 Actually, you are right. I also had the same idea. I am trying this in the context of end-ton-end retrieval training in RAG.  So far I have parallelized the embedding re-computation within the training loop by using datasets shards. 

Then I was thinking of can I calculate the indexes for each shard and combined them with **concatenate**  before I save. @lhoestq  As you mentioned faiss is already using multiprocessing. I tried to do the add_index with faiss for a dataset object inside a RAY actor and the process became very slow... if fact it takes so much time. It is because a ray actor comes with a single CPU core unless we assign it more. I also tried assigning more cores but still running add_index in the main process is very fast. 
I am thinking of making the  **add_faiss_index** process faster. What if we run the add_faiss_index process on separate dataset shards and then combine them before (dataset.concatenate) saving the faiss.index file ?

I feel theoretically this will reduce the accuracy of retrieval since it affects the indexing process.

@lhoestq

{'url': 'https://api.github.com/repos/huggingface/datasets/issues/1965/reactions', 'total_count': 0, '+1': 0, '-1': 0, 'laugh': 0, 'hooray': 0, 'confused': 0, 'heart': 0, 'rocket': 0, 'eyes': 0}