我正在使用 CUDA 12 开发 Google Cloud VM。我尝试在 python 3.12.4 下使用 venv 或 pyenv 虚拟环境安装
faiss-gpu-cu12
或 faiss-gpu-cu12[fix_cuda]
。对于应用程序,我们还需要 langchain 包,如下所示:
python --version
Python 3.12.4
python -m pip install langchain langchain-huggingface langchain-community faiss-gpu-cu12[fix_cuda]
pip 没有给出错误,一切看起来都很好,但是当我运行下面的最小示例时:
from langchain_community.vectorstores import FAISS
from langchain_huggingface import HuggingFaceEmbeddings
from sentence_transformers import SentenceTransformer
docs = [ 'sefsl;fk lskdf;lk s', 'ewrl kwelklekfl ls ;' ]
embedder = HuggingFaceEmbeddings(model_name='sentence-transformers/all-MiniLM-L6-v2')
f = FAISS.from_texts(docs, embedding=embedder)
embeddings = embedder.encode(docs)
我收到此错误:
Traceback (most recent call last):
File "/home/jupyterlab_user/erwan/RAG/.venv/lib/python3.12/site-packages/langchain_community/vectorstores/faiss.py", line 55, in dependable_faiss_import
import faiss
File "/home/jupyterlab_user/erwan/RAG/.venv/lib/python3.12/site-packages/faiss/__init__.py", line 16, in <module>
from .loader import *
File "/home/jupyterlab_user/erwan/RAG/.venv/lib/python3.12/site-packages/faiss/loader.py", line 111, in <module>
from .swigfaiss import *
File "/home/jupyterlab_user/erwan/RAG/.venv/lib/python3.12/site-packages/faiss/swigfaiss.py", line 10, in <module>
from . import _swigfaiss
ImportError: /home/jupyterlab_user/erwan/RAG/.venv/lib/python3.12/site-packages/faiss/_swigfaiss.cpython-312-x86_64-linux-gnu.so: ELF load command address/offset not properly aligned
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/jupyterlab_user/erwan/RAG/minimal-faiss-expl2.py", line 9, in <module>
f = FAISS.from_texts(docs, embedding=embedder)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jupyterlab_user/erwan/RAG/.venv/lib/python3.12/site-packages/langchain_community/vectorstores/faiss.py", line 1042, in from_texts
return cls.__from(
^^^^^^^^^^^
File "/home/jupyterlab_user/erwan/RAG/.venv/lib/python3.12/site-packages/langchain_community/vectorstores/faiss.py", line 994, in __from
faiss = dependable_faiss_import()
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jupyterlab_user/erwan/RAG/.venv/lib/python3.12/site-packages/langchain_community/vectorstores/faiss.py", line 57, in dependable_faiss_import
raise ImportError(
ImportError: Could not import faiss python package. Please install it with `pip install faiss-gpu` (for CUDA supported GPU) or `pip install faiss-cpu` (depending on Python version).
看起来 Faiss 库没有正确安装,尽管 pip 在安装包时没有给出错误
faiss-gpu-cu12
。有什么我错过的吗?例如,上述软件包之间是否存在任何已知的不兼容性?
目前我只能使用
faiss-cpu
,所以欢迎任何建议!
您能给我一些有关您正在使用的虚拟机的详细信息吗? (操作系统、glibc 版本等)