facebookresearch / faiss

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

Get inverted list ids of searched vectors in IndexIVFPQ #424

Closed rhina closed 6 years ago

rhina commented 6 years ago

Is there any way to get inverted list ids of searched vectors? There are nlists lists in IndexIVFPQ and I want to know the list ids that searched vectors belong using like following code

index = faiss.IndexIVFPQ (quantizer, d, nlist, n_subvec, n_bits)
index.train (x_train)
index.add (x_base) 
D, I, list_ids = index.search (x_query, k)

Is it possible to get list_ids?

mdouze commented 6 years ago

Hi Yes, but this has to be done in C++. See https://gist.github.com/mdouze/da4e7969c177afda3173192c3375e81a

rhina commented 6 years ago

Thank you for your answer! I'll use this C++ function