facebookresearch / faiss

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

Means for accelerating my gpu search #3956

Closed KirinZzzz closed 1 month ago

KirinZzzz commented 1 month ago

Summary

I am cerently working on a work using faiss on gpu to sove a vector search project, there is a loop in my project and each loop contains an faiss search section, I'm looking for a way to accelerate this process but have a few questions.

Platform

Faiss version: 1.7.2

Running on:

Interface:

Questions

my codes are: res = faiss.StandardGpuResources() config = faiss.GpuIndexIVFFlatConfig() config.use_raft = False index = faiss.GpuIndexIVFFlat(res, 64, 10,faiss.METRIC_INNER_PRODUCT,config) index.nprobe = 1 index.train(vecs) index.add(vecs) distances, indices = index.search(nq, 1000)

I find that "index = faiss.index_cpu_to_gpu(res, 2, index)" takes a lot of time to complete so I switch to " index = faiss.GpuIndexIVFFlat(res, 64, 10,faiss.METRIC_INNER_PRODUCT,config)", is there a difference?

Because initializing the index takes a lot of time in both circumstances, like I said there is a loop in my project and each loop contains an faiss search section, I want to initialize the index before going into the loop( so I can save the time for initializing ), thus i need to empty the index( reversing the add method )after each search( beacuse the vecs and nq are different in each loop ), I tried "index.remove_ids(np.arange(vecs.len))" but encounter: RuntimeError: Error in virtual size_t faiss::Index::remove_ids(const faiss::IDSelector&) at /home/conda/feedstock_root/build_artifacts/faiss-split_1644327811086/work/faiss/Index.cpp:43: remove_ids not implemented for this type of index

Is there a way to empty the index after searching in GPU ? Will my idea actually work?