FAISS Nearest neighbourhood search. Args: on_gpu: If set true, nearest neighbour searches are done on GPU. num_workers: Number of workers to use with FAISS for similarity search.
(self, on_gpu: bool = False, num_workers: int = 4)
| 13 | |
| 14 | class FaissNN(object): |
| 15 | def __init__(self, on_gpu: bool = False, num_workers: int = 4) -> None: |
| 16 | """FAISS Nearest neighbourhood search. |
| 17 | |
| 18 | Args: |
| 19 | on_gpu: If set true, nearest neighbour searches are done on GPU. |
| 20 | num_workers: Number of workers to use with FAISS for similarity search. |
| 21 | """ |
| 22 | faiss.omp_set_num_threads(num_workers) |
| 23 | self.on_gpu = on_gpu |
| 24 | self.search_index = None |
| 25 | |
| 26 | def _gpu_cloner_options(self): |
| 27 | return faiss.GpuClonerOptions() |