def quantize_vec_without_modifying_index(index: faiss.Index, vecs: np.ndarray) -> np.ndarray: """ Quantizes a batch of vectors if the index given uses quantization """ try: return index.sa_decode(index.sa_encode(vecs)) except (TypeError, RuntimeError): # error if the index doesn't use quantization return vecs
def quantize_vec_without_modifying_index(index: faiss.Index, vecs: np.ndarray) -> np.ndarray: """ qantize a batch of vectors """ quantized_vecs = index.sa_decode(index.sa_encode(vecs)) return quantized_vecs