我想在 Lambda Stack by 上安装 Faiss-GPU,conda install -c pytorch faiss-gpu但没有安装 conda 。
我尝试了这里提到的解决方案:使用此版本的 faiss https://anaconda.org/pytorch/faiss-gpu/1.6.0/download/linux-64/faiss-gpu-1.6.0-py36h1a5d453_0在 Google Colaboratory 上安装 faiss .tar.bz2但它说:
ImportError: libmkl_intel_lp64.so: cannot open shared object file: No such file or directory
ModuleNotFoundError: No module named '_swigfaiss_avx2'
ImportError: libmkl_intel_lp64.so: cannot open shared object file: No such file or directory
ModuleNotFoundError: No module named '_swigfaiss'
Run Code Online (Sandbox Code Playgroud)
在 Lambda Stack 上安装 Faiss 的正确方法是什么?
我正在使用 Faiss 来索引我的巨大数据集嵌入,即从 bert 模型生成的嵌入。我想增量添加嵌入,如果我仅使用 faiss.IndexFlatL2 添加它,它就可以正常工作,但问题是在保存它时它的大小太大。所以我尝试使用 faiss.IndexIVFPQ,但它需要在添加数据之前训练嵌入,所以我无法增量添加它,我必须先计算所有嵌入,然后训练并添加它,它有问题,因为所有数据应该保存在 RAM 中直到我写它。有什么办法可以逐步做到这一点。这是我的代码:
    # It is working fine when using with IndexFlatL2
    def __init__(self, sentences, model):
        self.sentences = sentences
        self.model = model
        self.index = faiss.IndexFlatL2(768)
    def process_sentences(self):
        result = self.model(self.sentences)
        self.sentence_ids = []
        self.token_ids = []
        self.all_tokens = []
        for i, (toks, embs) in enumerate(tqdm(result)):
            # initialize all_embeddings for every new sentence (INCREMENTALLY)
            all_embeddings = []
            for j, (tok, emb) in enumerate(zip(toks, embs)):
                self.sentence_ids.append(i)
                self.token_ids.append(j)
                self.all_tokens.append(tok)
                all_embeddings.append(emb)
            all_embeddings = np.stack(all_embeddings) # Add embeddings …Run Code Online (Sandbox Code Playgroud) 我用来faiss indexflatIP存储与某些单词相关的向量。我还使用另一个列表来存储单词(列表中第 n 个元素的向量是 faiss 索引中的第 n 个向量)。我有两个问题:
运行安装时:
pip install faiss
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
ERROR: Could not find a version that satisfies the requirement faiss (from versions: none)
ERROR: No matching distribution found for faiss
Run Code Online (Sandbox Code Playgroud)
当我使用 conda 时:
conda install faiss
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
PackagesNotFoundError: The following packages are not available from current channels:
  - faiss
Run Code Online (Sandbox Code Playgroud) 我想创建一个包含近 10M 个大小为 1024 的向量的索引。这是我使用的代码。
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")
Run Code Online (Sandbox Code Playgroud)
该代码适用于少量向量。但是当向量数量在2M左右时就超出了内存限制。我使用index.add()而不是将向量附加到列表(向量=[])。但效果并不好。
我想知道如何为大量向量创建索引。