Import faiss if available, otherwise raise error. If FAISS_NO_AVX2 environment variable is set, it will be considered to load FAISS with no AVX2 optimization. Code borrowed from langchain. Args: no_avx2: Load FAISS strictly with no AVX2 optimization so that
(no_avx2: Optional[bool] = None)
| 13 | from finagent.memory.base import VectorStore |
| 14 | |
| 15 | def dependable_faiss_import(no_avx2: Optional[bool] = None) -> Any: |
| 16 | """ |
| 17 | Import faiss if available, otherwise raise error. |
| 18 | If FAISS_NO_AVX2 environment variable is set, it will be considered |
| 19 | to load FAISS with no AVX2 optimization. |
| 20 | Code borrowed from langchain. |
| 21 | |
| 22 | Args: |
| 23 | no_avx2: Load FAISS strictly with no AVX2 optimization |
| 24 | so that the vectorstore is portable and compatible with other devices. |
| 25 | """ |
| 26 | if no_avx2 is None and "FAISS_NO_AVX2" in os.environ: |
| 27 | no_avx2 = bool(os.getenv("FAISS_NO_AVX2")) |
| 28 | |
| 29 | try: |
| 30 | if no_avx2: |
| 31 | from faiss import swigfaiss as faiss |
| 32 | else: |
| 33 | import faiss |
| 34 | except ImportError: |
| 35 | raise ImportError( |
| 36 | "Could not import faiss python package. " |
| 37 | "Please install it with `pip install faiss-gpu` (for CUDA supported GPU) " |
| 38 | "or `pip install faiss-cpu` (depending on Python version)." |
| 39 | ) |
| 40 | return faiss |
| 41 | |
| 42 | class FAISS(VectorStore): |
| 43 | def __init__( |
no outgoing calls
no test coverage detected