MCPcopy Create free account
hub / github.com/DVampire/FinAgent / dependable_faiss_import

Function dependable_faiss_import

finagent/memory/faiss.py:15–40  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

13from finagent.memory.base import VectorStore
14
15def 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
42class FAISS(VectorStore):
43 def __init__(

Callers 3

__init__Method · 0.85
load_localMethod · 0.85
save_localMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected