facebookresearch / faiss

A library for efficient similarity search and clustering of dense vectors.
https://faiss.ai
MIT License
31.03k stars 3.61k forks source link

feature request: `index.search` without labels #2313

Open bhatiaharsh opened 2 years ago

bhatiaharsh commented 2 years ago

Summary

I have a feature request and am curious if it is hard to support for the faiss team.

Currently, the index.search method returns both the distances and ids of the resulting points. This is a great feature and the labels I think come for free from the search tree. https://github.com/facebookresearch/faiss/blob/02c8452eb993cd8e6566b4cb00730094fa9ce129/faiss/Index.h#L113

However, if the application has no use for labels and is interested only in distances, then it forces us to allocate memory for labels only to throw it away after the query.

Can you support a search_without_label search? possibly by allowing to pass labels = nullptr and just not populate the labels if the application does not want it?

mdouze commented 2 years ago

To me it seems very marginally useful. Could you give a use case where allocating a temp buffer for labels would be a limiting factor?

bhatiaharsh commented 2 years ago

i think it is quite useful for any sort of memory-limited device.

specifically for our use case, we would like to collocate faiss index and all its queries onto the same gpu that is primarily engaged in a simulation. we are still doing some studies to get exact numbers, but we anticipate requiring all/most of the gpu memory for the simulation. therefore, minimizing the footprint for the faiss queries is an imprtant goal for us.

previously, we have used different devices for faiss and simulation (see here and here), and it works, except the latency of the data movement can be limiting.