コード例 #1
0
 def mih_index(self):
     """
     Convenience accessor for the underlaying faiss.IndexBinaryMultiHash index regardless of if it is wrapped in an ID
     map or not.
     """
     if hasattr(self.faiss_index, "index"):
         return faiss.downcast_IndexBinary(self.faiss_index.index)
     return self.faiss_index
コード例 #2
0
        def train_and_get_centroids(override_kmeans_index):
            index = faiss.index_binary_factory(d, b"BIVF10")
            index.verbose = True

            if override_kmeans_index is not None:
                index.clustering_index = override_kmeans_index

            index.train(xt)

            centroids = faiss.downcast_IndexBinary(index.quantizer).xb
            return faiss.vector_to_array(centroids).reshape(-1, d // 8)