python - Faiss:如何创建大小为 1024 的 10M 向量的索引
问题描述
我想创建一个大小为 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()
而不是将向量附加到列表(向量 = [])。但它也没有奏效。
我想知道如何为大量向量创建索引。
解决方案
推荐阅读
- zapier - Zapier CLI,在 inputFields 上使用选项在创建新 Zap 时不会在表单中显示
- gradle - `implementation` 而不是 `compile` for `fileTree` 会干扰复制库任务
- node.js - 如何从 json 读取 javascript 函数
- google-maps - 如何显示从最终用户位置到存储的大致位置?
- node.js - 如何编写自动更改节点版本的 .nvmrc 文件
- javascript - 脚本标签内带有占位符的淘汰赛绑定
- android - 为什么 Recyclerview 适配器 onBindViewHolder 被多次调用?
- asp.net - ASP.NET:模型验证错误 - 错误请求
- c++ - 没有返回值的整数函数
- python - 带 time.sleep 的 While 循环