💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Update Faiss macOS test to force module reload #818
davidmezzettie16d42382bc1
diff --git a/docs/faq.md b/docs/faq.mdindex 80db8704..f9944a71 100644--- a/docs/faq.md+++ b/docs/faq.md@@ -103,10 +103,11 @@ __Solution__Set the following environment parameters.-- OpenMP threading is handled internally on macOS platforms, but it can be disabled by setting the environment variable OMP_NUM_THREADS to 1, e.g., export OMP_NUM_THREADS=1. For more details, refer to the related discussion on GitHub: kyamagu/faiss-wheels#100.+- OpenMP threading is handled internally on macOS platforms but it can be disabled via `export OMP_NUM_THREADS=1`- Disable PyTorch MPS device via `export PYTORCH_MPS_DISABLE=1`- Disable llama.cpp metal via `export LLAMA_NO_METAL=1`+For more details, refer to [this issue on GitHub](https://github.com/kyamagu/faiss-wheels/issues/100).----------diff --git a/src/python/txtai/ann/faiss.py b/src/python/txtai/ann/faiss.pyindex 75d0958e..13d857be 100644--- a/src/python/txtai/ann/faiss.py+++ b/src/python/txtai/ann/faiss.py@@ -14,10 +14,7 @@ from faiss import index_binary_factory, read_index_binary, write_index_binary, Ifrom .base import ANNif platform.system() == "Darwin":- # Workaround for an open bug on macOS causing segmentation faults in FAISS.- # Setting the number of threads in OpenMP to 1 avoids the issue for now.- # Ref: https://github.com/kyamagu/faiss-wheels/issues/100- # Remove this workaround once the upstream bug is patched.+ # Workaround for a Faiss issue causing segmentation faults on macOS. See txtai FAQ for more.omp_set_num_threads(1)diff --git a/test/python/testann.py b/test/python/testann.pyindex c932be54..bc33b3ca 100644--- a/test/python/testann.py+++ b/test/python/testann.py@@ -4,6 +4,7 @@ ANN module testsimport osimport platform+import sysimport tempfileimport unittest@@ -67,6 +68,28 @@ class TestANN(unittest.TestCase):self.runTests("faiss", {"faiss": {"nprobe": 2, "components": "PCA16,IDMap,SQ8", "sample": 1.0}}, False)self.runTests("faiss", {"faiss": {"components": "IVF,SQ8"}}, False)+ @patch("platform.system")+ def testFaissMacOS(self, system):+ """+ Test Faiss backend with macOS+ """++ # Run test+ system.return_value = "Darwin"++ # pylint: disable=C0415, W0611+ # Force reload of class+ name = "txtai.ann.faiss"+ module = sys.modules[name]+ del sys.modules[name]+ import txtai.ann.faiss++ # Run tests+ self.runTests("faiss")++ # Restore original module+ sys.modules[name] = module+@unittest.skipIf(os.name == "nt", "mmap not supported on Windows")def testFaissMmap(self):"""@@ -136,14 +159,6 @@ class TestANN(unittest.TestCase):# Validate countself.assertEqual(ann.count(), 100)- @patch("platform.system")- def testFaissMacOS(self, mock_platform):- """- Test backend with OS Darwin- """- mock_platform.return_value = "Darwin"- self.runTests("faiss")-@patch("sqlalchemy.orm.Query.limit")def testPGVector(self, query):"""