Agent Zero AI framework
faiss monkey patch
frdel8e5b108f5827
diff --git a/python/helpers/faiss_monkey_patch.py b/python/helpers/faiss_monkey_patch.pynew file mode 100644index 000000000..65c997a06--- /dev/null+++ b/python/helpers/faiss_monkey_patch.py@@ -0,0 +1,28 @@+import sys+from types import ModuleType, SimpleNamespace++import numpy # real numpy++# for python 3.12 on arm, faiss needs a fake cpuinfo module+++""" This disgusting hack was brought to you by:+https://github.com/facebookresearch/faiss/issues/3936+"""++def hack_faiss_for_python_3_12() -> None:+ # Create a fake 'cpuinfo' module+ fake_cpuinfo_module = ModuleType("numpy.distutils.cpuinfo")+ fake_cpu_module = SimpleNamespace()+ fake_cpu_module.info = [{"Features": "asimd fp"}] # No 'sve'+ setattr(fake_cpuinfo_module, "cpu", fake_cpu_module)++ # Create a fake 'distutils' module and assign the cpuinfo module+ fake_distutils_module = ModuleType("numpy.distutils")+ setattr(fake_distutils_module, "cpuinfo", fake_cpuinfo_module)++ # Inject the fake modules into sys.modules+ sys.modules["numpy.distutils"] = fake_distutils_module+ sys.modules["numpy.distutils.cpuinfo"] = fake_cpuinfo_module++hack_faiss_for_python_3_12()\ No newline at end of filediff --git a/python/helpers/memory.py b/python/helpers/memory.pyindex 7c43042d5..60e60e2d3 100644--- a/python/helpers/memory.py+++ b/python/helpers/memory.py@@ -5,7 +5,12 @@ from langchain.embeddings import CacheBackedEmbeddings# from langchain_chroma import Chromafrom langchain_community.vectorstores import FAISS++# faiss needs to be patched for python 3.12 on arm #TODO remove once not needed+from python.helpers import faiss_monkey_patchimport faiss++from langchain_community.docstore.in_memory import InMemoryDocstorefrom langchain_community.vectorstores.utils import (DistanceStrategy,diff --git a/python/helpers/vector_db.py b/python/helpers/vector_db.pyindex c1bc1095b..21bd55ce6 100644--- a/python/helpers/vector_db.py+++ b/python/helpers/vector_db.py@@ -1,7 +1,12 @@from typing import Any, List, Sequenceimport uuidfrom langchain_community.vectorstores import FAISS++# faiss needs to be patched for python 3.12 on arm #TODO remove once not needed+from python.helpers import faiss_monkey_patchimport faiss++from langchain_core.documents import Documentfrom langchain.storage import InMemoryByteStorefrom langchain_community.docstore.in_memory import InMemoryDocstorediff --git a/requirements.txt b/requirements.txtindex ebf7e9d04..1b1de90ea 100644--- a/requirements.txt+++ b/requirements.txt@@ -4,7 +4,7 @@ beautifulsoup4==4.13.4browser-use==0.2.5docker==7.1.0duckduckgo-search==6.1.12-faiss-cpu==1.9.0+faiss-cpu==1.11.0fastmcp==2.3.4flask[async]==3.0.3flask-basicauth==0.2.0@@ -35,4 +35,4 @@ unstructured==0.15.13unstructured-client==0.25.9webcolors==24.6.0nest-asyncio==1.6.0-crontab==1.0.1+crontab==1.0.1\ No newline at end of file