我想创建一个大小为1024的近10M向量的索引。这是我使用的代码
import numpy as np
import faiss
import random
f = 1024
vectors = []
no_of_vectors=10000000
for k in range(no_of_vectors):
v = [random.gauss(0, 1) for z in range(f)]
vectors.append(v)
np_vectors = np.array(vectors).astype('float32')
index = faiss.IndexFlatL2(f)
index.add(np_vectors)
faiss.write_index(index, "faiss_index.index")
该代码是为少数向量编写的。但是当向量的数量大约为2M时,内存限制就超过了。我使用了index.add()
而不是将向量追加到列表中(vectors=[])。但效果不太好
我想知道如何为大量向量创建索引
目前没有回答
相关问题 更多 >
编程相关推荐