Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_optimal_index_keys_v2 support faiss AutoTune #139

Open
xiongqiangcs opened this issue Nov 16, 2022 · 4 comments
Open

get_optimal_index_keys_v2 support faiss AutoTune #139

xiongqiangcs opened this issue Nov 16, 2022 · 4 comments

Comments

@xiongqiangcs
Copy link

def get_optimal_index_keys_v2(
nb_vectors: int,
dim_vector: int,
max_index_memory_usage: str,
flat_threshold: int = 1000,
quantization_threshold: int = 10000,
force_pq: Optional[int] = None,
make_direct_map: bool = False,
should_be_memory_mappable: bool = False,
ivf_flat_threshold: int = 1_000_000,
use_gpu: bool = False,
) -> List[str]:
"""
Gives a list of interesting indices to try, *the one at the top is the most promising*
See: https://github.com/facebookresearch/faiss/wiki/Guidelines-to-choose-an-index for
detailed explanations.
"""
# Exception cases:

@rom1504
Copy link
Contributor

rom1504 commented Nov 16, 2022

Autofaiss is an alternative implementation of faiss AutoTune that works based on the contraints listed in the readme.
Do you have any specific suggestions?

@xiongqiangcs
Copy link
Author

I think the faiss readme is a recommendation rather than a standard, it's a tradeoff between performance and recall.
Examples:
http://ann-benchmarks.com/sift-128-euclidean_10_euclidean.html

image

but autofaiss

if not should_be_memory_mappable:
# If we can build an HNSW with the given memory constraints, it's the best
m_hnsw = int(floor((max_size_in_bytes / (4 * nb_vectors) - dim_vector) / 2))
if m_hnsw >= 8:
return [f"HNSW{min(m_hnsw, 32)}"]

I recommend randomly sampling the embeddings and evaluate recall/perf by various index key parameters to get optimal index key,such as https://github.com/erikbern/ann-benchmarks/blob/8807d6ead4cf14318ac43166cdabf02b491f620e/algos.yaml#L146-L187

@rom1504
Copy link
Contributor

rom1504 commented Nov 17, 2022 via email

@victor-paltz
Copy link
Contributor

Hello @xiongqiangcs !

We chose to use a heuristic rather than benchmarking n different indices because it is n times faster and that the heuristic is not too far from finding the best index.
Also, the fine-tuning step makes it possible to improve the final index performance, so we close the gap with an eventually better index key to use.

But indeed, benchmarking n index keys could give better results. There might be good ideas to use to make it possible to benchmark quickly several indices while not taking too much time! We are open to any suggestions if you want to try it out 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants